MCPcopy Create free account
hub / github.com/dailydotdev/apps / parseRoomMessage

Function parseRoomMessage

packages/shared/src/features/messages/muc.ts:64–95  ·  view source on GitHub ↗
(message: Element)

Source from the content-addressed store, hash-verified

62};
63
64export const parseRoomMessage = (message: Element): RoomMessage | null => {
65 if (message.getAttribute('type') !== 'groupchat') {
66 return null;
67 }
68
69 const body = textOf(message, 'body');
70 const occupant = splitOccupant(message.getAttribute('from'));
71 // Subject changes and bodyless stanzas (chat states) are not messages.
72 if (!body || !occupant || childOf(message, 'subject')) {
73 return null;
74 }
75
76 const senderId = senderFromNick(occupant.nick);
77 if (!senderId) {
78 return null;
79 }
80
81 const stamp = childOf(message, 'delay', NS_DELAY)?.getAttribute('stamp');
82 const originId = childOf(message, 'origin-id', NS_SID)?.getAttribute('id');
83
84 return {
85 id:
86 originId ??
87 message.getAttribute('id') ??
88 `${senderId}-${stamp ?? Date.now()}`,
89 roomJid: occupant.roomJid,
90 senderId,
91 body,
92 createdAt: stamp ?? new Date().toISOString(),
93 ...(stamp && { isHistory: true }),
94 };
95};
96
97const chatStates: DmChatState[] = [
98 'active',

Callers 2

muc.spec.tsFile · 0.90
onMessageFunction · 0.90

Calls 5

splitOccupantFunction · 0.85
senderFromNickFunction · 0.85
nowMethod · 0.80
textOfFunction · 0.70
childOfFunction · 0.70

Tested by

no test coverage detected