diff --git a/protocol/message_persistence.go b/protocol/message_persistence.go index 711e9c146..893062c00 100644 --- a/protocol/message_persistence.go +++ b/protocol/message_persistence.go @@ -757,7 +757,6 @@ func (db sqlitePersistence) tableEmojiReactionsAllFieldsCount() int { return strings.Count(db.tableEmojiReactionsAllFields(), ",") + 1 } - func (db sqlitePersistence) EmojiReactionByID(id string) (*EmojiReaction, error) { tx, err := db.db.BeginTx(context.Background(), &sql.TxOptions{}) if err != nil { diff --git a/protocol/messenger.go b/protocol/messenger.go index 910fdb78c..67ffcfdd8 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -3238,13 +3238,15 @@ func generateAliasAndIdenticon(pk string) (string, string, error) { } func (m *Messenger) SendEmojiReaction(ctx context.Context, chatID, messageID string, emojiID int) (*MessengerResponse, error) { + m.mutex.Lock() + defer m.mutex.Unlock() + var response MessengerResponse chat, ok := m.allChats[chatID] if !ok { return nil, ErrChatNotFound } - clock, _ := chat.NextClockAndTimestamp(m.getTimesource()) emojiReaction := &protobuf.EmojiReaction{ @@ -3288,10 +3290,49 @@ func (m *Messenger) SendEmojiReaction(ctx context.Context, chatID, messageID str return &response, nil } -func (m *Messenger) SendEmojiReactionRetraction(ctx context.Context, EmojiReactionID string) (*MessengerResponse, error) { - // TODO - +func (m *Messenger) SendEmojiReactionRetraction(ctx context.Context, emojiReactionID string) (*MessengerResponse, error) { // TODO check that the sender is the key owner - return nil, nil + m.mutex.Lock() + defer m.mutex.Unlock() + + emojiReaction, err := m.persistence.EmojiReactionByID(emojiReactionID) + if err != nil { + return nil, err + } + + chat, ok := m.allChats[emojiReaction.ChatID] + if !ok { + return nil, ErrChatNotFound + } + clock, _ := chat.NextClockAndTimestamp(m.getTimesource()) + + // Build the EmojiReactionRetraction protobuf struct + emojiRR := &protobuf.EmojiReactionRetraction{ + Clock: clock, + EmojiReactionId: emojiReactionID, + } + encodedMessage, err := proto.Marshal(emojiRR) + if err != nil { + return nil, err + } + + // Send the marshalled EmojiReactionRetraction protobuf + _, err = m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: emojiReaction.ChatID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_EMOJI_REACTION_RETRACTION, + ResendAutomatically: true, + }) + if err != nil { + return nil, err + } + + response := MessengerResponse{} + emojiReaction.Retracted = true + response.EmojiReactions = []*EmojiReaction{emojiReaction} + + // TODO update the retraction in the db + + return &response, nil }