backfill: fix dialog fetch, HasMore, and skip forbidden channels

Signed-off-by: Sumner Evans <sumner.evans@automattic.com>
This commit is contained in:
Sumner Evans
2024-10-08 12:22:04 -06:00
parent 9576f48c5b
commit 9a8f356348
2 changed files with 16 additions and 5 deletions
+11 -4
View File
@@ -93,11 +93,18 @@ func (t *TelegramClient) takeoutDialogs(ctx context.Context, takeoutID int64) er
}
for {
log.Info().Stringer("cursor", req.OffsetPeer).Msg("Fetching dialogs")
dialogs, err := APICallWithUpdates(ctx, t, func() (*tg.MessagesDialogs, error) {
var dialogs tg.MessagesDialogs
return &dialogs, t.client.Invoke(ctx,
dialogs, err := APICallWithUpdates(ctx, t, func() (tg.ModifiedMessagesDialogs, error) {
var dialogs tg.MessagesDialogsBox
err := t.client.Invoke(ctx,
&tg.InvokeWithTakeoutRequest{TakeoutID: takeoutID, Query: &req},
&dialogs)
if err != nil {
return nil, err
} else if modified, ok := dialogs.Dialogs.AsModified(); !ok {
return nil, fmt.Errorf("unexpected response type: %T", dialogs.Dialogs)
} else {
return modified, nil
}
})
if err != nil {
return fmt.Errorf("failed to get dialogs: %w", err)
@@ -302,7 +309,7 @@ func (t *TelegramClient) FetchMessages(ctx context.Context, fetchParams bridgev2
return &bridgev2.FetchMessagesResponse{
Messages: backfillMessages,
Cursor: cursor,
HasMore: len(messages) == fetchParams.Count,
HasMore: len(backfillMessages) > 0,
Forward: fetchParams.Forward,
MarkRead: markRead,
}, nil
+5 -1
View File
@@ -133,7 +133,11 @@ func (t *TelegramClient) handleDialogs(ctx context.Context, dialogs tg.ModifiedM
chatInfo.Members.PowerLevels = t.getGroupChatPowerLevels(chats[peer.ChatID])
chatInfo.Name = &chats[peer.ChatID].(*tg.Chat).Title
case *tg.PeerChannel:
channel := chats[peer.ChannelID].(*tg.Channel)
channel, ok := chats[peer.ChannelID].(*tg.Channel)
if !ok {
log.Error().Type("channel", chats[peer.ChannelID]).Msg("Failed to cast chat to channel")
continue
}
chatInfo.Name = &channel.Title
chatInfo.Members.PowerLevels = t.getGroupChatPowerLevels(channel)
if !portal.Metadata.(*PortalMetadata).IsSuperGroup {