(message: Element)
| 62 | }; |
| 63 | |
| 64 | export 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 | |
| 97 | const chatStates: DmChatState[] = [ |
| 98 | 'active', |
no test coverage detected