add MCuteEvent component and implement cute event commands (wave, poke)

This commit is contained in:
Rye committed 2026-03-08 18:49:07 +01:00
1 parent a38ad8995e
commit df6b274d7e
3 files changed
+101 -5

No files matched your search

@@ -33,6 +33,7 @@ import { ImageViewer } from './image-viewer';
import { PdfViewer } from './Pdf-viewer';
import { TextViewer } from './text-viewer';
import { ClientSideHoverFreeze } from './ClientSideHoverFreeze';
import { MCuteEvent } from './message/MCuteEvent';
type RenderMessageContentProps = {
displayName: string;
@@ -348,6 +349,15 @@ function RenderMessageContentInternal({
if (msgType === MsgType.Location) return <MLocation content={content} />;
if (msgType === 'm.bad.encrypted') return <MBadEncrypted />;
// cute events
if (msgType === 'im.fluffychat.cute_event')
return (
<MCuteEvent
content={content}
type={content?.cute_type}
mentionedUserIds={content?.mentionedUserIds}
/>
);
return <UnsupportedContent />;
}
+58
View File
@@ -0,0 +1,58 @@
// rendering for cute events (e.g. hug, cuddle, etc.)
import { MessageTextBody } from './layout';
enum CuteEventType {
Hug = 'hug',
Cuddle = 'cuddle',
Wave = 'wave',
Poke = 'poke',
// currently unused, but could be added in the future if there's demand for it
Kiss = 'kiss',
}
type MCuteEventProps = {
// Content is only used to check if the event is valid, the actual text is generated based on the type and mentioned users
content: string | undefined;
// The type of cute event (e.g. hug, cuddle, etc.)
type: CuteEventType;
// The user IDs mentioned in the event (e.g. the target of the hug/cuddle/etc.)
mentionedUserIds?: string[];
};
export function MCuteEvent({ content, type, mentionedUserIds }: MCuteEventProps) {
if (!content) return null;
let cuteText = '';
switch (type) {
case CuteEventType.Hug:
cuteText = `hugs ${mentionedUserIds?.[0] || 'you'}`;
break;
case CuteEventType.Cuddle:
cuteText = `cuddles ${mentionedUserIds?.[0] || 'you'}`;
break;
case CuteEventType.Kiss:
// in here for future expansion
// would need some kind of filtering to prevent abuse (e.g. someone sending a kiss event with a random user ID to harass them)
// cuteText = `kisses ${mentionedUserIds?.[0] || 'you'}`;
cuteText =
'currently disabled kiss event, in light of potential abuse, may be added in the future with proper filtering';
break;
case CuteEventType.Wave:
cuteText = `waves at ${mentionedUserIds?.[0] || 'you'}`;
break;
case CuteEventType.Poke:
cuteText = `pokes ${mentionedUserIds?.[0] || 'you'}`;
break;
default:
cuteText = `sends ${mentionedUserIds?.[0] || 'you'} a cute event`;
}
return (
<MessageTextBody notice>
<em data-cute-event data-cute-type={type}>
{cuteText}
</em>
</MessageTextBody>
);
}
+33 -5
View File
@@ -31,7 +31,6 @@ import { useSetting } from '$state/hooks/settings';
import { settingsAtom } from '$state/settings';
import { createRoomEncryptionState } from '$components/create-room';
import { parsePronounsInput } from '$utils/pronouns';
import { escapeHTML } from '$utils/transformation';
import { useRoomNavigate } from './useRoomNavigate';
import { enrichWidgetUrl } from './useRoomWidgets';
import { useUserProfile } from './useUserProfile';
@@ -245,6 +244,9 @@ export enum Command {
// Cute Events
Hug = 'hug',
Cuddle = 'cuddle',
// our own cute events, not part of FluffyChat or other clients
Wave = 'wave',
Poke = 'poke',
}
export type CommandContent = {
@@ -1312,8 +1314,6 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
},
cute_type: 'hug',
body: `🤗`,
format: 'org.matrix.custom.html',
formatted_body: `<em>hugs ${escapeHTML(target) ?? 'you'}</em>`,
} as any);
},
},
@@ -1329,8 +1329,36 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
user_ids: target ? [target] : [],
},
body: `😊`,
format: 'org.matrix.custom.html',
formatted_body: `<em>cuddles ${escapeHTML(target) ?? 'you'}</em>`,
} as any);
},
},
[Command.Wave]: {
name: Command.Wave,
description: 'Send a wave to someone. Example: /wave [@user:example.org]',
exe: async (payload) => {
const target = payload.trim();
await mx.sendMessage(room.roomId, {
msgtype: 'im.fluffychat.cute_event',
cute_type: 'wave',
'm.mentions': {
user_ids: target ? [target] : [],
},
body: `👋`,
} as any);
},
},
[Command.Poke]: {
name: Command.Poke,
description: 'Send a poke to someone. Example: /poke [@user:example.org]',
exe: async (payload) => {
const target = payload.trim();
await mx.sendMessage(room.roomId, {
msgtype: 'im.fluffychat.cute_event',
cute_type: 'poke',
'm.mentions': {
user_ids: target ? [target] : [],
},
body: `🫵`,
} as any);
},
},