handletelegram: handle UpdateMessageReactions
This commit is contained in:
@@ -210,6 +210,7 @@ func (t *TelegramClient) onUpdateNewMessage(ctx context.Context, entities tg.Ent
|
|||||||
log.Info().Int64("user_id", contact.UserID).Msg("received contact")
|
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]{
|
res := t.main.Bridge.QueueRemoteEvent(t.userLogin, &simplevent.Message[*tg.Message]{
|
||||||
EventMeta: simplevent.EventMeta{
|
EventMeta: simplevent.EventMeta{
|
||||||
Type: bridgev2.RemoteEventMessage,
|
Type: bridgev2.RemoteEventMessage,
|
||||||
@@ -222,7 +223,7 @@ func (t *TelegramClient) onUpdateNewMessage(ctx context.Context, entities tg.Ent
|
|||||||
Stringer("peer_id", msg.PeerID)
|
Stringer("peer_id", msg.PeerID)
|
||||||
},
|
},
|
||||||
Sender: sender,
|
Sender: sender,
|
||||||
PortalKey: t.makePortalKeyFromPeer(msg.PeerID, t.getTopicID(ctx, msg.PeerID, msg.ReplyTo)),
|
PortalKey: t.makePortalKeyFromPeer(msg.PeerID, topicID),
|
||||||
CreatePortal: true,
|
CreatePortal: true,
|
||||||
Timestamp: time.Unix(int64(msg.Date), 0),
|
Timestamp: time.Unix(int64(msg.Date), 0),
|
||||||
StreamOrder: int64(msg.GetID()),
|
StreamOrder: int64(msg.GetID()),
|
||||||
@@ -236,7 +237,7 @@ func (t *TelegramClient) onUpdateNewMessage(ctx context.Context, entities tg.Ent
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return t.handleTelegramReactions(ctx, msg)
|
return t.handleTelegramReactions(ctx, msg.PeerID, topicID, msg.ID, msg.Reactions)
|
||||||
case *tg.MessageService:
|
case *tg.MessageService:
|
||||||
return t.handleServiceMessage(ctx, msg)
|
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)
|
return t.onMessageEdit(ctx, update)
|
||||||
case *tg.UpdateEditChannelMessage:
|
case *tg.UpdateEditChannelMessage:
|
||||||
return t.onMessageEdit(ctx, update)
|
return t.onMessageEdit(ctx, update)
|
||||||
|
case *tg.UpdateMessageReactions:
|
||||||
|
return t.onMessageReactions(ctx, update)
|
||||||
case *tg.UpdateUserTyping:
|
case *tg.UpdateUserTyping:
|
||||||
return t.handleTyping(t.makePortalKeyFromID(ids.PeerTypeUser, update.UserID, 0), t.senderForUserID(update.UserID), update.Action)
|
return t.handleTyping(t.makePortalKeyFromID(ids.PeerTypeUser, update.UserID, 0), t.senderForUserID(update.UserID), update.Action)
|
||||||
case *tg.UpdateChatUserTyping:
|
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 {
|
func (t *TelegramClient) onMessageEdit(ctx context.Context, update IGetMessage) error {
|
||||||
msg, ok := update.GetMessage().(*tg.Message)
|
msg, ok := update.GetMessage().(*tg.Message)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -957,12 +964,13 @@ func (t *TelegramClient) onMessageEdit(ctx context.Context, update IGetMessage)
|
|||||||
return nil
|
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 {
|
if err != nil {
|
||||||
zerolog.Ctx(ctx).Err(err).Msg("Failed to handle reactions on edited message")
|
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)
|
portal, err := t.main.Bridge.GetPortalByKey(ctx, portalKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -105,13 +105,13 @@ func computeEmojiAndID(reaction tg.ReactionClass, customEmojis map[networkid.Emo
|
|||||||
return
|
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().
|
log := zerolog.Ctx(ctx).With().
|
||||||
Str("handler", "handle_telegram_reactions").
|
Str("handler", "handle_telegram_reactions").
|
||||||
Int("message_id", msg.ID).
|
Int("message_id", msgID).
|
||||||
Logger()
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to compute reactions: %w", err)
|
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{
|
EventMeta: simplevent.EventMeta{
|
||||||
Type: bridgev2.RemoteEventReactionSync,
|
Type: bridgev2.RemoteEventReactionSync,
|
||||||
LogContext: func(c zerolog.Context) zerolog.Context {
|
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},
|
Reactions: &bridgev2.ReactionSyncData{Users: users, HasAllUsers: isFull},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user