client: add lock for onTransfer

There should never be multiple clients to actually need this, but just in case
This commit is contained in:
Tulir Asokan
2025-12-29 23:12:33 +02:00
parent cac1f5acde
commit 274141a1b0
+10
View File
@@ -104,6 +104,8 @@ type TelegramClient struct {
contactsLock sync.Mutex
lastContactReq time.Time
dcTransferLock sync.Mutex
takeoutLock sync.Mutex
takeoutAccepted *exsync.Event
stopTakeoutTimer *time.Timer
@@ -256,6 +258,7 @@ func NewTelegramClient(ctx context.Context, tc *TelegramConnector, login *bridge
OnDead: client.onDead,
OnSession: client.onSession,
OnConnected: client.onConnected,
OnTransfer: client.onTransfer,
PingCallback: client.onPing,
OnAuthError: client.onAuthError,
PingTimeout: time.Duration(tc.Config.Ping.TimeoutSeconds) * time.Second,
@@ -501,6 +504,13 @@ func (t *TelegramClient) onConnected(self *tg.User) {
t.userLogin.BridgeState.Send(status.BridgeState{StateEvent: status.StateConnected})
}
func (t *TelegramClient) onTransfer(ctx context.Context, _ *telegram.Client, fn func(context.Context) error) error {
t.userLogin.Log.Trace().Msg("Doing DC auth transfer")
t.dcTransferLock.Lock()
defer t.dcTransferLock.Unlock()
return fn(ctx)
}
func (t *TelegramClient) onSession() {
t.userLogin.Log.Debug().Msg("Got session created event")
}