move gotd fork into repo. (#111)
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/go-faster/errors"
|
||||
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
|
||||
)
|
||||
|
||||
func (c *Client) exportAuth(ctx context.Context, dcID int) (*tg.AuthExportedAuthorization, error) {
|
||||
export, err := c.tg.AuthExportAuthorization(ctx, dcID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "export auth to %d", dcID)
|
||||
}
|
||||
|
||||
return export, nil
|
||||
}
|
||||
|
||||
// AuthTransferHandler is a function that is called during authorization transfer.
|
||||
//
|
||||
// The fn callback should be serialized by user id via external locking.
|
||||
// You can call [Client.Self] to acquire current user id.
|
||||
//
|
||||
// The fn callback must return fn error if any.
|
||||
type AuthTransferHandler func(ctx context.Context, client *Client, fn func(context.Context) error) error
|
||||
|
||||
func noopOnTransfer(ctx context.Context, _ *Client, fn func(context.Context) error) error {
|
||||
return fn(ctx)
|
||||
}
|
||||
|
||||
// transfer exports current authorization and imports it to another DC.
|
||||
// See https://core.telegram.org/api/datacenter#authorization-transfer.
|
||||
func (c *Client) transfer(ctx context.Context, to *tg.Client, dc int) (tg.AuthAuthorizationClass, error) {
|
||||
var out tg.AuthAuthorizationClass
|
||||
if err := c.onTransfer(ctx, c, func(ctx context.Context) error {
|
||||
auth, err := c.exportAuth(ctx, dc)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "export to %d", dc)
|
||||
}
|
||||
|
||||
req := &tg.AuthImportAuthorizationRequest{}
|
||||
req.FillFrom(auth)
|
||||
r, err := to.AuthImportAuthorization(ctx, req)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "import from %d", dc)
|
||||
}
|
||||
|
||||
out = r
|
||||
return nil
|
||||
}); err != nil {
|
||||
return nil, errors.Wrap(err, "onTransfer")
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
Reference in New Issue
Block a user