2020-07-20 17:06:38 +00:00
|
|
|
package protocol
|
|
|
|
|
2020-07-25 14:16:00 +00:00
|
|
|
import (
|
|
|
|
"crypto/ecdsa"
|
2020-07-27 12:27:48 +00:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2020-07-25 14:16:00 +00:00
|
|
|
|
2020-07-25 16:13:08 +00:00
|
|
|
"github.com/golang/protobuf/proto"
|
|
|
|
|
2020-07-27 12:27:48 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/crypto"
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
2020-07-25 14:16:00 +00:00
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
|
|
|
)
|
2020-07-20 17:06:38 +00:00
|
|
|
|
|
|
|
// EmojiReaction represents an emoji reaction from a user in the application layer, used for persistence, querying and
|
|
|
|
// signaling
|
|
|
|
type EmojiReaction struct {
|
2020-07-25 14:16:00 +00:00
|
|
|
protobuf.EmojiReaction
|
|
|
|
|
2020-07-20 17:06:38 +00:00
|
|
|
// From is a public key of the author of the emoji reaction.
|
2020-07-27 12:27:48 +00:00
|
|
|
From string `json:"from,omitempty"`
|
2020-07-25 14:16:00 +00:00
|
|
|
|
|
|
|
// SigPubKey is the ecdsa encoded public key of the emoji reaction author
|
|
|
|
SigPubKey *ecdsa.PublicKey `json:"-"`
|
2020-07-28 07:53:32 +00:00
|
|
|
|
|
|
|
// LocalChatID is the chatID of the local chat (one-to-one are not symmetric)
|
|
|
|
LocalChatID string `json:"localChatId"`
|
2020-07-25 14:16:00 +00:00
|
|
|
}
|
|
|
|
|
2020-07-28 07:53:32 +00:00
|
|
|
// ID is the Keccak256() contatenation of From-MessageID-EmojiType
|
2020-07-27 12:27:48 +00:00
|
|
|
func (e EmojiReaction) ID() string {
|
2020-07-28 07:53:32 +00:00
|
|
|
return types.EncodeHex(crypto.Keccak256([]byte(fmt.Sprintf("%s%s%d", e.From, e.MessageId, e.Type))))
|
2020-07-27 12:27:48 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 14:16:00 +00:00
|
|
|
// GetSigPubKey returns an ecdsa encoded public key
|
2020-07-25 16:13:08 +00:00
|
|
|
// this function is required to implement the ChatEntity interface
|
2020-07-25 14:16:00 +00:00
|
|
|
func (e EmojiReaction) GetSigPubKey() *ecdsa.PublicKey {
|
|
|
|
return e.SigPubKey
|
2020-07-20 17:06:38 +00:00
|
|
|
}
|
2020-07-25 16:13:08 +00:00
|
|
|
|
|
|
|
// GetProtoBuf returns the struct's embedded protobuf struct
|
|
|
|
// this function is required to implement the ChatEntity interface
|
|
|
|
func (e EmojiReaction) GetProtobuf() proto.Message {
|
|
|
|
return &e.EmojiReaction
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetMessageType a setter for the MessageType field
|
|
|
|
// this function is required to implement the ChatEntity interface
|
|
|
|
func (e *EmojiReaction) SetMessageType(messageType protobuf.MessageType) {
|
|
|
|
e.MessageType = messageType
|
|
|
|
}
|
2020-07-27 12:27:48 +00:00
|
|
|
|
2020-07-27 15:57:01 +00:00
|
|
|
func (e EmojiReaction) MarshalJSON() ([]byte, error) {
|
2020-07-27 12:27:48 +00:00
|
|
|
item := struct {
|
2020-07-28 11:37:17 +00:00
|
|
|
ID string `json:"id"`
|
|
|
|
Clock uint64 `json:"clock,omitempty"`
|
|
|
|
ChatID string `json:"chatId,omitempty"`
|
|
|
|
LocalChatID string `json:"localChatId,omitempty"`
|
|
|
|
From string `json:"from"`
|
|
|
|
MessageID string `json:"messageId,omitempty"`
|
|
|
|
MessageType protobuf.MessageType `json:"messageType,omitempty"`
|
2020-07-28 13:07:23 +00:00
|
|
|
Retracted bool `json:"retracted,omitempty"`
|
2020-07-28 11:37:17 +00:00
|
|
|
EmojiID protobuf.EmojiReaction_Type `json:"emojiId,omitempty"`
|
2020-07-27 12:27:48 +00:00
|
|
|
}{
|
|
|
|
|
2020-07-28 11:37:17 +00:00
|
|
|
ID: e.ID(),
|
|
|
|
Clock: e.Clock,
|
|
|
|
ChatID: e.ChatId,
|
|
|
|
LocalChatID: e.LocalChatID,
|
|
|
|
From: e.From,
|
|
|
|
MessageID: e.MessageId,
|
|
|
|
MessageType: e.MessageType,
|
2020-07-28 13:07:23 +00:00
|
|
|
Retracted: e.Retracted,
|
2020-07-28 11:37:17 +00:00
|
|
|
EmojiID: e.Type,
|
|
|
|
}
|
2020-07-27 15:57:01 +00:00
|
|
|
|
2020-07-27 12:27:48 +00:00
|
|
|
return json.Marshal(item)
|
|
|
|
}
|
2021-01-15 17:47:30 +00:00
|
|
|
|
|
|
|
// WrapGroupMessage indicates whether we should wrap this in membership information
|
|
|
|
func (e EmojiReaction) WrapGroupMessage() bool {
|
|
|
|
return false
|
|
|
|
}
|