|
|
@ -1,4 +1,4 @@
|
|
|
|
import type { ChatMessage } from 'tailchat-shared';
|
|
|
|
import { ChatMessage, useUsernames } from 'tailchat-shared';
|
|
|
|
import _groupBy from 'lodash/groupBy';
|
|
|
|
import _groupBy from 'lodash/groupBy';
|
|
|
|
import _uniqBy from 'lodash/uniqBy';
|
|
|
|
import _uniqBy from 'lodash/uniqBy';
|
|
|
|
import { useMemo } from 'react';
|
|
|
|
import { useMemo } from 'react';
|
|
|
@ -6,13 +6,41 @@ import { Emoji } from '@/components/Emoji';
|
|
|
|
import React from 'react';
|
|
|
|
import React from 'react';
|
|
|
|
import { Tooltip } from 'antd';
|
|
|
|
import { Tooltip } from 'antd';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface GroupedReaction {
|
|
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
|
|
length: number;
|
|
|
|
|
|
|
|
users: string[];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 消息反应的用户名
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
const ReactionItem: React.FC<{ reaction: GroupedReaction }> = React.memo(
|
|
|
|
|
|
|
|
(props) => {
|
|
|
|
|
|
|
|
const { reaction } = props;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
<div className="py-0.5 px-1 bg-black bg-opacity-20 rounded flex">
|
|
|
|
|
|
|
|
<Tooltip title={useUsernames(reaction.users)}>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
|
|
|
<Emoji emoji={reaction.name} />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{reaction.length > 1 && <span>{reaction.length}</span>}
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</Tooltip>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
ReactionItem.displayName = 'ReactionItem';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 消息反应表情渲染
|
|
|
|
* 消息反应表情渲染
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function useMessageReactions(payload: ChatMessage) {
|
|
|
|
export function useMessageReactions(payload: ChatMessage) {
|
|
|
|
const reactions = payload.reactions ?? [];
|
|
|
|
const reactions = payload.reactions ?? [];
|
|
|
|
|
|
|
|
|
|
|
|
const groupedReactions = useMemo(() => {
|
|
|
|
const groupedReactions: GroupedReaction[] = useMemo(() => {
|
|
|
|
const groups = _groupBy(reactions, 'name');
|
|
|
|
const groups = _groupBy(reactions, 'name');
|
|
|
|
|
|
|
|
|
|
|
|
return Object.keys(groups).map((name) => {
|
|
|
|
return Object.keys(groups).map((name) => {
|
|
|
@ -28,14 +56,7 @@ export function useMessageReactions(payload: ChatMessage) {
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div className="flex chat-message-reactions gap-1">
|
|
|
|
<div className="flex chat-message-reactions gap-1">
|
|
|
|
{groupedReactions.map((reaction) => (
|
|
|
|
{groupedReactions.map((reaction) => (
|
|
|
|
<div
|
|
|
|
<ReactionItem key={reaction.name} reaction={reaction} />
|
|
|
|
key={reaction.name}
|
|
|
|
|
|
|
|
className="py-0.5 px-1 bg-black bg-opacity-20 rounded flex"
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
<Emoji emoji={reaction.name} />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{reaction.length > 1 && <span>{reaction.length}</span>}
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
))}
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
);
|
|
|
|