diff --git a/pkg/connector/backfill.go b/pkg/connector/backfill.go index 608acca5..a0b8fc06 100644 --- a/pkg/connector/backfill.go +++ b/pkg/connector/backfill.go @@ -51,7 +51,7 @@ func (t *TelegramClient) getTakeoutID(ctx context.Context) (takeoutID int64, err // Resume fetching dialogs using takeout and enqueueing them for // backfill. 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") } }) @@ -84,7 +84,7 @@ func (t *TelegramClient) getTakeoutID(ctx context.Context) (takeoutID int64, err // Fetch all dialogs using takeout and enqueue them for backfill. 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") } }) diff --git a/pkg/connector/chatsync.go b/pkg/connector/chatsync.go index 42e87674..3752f163 100644 --- a/pkg/connector/chatsync.go +++ b/pkg/connector/chatsync.go @@ -33,7 +33,7 @@ import ( "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 { return nil } @@ -53,7 +53,11 @@ func (t *TelegramClient) syncChats(ctx context.Context, takeoutID int64, onLogin } 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") return nil } diff --git a/pkg/connector/commands.go b/pkg/connector/commands.go index 0cbb9fec..685a06ef 100644 --- a/pkg/connector/commands.go +++ b/pkg/connector/commands.go @@ -54,7 +54,7 @@ func fnSync(ce *commands.Event) { wg.Add(1) go func() { 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) } }() diff --git a/pkg/connector/login.go b/pkg/connector/login.go index 7495a3b9..4bee7e28 100644 --- a/pkg/connector/login.go +++ b/pkg/connector/login.go @@ -241,7 +241,7 @@ 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 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") } }()