unify reaction type

This commit is contained in:
Pavel Prichodko 2022-06-09 15:56:19 +02:00 committed by Felicio Mununga
parent 54020b4be6
commit 6ce1344af1
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
2 changed files with 15 additions and 29 deletions

View File

@ -1,12 +1,6 @@
import { EmojiReaction } from '../../../protos/emoji-reaction'
import type { EmojiReaction } from '../../../protos/emoji-reaction'
type Reaction =
| 'heart'
| 'thumbs-up'
| 'thumbs-down'
| 'smile'
| 'sad'
| 'angry'
type Reaction = Exclude<`${EmojiReaction.Type}`, 'UNKNOWN_EMOJI_REACTION_TYPE'>
export type Reactions = {
[key in Reaction]: {
@ -15,38 +9,30 @@ export type Reactions = {
}
}
const REACTION_MAP: Record<EmojiReaction.Type, string> = {
[EmojiReaction.Type.LOVE]: 'heart',
[EmojiReaction.Type.THUMBS_UP]: 'thumbs-up',
[EmojiReaction.Type.THUMBS_DOWN]: 'thumbs-down',
[EmojiReaction.Type.LAUGH]: 'smile',
[EmojiReaction.Type.SAD]: 'sad',
[EmojiReaction.Type.ANGRY]: 'angry',
[EmojiReaction.Type.UNKNOWN_EMOJI_REACTION_TYPE]: 'unknown',
}
export function getReactions(
reaction: EmojiReaction,
reactions: Reactions,
isMe: boolean
) {
// fixme!: type
const type = REACTION_MAP[reaction.type] as Reaction
const isRetracted = reaction.retracted
const { type, retracted } = reaction
if (type === 'UNKNOWN_EMOJI_REACTION_TYPE') {
return reactions
}
const _reaction = {
count: reactions[type].count,
me: reactions[type].me,
}
if (isRetracted && _reaction.count !== 0) {
if (retracted && _reaction.count !== 0) {
_reaction.count -= 1
} else {
_reaction.count += 1
}
if (isMe) {
_reaction.me = isRetracted ? false : true
_reaction.me = retracted ? false : true
}
return {

View File

@ -19,27 +19,27 @@ export function mapChatMessage(
channelId,
pinned: false,
reactions: {
'thumbs-up': {
THUMBS_UP: {
count: 0,
me: false,
},
'thumbs-down': {
THUMBS_DOWN: {
count: 0,
me: false,
},
heart: {
LOVE: {
count: 0,
me: false,
},
smile: {
LAUGH: {
count: 0,
me: false,
},
sad: {
SAD: {
count: 0,
me: false,
},
angry: {
ANGRY: {
count: 0,
me: false,
},