From 10b8c4b635b06dccdf3d1758cea8ed9a2b07bd44 Mon Sep 17 00:00:00 2001 From: Nick Mills-Barrett Date: Mon, 7 Apr 2025 13:57:52 +0100 Subject: [PATCH] chatinfo: log when chats have no or unknown photo types --- pkg/connector/chatinfo.go | 12 ++++++++---- pkg/connector/telegram.go | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/connector/chatinfo.go b/pkg/connector/chatinfo.go index 9dac871b..68bec861 100644 --- a/pkg/connector/chatinfo.go +++ b/pkg/connector/chatinfo.go @@ -186,8 +186,12 @@ func (t *TelegramClient) getGroupChatInfo(fullChat *tg.MessagesChatFull, chatID return &chatInfo, isBroadcastChannel, nil } -func (t *TelegramClient) avatarFromPhoto(photo tg.PhotoClass) *bridgev2.Avatar { - if photo == nil || photo.TypeID() != tg.PhotoTypeID { +func (t *TelegramClient) avatarFromPhoto(ctx context.Context, photo tg.PhotoClass) *bridgev2.Avatar { + if photo == nil { + zerolog.Ctx(ctx).Trace().Msg("Chat photo is nil, returning no avatar") + return nil + } else if photo.TypeID() != tg.PhotoTypeID { + zerolog.Ctx(ctx).Warn().Uint32("type_id", photo.TypeID()).Msg("Chat photo type unknown, returning no avatar") return nil } return &bridgev2.Avatar{ @@ -256,7 +260,7 @@ func (t *TelegramClient) GetChatInfo(ctx context.Context, portal *bridgev2.Porta if !ok { return nil, fmt.Errorf("full chat is %T not *tg.ChatFull", fullChat.FullChat) } - chatInfo.Avatar = t.avatarFromPhoto(chatFull.ChatPhoto) + chatInfo.Avatar = t.avatarFromPhoto(ctx, chatFull.ChatPhoto) if chatFull.Participants.TypeID() == tg.ChatParticipantsForbiddenTypeID { chatInfo.Members.IsFull = false @@ -320,7 +324,7 @@ func (t *TelegramClient) GetChatInfo(ctx context.Context, portal *bridgev2.Porta return nil, fmt.Errorf("too many participants (%d) in chat %d", channelFull.ParticipantsCount, id) } - chatInfo.Avatar = t.avatarFromPhoto(channelFull.ChatPhoto) + chatInfo.Avatar = t.avatarFromPhoto(ctx, channelFull.ChatPhoto) // TODO save available reactions? // TODO save reactions limit? diff --git a/pkg/connector/telegram.go b/pkg/connector/telegram.go index 4bc9c8e7..5067dc6e 100644 --- a/pkg/connector/telegram.go +++ b/pkg/connector/telegram.go @@ -191,7 +191,7 @@ func (t *TelegramClient) onUpdateNewMessage(ctx context.Context, entities tg.Ent case *tg.MessageActionChatEditPhoto: t.main.Bridge.QueueRemoteEvent(t.userLogin, &simplevent.ChatInfoChange{ EventMeta: eventMeta.WithType(bridgev2.RemoteEventChatInfoChange), - ChatInfoChange: &bridgev2.ChatInfoChange{ChatInfo: &bridgev2.ChatInfo{Avatar: t.avatarFromPhoto(action.Photo)}}, + ChatInfoChange: &bridgev2.ChatInfoChange{ChatInfo: &bridgev2.ChatInfo{Avatar: t.avatarFromPhoto(ctx, action.Photo)}}, }) case *tg.MessageActionChatDeletePhoto: t.main.Bridge.QueueRemoteEvent(t.userLogin, &simplevent.ChatInfoChange{