mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-20 15:36:18 +00:00
feat(mentions): client api types, store, snapshot + message hooks
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import { MarkMentionsReadComposer, MentionReceivedEvent, MentionsListEvent, RequestMentionsComposer } from '@nitrots/nitro-renderer';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
import { GetConfigurationValue, IMentionEntry, LocalizeText, NotificationBubbleType, PlaySound, SendMessageComposer, SoundNames } from '../../api';
|
||||
import { useMessageEvent } from '../events';
|
||||
import { useNotificationActions } from '../notification';
|
||||
import { addMention, setMentions } from './mentionsStore';
|
||||
|
||||
// MarkMentionsReadComposer is part of the mentions wire contract; it is sent by
|
||||
// the UI layer (later phase) when the user opens / clears the mentions window.
|
||||
void MarkMentionsReadComposer;
|
||||
|
||||
export const useMentionMessages = (): void =>
|
||||
{
|
||||
const { showSingleBubble } = useNotificationActions();
|
||||
|
||||
const onMentionsList = useCallback((event: MentionsListEvent) =>
|
||||
{
|
||||
const list = event.getParser().mentions;
|
||||
|
||||
setMentions(list.map(m => ({
|
||||
mentionId: m.mentionId,
|
||||
senderId: m.senderId,
|
||||
senderUsername: m.senderUsername,
|
||||
roomId: m.roomId,
|
||||
roomName: m.roomName,
|
||||
message: m.message,
|
||||
mentionType: m.mentionType,
|
||||
timestamp: m.timestamp,
|
||||
read: m.read
|
||||
})));
|
||||
}, []);
|
||||
|
||||
const onMentionReceived = useCallback((event: MentionReceivedEvent) =>
|
||||
{
|
||||
if(!GetConfigurationValue<boolean>('mentions_ui.enabled', true)) return;
|
||||
|
||||
const m = event.getParser().mention;
|
||||
|
||||
const entry: IMentionEntry = {
|
||||
mentionId: m.mentionId,
|
||||
senderId: m.senderId,
|
||||
senderUsername: m.senderUsername,
|
||||
roomId: m.roomId,
|
||||
roomName: m.roomName,
|
||||
message: m.message,
|
||||
mentionType: m.mentionType,
|
||||
timestamp: m.timestamp,
|
||||
read: false
|
||||
};
|
||||
|
||||
addMention(entry);
|
||||
|
||||
if(GetConfigurationValue<boolean>('mentions_ui.sound', true)) PlaySound(SoundNames.MESSENGER_MESSAGE_RECEIVED);
|
||||
|
||||
showSingleBubble(
|
||||
LocalizeText('mentions.notification', [ 'sender', 'room' ], [ entry.senderUsername, entry.roomName ]),
|
||||
NotificationBubbleType.INFO,
|
||||
null,
|
||||
'mentions/toggle',
|
||||
entry.senderUsername
|
||||
);
|
||||
}, [ showSingleBubble ]);
|
||||
|
||||
useMessageEvent<MentionsListEvent>(MentionsListEvent, onMentionsList);
|
||||
useMessageEvent<MentionReceivedEvent>(MentionReceivedEvent, onMentionReceived);
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
if(!GetConfigurationValue<boolean>('mentions_ui.enabled', true)) return;
|
||||
|
||||
SendMessageComposer(new RequestMentionsComposer());
|
||||
}, []);
|
||||
};
|
||||
Reference in New Issue
Block a user