commands: restart dialog sync on command
This commit is contained in:
@@ -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")
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user