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