handletelegram: don't sync empty reactions on new messages
This commit is contained in:
@@ -243,7 +243,10 @@ func (tc *TelegramClient) onUpdateNewMessage(ctx context.Context, entities tg.En
|
||||
return err
|
||||
}
|
||||
|
||||
return tc.handleTelegramReactions(ctx, msg.PeerID, topicID, msg.ID, msg.Reactions)
|
||||
if len(msg.Reactions.Results) > 0 {
|
||||
return tc.handleTelegramReactions(ctx, msg.PeerID, topicID, msg.ID, msg.Reactions, "updateNewMessage")
|
||||
}
|
||||
return nil
|
||||
case *tg.MessageService:
|
||||
return tc.handleServiceMessage(ctx, msg)
|
||||
|
||||
@@ -958,7 +961,7 @@ func (tc *TelegramClient) onUpdate(ctx context.Context, e tg.Entities, upd tg.Up
|
||||
}
|
||||
|
||||
func (tc *TelegramClient) onMessageReactions(ctx context.Context, update *tg.UpdateMessageReactions) error {
|
||||
return tc.handleTelegramReactions(ctx, update.Peer, update.TopMsgID, update.MsgID, update.Reactions)
|
||||
return tc.handleTelegramReactions(ctx, update.Peer, update.TopMsgID, update.MsgID, update.Reactions, "updateMessageReactions")
|
||||
}
|
||||
|
||||
func (tc *TelegramClient) onMessageEdit(ctx context.Context, update IGetMessage) error {
|
||||
@@ -975,7 +978,7 @@ func (tc *TelegramClient) onMessageEdit(ctx context.Context, update IGetMessage)
|
||||
// with an empty reactions list, which would confuse the handle method. Therefore, just don't sync reactions
|
||||
// on channel message edits.
|
||||
if _, isChannel := msg.PeerID.(*tg.PeerChannel); !isChannel {
|
||||
err := tc.handleTelegramReactions(ctx, msg.PeerID, topicID, msg.ID, msg.Reactions)
|
||||
err := tc.handleTelegramReactions(ctx, msg.PeerID, topicID, msg.ID, msg.Reactions, "updateMessageEdit")
|
||||
if err != nil {
|
||||
zerolog.Ctx(ctx).Err(err).Msg("Failed to handle reactions on edited message")
|
||||
}
|
||||
|
||||
@@ -155,9 +155,10 @@ func (tc *TelegramClient) prepareReactionSync(ctx context.Context, peer tg.PeerC
|
||||
return &bridgev2.ReactionSyncData{Users: users, HasAllUsers: isFull}, nil
|
||||
}
|
||||
|
||||
func (tc *TelegramClient) handleTelegramReactions(ctx context.Context, peer tg.PeerClass, topicID, msgID int, reactions tg.MessageReactions) error {
|
||||
func (tc *TelegramClient) handleTelegramReactions(ctx context.Context, peer tg.PeerClass, topicID, msgID int, reactions tg.MessageReactions, source string) error {
|
||||
ctx = zerolog.Ctx(ctx).With().
|
||||
Str("handler", "handle_telegram_reactions").
|
||||
Str("sync_source", source).
|
||||
Int("message_id", msgID).
|
||||
Logger().WithContext(ctx)
|
||||
|
||||
@@ -170,7 +171,7 @@ func (tc *TelegramClient) handleTelegramReactions(ctx context.Context, peer tg.P
|
||||
EventMeta: simplevent.EventMeta{
|
||||
Type: bridgev2.RemoteEventReactionSync,
|
||||
LogContext: func(c zerolog.Context) zerolog.Context {
|
||||
return c.Int("message_id", msgID)
|
||||
return c.Int("message_id", msgID).Str("sync_source", source)
|
||||
},
|
||||
PortalKey: tc.makePortalKeyFromPeer(peer, topicID),
|
||||
},
|
||||
@@ -307,7 +308,7 @@ func (tc *TelegramClient) pollForReactions(ctx context.Context, portalKey networ
|
||||
EventMeta: simplevent.EventMeta{
|
||||
Type: bridgev2.RemoteEventReactionSync,
|
||||
LogContext: func(c zerolog.Context) zerolog.Context {
|
||||
return c.Int("message_id", reaction.MsgID)
|
||||
return c.Int("message_id", reaction.MsgID).Str("sync_source", "poll")
|
||||
},
|
||||
PortalKey: dbMsg.Room,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user