Skip to content

Commit 3ee8746

Browse files
committed
refactor(emoji): change API to accept hexcodes instead + clean up
This is necessary, because passing the direct UTF emoji made it so that we had to let the OS show the emoji so it could look bad on some OSes. Plus using the hex makes sure we have control over the size. This commit also removes the old V1 API because no clients use it anymore.
1 parent 063580a commit 3ee8746

File tree

3 files changed

+8
-18
lines changed

3 files changed

+8
-18
lines changed

protocol/emoji_reaction.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import (
1414
"github.com/status-im/status-go/protocol/protobuf"
1515
)
1616

17-
// There is no foolproof way to validate emojis, but this regex should cover all standard emojis
18-
// it will also allow some non-emoji unicode characters, but that's not a big issue
19-
var emojiRegex = regexp.MustCompile("(?:\u00A9|\u00AE|[\u2000-\u3300]|[\U0001F000-\U0001FBFF])")
17+
// Validates that the emoji string is a valid hex string (used for emojis hexcodes
18+
// eg: 1f385-1f3fe
19+
var emojiRegex = regexp.MustCompile("[a-f0-9\\-]+")
2020

2121
// EmojiReaction represents an emoji reaction from a user in the application layer, used for persistence, querying and
2222
// signaling

protocol/messenger_emoji_reactions.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ func (m *Messenger) CheckMaxNumberOfEmojiReactionsPerMessage(chatID string, mess
5757
return nil
5858
}
5959

60-
// TODO remove emojiID once the client supports sending custom emojis
61-
func (m *Messenger) SendEmojiReaction(ctx context.Context, chatID, messageID string, emojiID protobuf.EmojiReaction_Type, emoji string) (*MessengerResponse, error) {
60+
func (m *Messenger) SendEmojiReaction(ctx context.Context, chatID, messageID string, emoji string) (*MessengerResponse, error) {
6261
var response MessengerResponse
6362

6463
chat, ok := m.allChats.Load(chatID)
@@ -68,10 +67,7 @@ func (m *Messenger) SendEmojiReaction(ctx context.Context, chatID, messageID str
6867
clock, _ := chat.NextClockAndTimestamp(m.getTimesource())
6968

7069
if emoji == "" {
71-
emoji = ConvertEmojiIDToString(emojiID)
72-
if emoji == "" {
73-
return nil, errors.New("invalid emojiID")
74-
}
70+
return nil, errors.New("no emoji provided")
7571
}
7672

7773
// Validate that the emoji is valid
@@ -89,7 +85,7 @@ func (m *Messenger) SendEmojiReaction(ctx context.Context, chatID, messageID str
8985
Clock: clock,
9086
MessageId: messageID,
9187
ChatId: chatID,
92-
Type: emojiID,
88+
Type: protobuf.EmojiReaction_UNKNOWN_EMOJI_REACTION_TYPE,
9389
Emoji: emoji,
9490
},
9591
LocalChatID: chatID,

services/ext/api.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -978,14 +978,8 @@ func (api *PublicAPI) RegisteredForPushNotifications() (bool, error) {
978978
}
979979

980980
// Emoji
981-
982-
func (api *PublicAPI) SendEmojiReaction(ctx context.Context, chatID, messageID string, emojiID protobuf.EmojiReaction_Type) (*protocol.MessengerResponse, error) {
983-
return api.service.messenger.SendEmojiReaction(ctx, chatID, messageID, emojiID, "")
984-
}
985-
986-
// TODO remove SendEmojiReaction and remove the V2 when the client supports sending custom emojis
987-
func (api *PublicAPI) SendEmojiReactionV2(ctx context.Context, chatID, messageID string, emoji string) (*protocol.MessengerResponse, error) {
988-
return api.service.messenger.SendEmojiReaction(ctx, chatID, messageID, protobuf.EmojiReaction_UNKNOWN_EMOJI_REACTION_TYPE, emoji)
981+
func (api *PublicAPI) SendEmojiReaction(ctx context.Context, chatID, messageID string, emoji string) (*protocol.MessengerResponse, error) {
982+
return api.service.messenger.SendEmojiReaction(ctx, chatID, messageID, emoji)
989983
}
990984

991985
func (api *PublicAPI) SendEmojiReactionRetraction(ctx context.Context, emojiReactionID string) (*protocol.MessengerResponse, error) {

0 commit comments

Comments
 (0)