Added Messenger.SendEmojiReaction()

stubbed SendEmojiReactionRetraction() added new protocol/EmojiReaction{}
This commit is contained in:
Samuel Hawksby-Robinson 2020-07-20 18:06:38 +01:00 committed by Andrea Maria Piana
parent 1dadab9104
commit 2d9db29f31
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
2 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,26 @@
package protocol
import "github.com/status-im/status-go/protocol/protobuf"
// EmojiReaction represents an emoji reaction from a user in the application layer, used for persistence, querying and
// signaling
type EmojiReaction struct {
// ID calculated as keccak256(compressedAuthorPubKey, data) where data is unencrypted payload.
ID string
// MessageID the ID of the target message that the user wishes to react to
MessageID string
// ChatID the ID of the chat the message belongs to, for query efficiency the ChatID is stored in the db even though the
// target message also stores the ChatID
ChatID string
// EmojiID the ID of the emoji the user wishes to react with
EmojiID protobuf.EmojiReaction_Type
// From is a public key of the author of the emoji reaction.
From string
// Retracted represents whether the user has chosen to remove a previously given reaction
Retracted bool
}

View File

@ -91,6 +91,7 @@ type MessengerResponse struct {
Messages []*Message `json:"messages,omitempty"` Messages []*Message `json:"messages,omitempty"`
Contacts []*Contact `json:"contacts,omitempty"` Contacts []*Contact `json:"contacts,omitempty"`
Installations []*multidevice.Installation `json:"installations,omitempty"` Installations []*multidevice.Installation `json:"installations,omitempty"`
EmojiReactions []*EmojiReaction `json:"emoji_reactions"`
} }
func (m *MessengerResponse) IsEmpty() bool { func (m *MessengerResponse) IsEmpty() bool {
@ -3235,3 +3236,54 @@ func generateAliasAndIdenticon(pk string) (string, string, error) {
return name, identicon, nil return name, identicon, nil
} }
func (m *Messenger) SendEmojiReaction(ctx context.Context, chatID, messageID string, emojiId int) (*MessengerResponse, error) {
var response MessengerResponse
chat, ok := m.allChats[chatID]
if !ok {
return nil, ErrChatNotFound
}
clock, _ := chat.NextClockAndTimestamp(m.getTimesource())
emojiReaction := &protobuf.EmojiReaction{
Clock: clock,
MessageId: messageID,
Type: protobuf.EmojiReaction_Type(emojiId),
}
encodedMessage, err := proto.Marshal(emojiReaction)
if err != nil {
return nil, err
}
id, err := m.dispatchMessage(ctx, &RawMessage{
LocalChatID: chatID,
Payload: encodedMessage,
MessageType: protobuf.ApplicationMetadataMessage_EMOJI_REACTION,
ResendAutomatically: true,
})
if err != nil {
return nil, err
}
emojiR := &EmojiReaction{
ID: types.EncodeHex(id),
MessageID: messageID,
ChatID: chatID,
EmojiID: protobuf.EmojiReaction_Type(emojiId),
From: types.EncodeHex(crypto.FromECDSAPub(&m.identity.PublicKey)),
Retracted: false,
}
response.EmojiReactions = []*EmojiReaction{emojiR}
response.Chats = []*Chat{chat}
// TODO emoji reaction persistence
return &response, nil
}
func (m *Messenger) SendEmojiReactionRetraction(ctx context.Context, EmojiReactionID string) (*MessengerResponse, error) {
// TODO
}