diff --git a/lib/shared/reaction-utils.js b/lib/shared/reaction-utils.js new file mode 100644 --- /dev/null +++ b/lib/shared/reaction-utils.js @@ -0,0 +1,29 @@ +// @flow + +import invariant from 'invariant'; + +import type { MessageReactionInfo } from '../selectors/chat-selectors'; + +function stringForReactionList( + reactions: $ReadOnlyMap, +): string { + let reactionText = ''; + let index = 0; + for (const key of reactions.keys()) { + const reactionInfo = reactions.get(key); + invariant(reactionInfo, 'reactionInfo should be set'); + + if (index > 0) { + reactionText += ' '; + } + reactionText += key; + if (reactionInfo.users.size > 1) { + reactionText += ` ${reactionInfo.users.size}`; + } + index++; + } + + return reactionText; +} + +export { stringForReactionList };