mirror of https://github.com/msgbyte/tailchat
feat: 增加消息reactions渲染
parent
ea30bb8894
commit
66fbf1a024
@ -0,0 +1,42 @@
|
||||
import type { ChatMessage } from 'tailchat-shared';
|
||||
import _groupBy from 'lodash/groupBy';
|
||||
import _uniqBy from 'lodash/uniqBy';
|
||||
import { useMemo } from 'react';
|
||||
import { Emoji } from '@/components/Emoji';
|
||||
import React from 'react';
|
||||
import { Tooltip } from 'antd';
|
||||
|
||||
/**
|
||||
* 消息反应表情渲染
|
||||
*/
|
||||
export function useMessageReactions(payload: ChatMessage) {
|
||||
const reactions = payload.reactions ?? [];
|
||||
|
||||
const groupedReactions = useMemo(() => {
|
||||
const groups = _groupBy(reactions, 'name');
|
||||
|
||||
return Object.keys(groups).map((name) => {
|
||||
const reactions = _uniqBy(groups[name], 'author');
|
||||
return {
|
||||
name,
|
||||
length: reactions.length,
|
||||
users: reactions.map((r) => r.author),
|
||||
};
|
||||
});
|
||||
}, [reactions]);
|
||||
|
||||
return (
|
||||
<div className="flex chat-message-reactions gap-1">
|
||||
{groupedReactions.map((reaction) => (
|
||||
<div
|
||||
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>
|
||||
);
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
import { Emoji as OriginEmoji, EmojiProps } from 'emoji-mart';
|
||||
import React from 'react';
|
||||
|
||||
interface Props extends Omit<EmojiProps, 'size'> {
|
||||
size?: number;
|
||||
}
|
||||
const Emoji: React.FC<Props> = React.memo((props) => {
|
||||
return <OriginEmoji size={16} {...props} />;
|
||||
});
|
||||
Emoji.displayName = 'Emoji';
|
||||
|
||||
export default Emoji;
|
Loading…
Reference in New Issue