Added basic EmojiReaction handler

This commit is contained in:
Samuel Hawksby-Robinson 2020-07-24 14:47:58 +01:00 committed by Andrea Maria Piana
parent eb562122b6
commit 9a775619cd
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
2 changed files with 35 additions and 1 deletions

View File

@ -669,3 +669,26 @@ func (m *MessageHandler) messageExists(messageID string, existingMessagesMap map
}
return false, nil
}
func (m *MessageHandler) HandleEmojiReaction(state *ReceivedMessageState, message protobuf.EmojiReaction) error {
logger := m.logger.With(zap.String("site", "HandleEmojiReaction"))
// TODO change this to chat id directly from the protobuf once it is updated
contact := state.CurrentMessageState.Contact
chat, ok := state.AllChats[contact.ID]
if !ok {
chat = OneToOneFromPublicKey(state.CurrentMessageState.PublicKey, state.Timesource)
// We don't want to show the chat to the user
chat.Active = false
}
logger.Info("Handling emoji reaction")
if chat.LastClockValue < message.Clock {
chat.LastClockValue = message.Clock
}
state.ModifiedChats[chat.ID] = true
state.AllChats[chat.ID] = chat
return nil
}

View File

@ -2056,7 +2056,19 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
}
// We continue in any case, no changes to messenger
continue
case protobuf.EmojiReaction:
err = m.handler.HandleEmojiReaction(messageState, msg.ParsedMessage.(protobuf.EmojiReaction))
if err != nil {
logger.Warn("failed to handle EmojiReaction", zap.Error(err))
continue
}
case protobuf.EmojiReactionRetraction:
err = m.handler.HandleEmojiReactionRetraction(messageState, msg.ParsedMessage.(protobuf.EmojiReactionRetraction))
if err != nil {
logger.Warn("failed to handle EmojiReactionRetraction", zap.Error(err))
continue
}
default:
// Check if is an encrypted PushNotificationRegistration
if msg.Type == protobuf.ApplicationMetadataMessage_PUSH_NOTIFICATION_REGISTRATION {
@ -3291,7 +3303,6 @@ func (m *Messenger) SendEmojiReaction(ctx context.Context, chatID, messageID str
}
func (m *Messenger) SendEmojiReactionRetraction(ctx context.Context, emojiReactionID string) (*MessengerResponse, error) {
m.mutex.Lock()
defer m.mutex.Unlock()