client: resume chat list sync after restart
This commit is contained in:
@@ -111,6 +111,7 @@ type TelegramClient struct {
|
||||
stopTakeoutTimer *time.Timer
|
||||
takeoutDialogsOnce sync.Once
|
||||
syncChatsLock sync.Mutex
|
||||
isNewLogin bool
|
||||
|
||||
prevReactionPoll map[networkid.PortalKey]time.Time
|
||||
prevReactionPollLock sync.Mutex
|
||||
@@ -511,6 +512,15 @@ func (t *TelegramClient) runInBackground(ctx context.Context) {
|
||||
log := zerolog.Ctx(ctx)
|
||||
err := t.client.Run(ctx, func(ctx context.Context) error {
|
||||
t.clientInitialized.Set()
|
||||
// If takeout dialog sync is enabled, we assume it'll resume from a getTakeoutID call.
|
||||
// If not, resume dialog sync manually here.
|
||||
if !t.isNewLogin && !t.main.Config.Takeout.DialogSync {
|
||||
go func() {
|
||||
if err := t.syncChats(log.WithContext(t.clientCtx), 0, false, false); err != nil {
|
||||
log.Err(err).Msg("Failed to resume chat sync")
|
||||
}
|
||||
}()
|
||||
}
|
||||
log.Info().Msg("Client running, starting updates")
|
||||
err := t.updatesManager.Run(ctx, t.client.API(), t.telegramUserID, updates.AuthOptions{
|
||||
IsBot: t.metadata.IsBot,
|
||||
|
||||
@@ -229,8 +229,9 @@ func (bl *baseLogin) finalizeLogin(
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to save new login: %w", err)
|
||||
}
|
||||
ul.Client.Connect(ul.Log.WithContext(bl.main.Bridge.BackgroundCtx))
|
||||
client := ul.Client.(*TelegramClient)
|
||||
client.isNewLogin = true
|
||||
client.Connect(ul.Log.WithContext(bl.main.Bridge.BackgroundCtx))
|
||||
|
||||
bgCtx := ul.Log.WithContext(bl.main.Bridge.BackgroundCtx)
|
||||
go func() {
|
||||
@@ -241,6 +242,8 @@ func (bl *baseLogin) finalizeLogin(
|
||||
err := client.clientInitialized.Wait(bgCtx)
|
||||
if err != nil {
|
||||
log.Err(err).Msg("Failed to wait for client init to sync chats after login")
|
||||
} else if client.clientDone.IsSet() {
|
||||
log.Warn().Msg("Client is already done after login, skipping chat sync")
|
||||
} else if err = client.syncChats(log.WithContext(client.clientCtx), 0, true, false); err != nil {
|
||||
log.Err(err).Msg("Failed to sync chats")
|
||||
}
|
||||
@@ -259,6 +262,8 @@ func (bl *baseLogin) finalizeLogin(
|
||||
err := client.clientInitialized.Wait(bgCtx)
|
||||
if err != nil {
|
||||
log.Err(err).Msg("Failed to wait for client init to start takeout")
|
||||
} else if client.clientDone.IsSet() {
|
||||
log.Warn().Msg("Client is already done after login, skipping takeout")
|
||||
} else if _, err = client.getTakeoutID(bgCtx); err != nil {
|
||||
log.Err(err).Msg("Failed to get takeout")
|
||||
} else if client.stopTakeoutTimer == nil {
|
||||
|
||||
Reference in New Issue
Block a user