client: add lock for onTransfer
There should never be multiple clients to actually need this, but just in case
This commit is contained in:
@@ -104,6 +104,8 @@ type TelegramClient struct {
|
|||||||
contactsLock sync.Mutex
|
contactsLock sync.Mutex
|
||||||
lastContactReq time.Time
|
lastContactReq time.Time
|
||||||
|
|
||||||
|
dcTransferLock sync.Mutex
|
||||||
|
|
||||||
takeoutLock sync.Mutex
|
takeoutLock sync.Mutex
|
||||||
takeoutAccepted *exsync.Event
|
takeoutAccepted *exsync.Event
|
||||||
stopTakeoutTimer *time.Timer
|
stopTakeoutTimer *time.Timer
|
||||||
@@ -256,6 +258,7 @@ func NewTelegramClient(ctx context.Context, tc *TelegramConnector, login *bridge
|
|||||||
OnDead: client.onDead,
|
OnDead: client.onDead,
|
||||||
OnSession: client.onSession,
|
OnSession: client.onSession,
|
||||||
OnConnected: client.onConnected,
|
OnConnected: client.onConnected,
|
||||||
|
OnTransfer: client.onTransfer,
|
||||||
PingCallback: client.onPing,
|
PingCallback: client.onPing,
|
||||||
OnAuthError: client.onAuthError,
|
OnAuthError: client.onAuthError,
|
||||||
PingTimeout: time.Duration(tc.Config.Ping.TimeoutSeconds) * time.Second,
|
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})
|
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() {
|
func (t *TelegramClient) onSession() {
|
||||||
t.userLogin.Log.Debug().Msg("Got session created event")
|
t.userLogin.Log.Debug().Msg("Got session created event")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user