(
args: {
channelId: string;
content: string;
parentEventId?: string | null;
kind?: number | null;
mentionPubkeys?: string[];
mediaTags?: string[][] | null;
emojiTags?: string[][] | null;
},
config: E2eConfig | undefined,
)
| 6914 | } |
| 6915 | |
| 6916 | async function handleSendChannelMessage( |
| 6917 | args: { |
| 6918 | channelId: string; |
| 6919 | content: string; |
| 6920 | parentEventId?: string | null; |
| 6921 | kind?: number | null; |
| 6922 | mentionPubkeys?: string[]; |
| 6923 | mediaTags?: string[][] | null; |
| 6924 | emojiTags?: string[][] | null; |
| 6925 | }, |
| 6926 | config: E2eConfig | undefined, |
| 6927 | ): Promise<RawSendChannelMessageResponse> { |
| 6928 | const kind = args.kind ?? 9; |
| 6929 | const sendMessageDelayMs = config?.mock?.sendMessageDelayMs ?? 0; |
| 6930 | if (sendMessageDelayMs > 0) { |
| 6931 | await new Promise((resolve) => |
| 6932 | window.setTimeout(resolve, sendMessageDelayMs), |
| 6933 | ); |
| 6934 | } |
| 6935 | |
| 6936 | // NIP-92 imeta attachments. The real relay echoes these back on the stored |
| 6937 | // event; mirror that here so attachment renderers (FileCard, images, video) |
| 6938 | // have the imeta tags they key on. `null`/empty → no extra tags. |
| 6939 | const mediaTags = args.mediaTags ?? []; |
| 6940 | // NIP-30 custom-emoji tags ride their own validated arg server-side; the |
| 6941 | // relay echoes them back on the stored event too, so mirror that here so the |
| 6942 | // emoji renderer keeps resolving `:shortcode:` after the round-trip. |
| 6943 | const emojiTags = args.emojiTags ?? []; |
| 6944 | // Both kinds end up on the stored event's tag set, just like the real relay. |
| 6945 | const extraTags = [...mediaTags, ...emojiTags]; |
| 6946 | const identity = getIdentity(config); |
| 6947 | if (!identity) { |
| 6948 | const createdAt = Math.floor(Date.now() / 1000); |
| 6949 | const mockPubkey = getMockMemberPubkey(config); |
| 6950 | |
| 6951 | if (!args.parentEventId) { |
| 6952 | const event = createMockEvent(kind, args.content, [ |
| 6953 | ...buildTopLevelMessageTags( |
| 6954 | args.channelId, |
| 6955 | args.mentionPubkeys, |
| 6956 | mockPubkey, |
| 6957 | ), |
| 6958 | ...extraTags, |
| 6959 | ]); |
| 6960 | recordMockMessage(args.channelId, event); |
| 6961 | emitMockLiveEvent(args.channelId, event); |
| 6962 | |
| 6963 | return { |
| 6964 | event_id: event.id, |
| 6965 | parent_event_id: null, |
| 6966 | root_event_id: null, |
| 6967 | depth: 0, |
| 6968 | created_at: createdAt, |
| 6969 | }; |
| 6970 | } |
| 6971 | |
| 6972 | const history = getMockMessageStore(args.channelId); |
| 6973 | const parentEvent = history.find( |
no test coverage detected