MCPcopy Create free account
hub / github.com/block/buzz / handleSendChannelMessage

Function handleSendChannelMessage

desktop/src/testing/e2eBridge.ts:6916–7063  ·  view source on GitHub ↗
(
  args: {
    channelId: string;
    content: string;
    parentEventId?: string | null;
    kind?: number | null;
    mentionPubkeys?: string[];
    mediaTags?: string[][] | null;
    emojiTags?: string[][] | null;
  },
  config: E2eConfig | undefined,
)

Source from the content-addressed store, hash-verified

6914}
6915
6916async 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(

Callers 1

handleMockCommandFunction · 0.85

Calls 11

getMockMemberPubkeyFunction · 0.85
createMockEventFunction · 0.85
buildTopLevelMessageTagsFunction · 0.85
recordMockMessageFunction · 0.85
emitMockLiveEventFunction · 0.85
getMockMessageStoreFunction · 0.85
buildReplyMessageTagsFunction · 0.85
getRelayIdentityFunction · 0.85
submitSignedEventFunction · 0.85
getIdentityFunction · 0.70

Tested by

no test coverage detected