backfill: fix dialog fetch, HasMore, and skip forbidden channels
Signed-off-by: Sumner Evans <sumner.evans@automattic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user