commands: restart dialog sync on command

This commit is contained in:
Tulir Asokan
2026-03-19 16:15:44 +02:00
parent 800c15f7b7
commit 64724aa654
4 changed files with 10 additions and 6 deletions
+2 -2
View File
@@ -51,7 +51,7 @@ func (t *TelegramClient) getTakeoutID(ctx context.Context) (takeoutID int64, err
// Resume fetching dialogs using takeout and enqueueing them for // Resume fetching dialogs using takeout and enqueueing them for
// backfill. // backfill.
go t.takeoutDialogsOnce.Do(func() { go t.takeoutDialogsOnce.Do(func() {
if err = t.syncChats(ctx, takeoutID, false); err != nil { if err = t.syncChats(ctx, takeoutID, false, false); err != nil {
log.Err(err).Msg("Failed to takeout dialogs") log.Err(err).Msg("Failed to takeout dialogs")
} }
}) })
@@ -84,7 +84,7 @@ func (t *TelegramClient) getTakeoutID(ctx context.Context) (takeoutID int64, err
// Fetch all dialogs using takeout and enqueue them for backfill. // Fetch all dialogs using takeout and enqueue them for backfill.
go t.takeoutDialogsOnce.Do(func() { go t.takeoutDialogsOnce.Do(func() {
if err = t.syncChats(ctx, takeoutID, false); err != nil { if err = t.syncChats(ctx, takeoutID, false, false); err != nil {
log.Err(err).Msg("Failed to takeout dialogs") log.Err(err).Msg("Failed to takeout dialogs")
} }
}) })
+6 -2
View File
@@ -33,7 +33,7 @@ import (
"go.mau.fi/mautrix-telegram/pkg/gotd/tgerr" "go.mau.fi/mautrix-telegram/pkg/gotd/tgerr"
) )
func (t *TelegramClient) syncChats(ctx context.Context, takeoutID int64, onLogin bool) error { func (t *TelegramClient) syncChats(ctx context.Context, takeoutID int64, onLogin, restart bool) error {
if takeoutID != 0 && !t.main.Config.Takeout.DialogSync { if takeoutID != 0 && !t.main.Config.Takeout.DialogSync {
return nil return nil
} }
@@ -53,7 +53,11 @@ func (t *TelegramClient) syncChats(ctx context.Context, takeoutID int64, onLogin
} }
defer t.syncChatsLock.Unlock() defer t.syncChatsLock.Unlock()
if t.metadata.DialogSyncComplete { if restart {
t.metadata.DialogSyncCount = 0
t.metadata.DialogSyncComplete = false
t.metadata.DialogSyncCursor = ""
} else if t.metadata.DialogSyncComplete {
log.Debug().Msg("Dialogs already synced") log.Debug().Msg("Dialogs already synced")
return nil return nil
} }
+1 -1
View File
@@ -54,7 +54,7 @@ func fnSync(ce *commands.Event) {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
if err := client.syncChats(ce.Ctx, 0, false); err != nil { if err := client.syncChats(ce.Ctx, 0, false, true); err != nil {
ce.Reply("Failed to synchronize chats for %s: %v", login.ID, err) ce.Reply("Failed to synchronize chats for %s: %v", login.ID, err)
} }
}() }()
+1 -1
View File
@@ -241,7 +241,7 @@ 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 err = client.syncChats(log.WithContext(client.clientCtx), 0, true); 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")
} }
}() }()