From d4f6be81553f55293998a9f29064fc02e6d0c758 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 17 Jul 2025 18:26:16 +0300 Subject: [PATCH] sync: fix handling chats with no messages --- pkg/connector/sync.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/connector/sync.go b/pkg/connector/sync.go index ce1bf272..8d875e4f 100644 --- a/pkg/connector/sync.go +++ b/pkg/connector/sync.go @@ -231,7 +231,14 @@ func (t *TelegramClient) handleDialogs(ctx context.Context, dialogs tg.ModifiedM if portal == nil || portal.MXID == "" { // Check what the latest message is topMessage := messages[ids.MakeMessageID(dialog.Peer, dialog.TopMessage)] - if topMessage.TypeID() == tg.MessageServiceTypeID { + if topMessage == nil { + if dialog.TopMessage == 0 { + log.Debug().Msg("Not syncing portal because there are no messages") + continue + } else { + log.Warn().Msg("TopMessage of dialog not in messages map") + } + } else if topMessage.TypeID() == tg.MessageServiceTypeID { action := topMessage.(*tg.MessageService).Action if action.TypeID() == tg.MessageActionContactSignUpTypeID || action.TypeID() == tg.MessageActionHistoryClearTypeID { log.Debug().Str("action_type", action.TypeName()).Msg("Not syncing portal because it's a contact sign up or history clear")