handletelegram: handle UpdateMessageReactions

This commit is contained in:
Tulir Asokan
2026-03-30 17:19:47 +03:00
parent 3500590f11
commit a0323a5233
2 changed files with 18 additions and 10 deletions

View File

@@ -210,6 +210,7 @@ func (t *TelegramClient) onUpdateNewMessage(ctx context.Context, entities tg.Ent
log.Info().Int64("user_id", contact.UserID).Msg("received contact")
}
topicID := t.getTopicID(ctx, msg.PeerID, msg.ReplyTo)
res := t.main.Bridge.QueueRemoteEvent(t.userLogin, &simplevent.Message[*tg.Message]{
EventMeta: simplevent.EventMeta{
Type: bridgev2.RemoteEventMessage,
@@ -222,7 +223,7 @@ func (t *TelegramClient) onUpdateNewMessage(ctx context.Context, entities tg.Ent
Stringer("peer_id", msg.PeerID)
},
Sender: sender,
PortalKey: t.makePortalKeyFromPeer(msg.PeerID, t.getTopicID(ctx, msg.PeerID, msg.ReplyTo)),
PortalKey: t.makePortalKeyFromPeer(msg.PeerID, topicID),
CreatePortal: true,
Timestamp: time.Unix(int64(msg.Date), 0),
StreamOrder: int64(msg.GetID()),
@@ -236,7 +237,7 @@ func (t *TelegramClient) onUpdateNewMessage(ctx context.Context, entities tg.Ent
return err
}
return t.handleTelegramReactions(ctx, msg)
return t.handleTelegramReactions(ctx, msg.PeerID, topicID, msg.ID, msg.Reactions)
case *tg.MessageService:
return t.handleServiceMessage(ctx, msg)
@@ -911,6 +912,8 @@ func (t *TelegramClient) onUpdate(ctx context.Context, e tg.Entities, upd tg.Upd
return t.onMessageEdit(ctx, update)
case *tg.UpdateEditChannelMessage:
return t.onMessageEdit(ctx, update)
case *tg.UpdateMessageReactions:
return t.onMessageReactions(ctx, update)
case *tg.UpdateUserTyping:
return t.handleTyping(t.makePortalKeyFromID(ids.PeerTypeUser, update.UserID, 0), t.senderForUserID(update.UserID), update.Action)
case *tg.UpdateChatUserTyping:
@@ -948,6 +951,10 @@ func (t *TelegramClient) onUpdate(ctx context.Context, e tg.Entities, upd tg.Upd
}
}
func (t *TelegramClient) onMessageReactions(ctx context.Context, update *tg.UpdateMessageReactions) error {
return t.handleTelegramReactions(ctx, update.Peer, update.TopMsgID, update.MsgID, update.Reactions)
}
func (t *TelegramClient) onMessageEdit(ctx context.Context, update IGetMessage) error {
msg, ok := update.GetMessage().(*tg.Message)
if !ok {
@@ -957,12 +964,13 @@ func (t *TelegramClient) onMessageEdit(ctx context.Context, update IGetMessage)
return nil
}
err := t.handleTelegramReactions(ctx, msg)
topicID := t.getTopicID(ctx, msg.PeerID, msg.ReplyTo)
err := t.handleTelegramReactions(ctx, msg.PeerID, topicID, msg.ID, msg.Reactions)
if err != nil {
zerolog.Ctx(ctx).Err(err).Msg("Failed to handle reactions on edited message")
}
portalKey := t.makePortalKeyFromPeer(msg.PeerID, t.getTopicID(ctx, msg.PeerID, msg.ReplyTo))
portalKey := t.makePortalKeyFromPeer(msg.PeerID, topicID)
portal, err := t.main.Bridge.GetPortalByKey(ctx, portalKey)
if err != nil {
return err

View File

@@ -105,13 +105,13 @@ func computeEmojiAndID(reaction tg.ReactionClass, customEmojis map[networkid.Emo
return
}
func (t *TelegramClient) handleTelegramReactions(ctx context.Context, msg *tg.Message) error {
func (t *TelegramClient) handleTelegramReactions(ctx context.Context, peer tg.PeerClass, topicID, msgID int, reactions tg.MessageReactions) error {
log := zerolog.Ctx(ctx).With().
Str("handler", "handle_telegram_reactions").
Int("message_id", msg.ID).
Int("message_id", msgID).
Logger()
reactionsList, isFull, customEmojis, err := t.computeReactionsList(ctx, msg.PeerID, msg.ID, msg.Reactions)
reactionsList, isFull, customEmojis, err := t.computeReactionsList(ctx, peer, msgID, reactions)
if err != nil {
return fmt.Errorf("failed to compute reactions: %w", err)
}
@@ -152,11 +152,11 @@ func (t *TelegramClient) handleTelegramReactions(ctx context.Context, msg *tg.Me
EventMeta: simplevent.EventMeta{
Type: bridgev2.RemoteEventReactionSync,
LogContext: func(c zerolog.Context) zerolog.Context {
return c.Int("message_id", msg.ID)
return c.Int("message_id", msgID)
},
PortalKey: t.makePortalKeyFromPeer(msg.PeerID, t.getTopicID(ctx, msg.PeerID, msg.ReplyTo)),
PortalKey: t.makePortalKeyFromPeer(peer, topicID),
},
TargetMessage: ids.GetMessageIDFromMessage(msg),
TargetMessage: ids.MakeMessageID(peer, msgID),
Reactions: &bridgev2.ReactionSyncData{Users: users, HasAllUsers: isFull},
})