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

Function handleCreateChannel

desktop/src/testing/e2eBridge.ts:4923–5011  ·  view source on GitHub ↗
(
  args: {
    name: string;
    channelType: "stream" | "forum";
    visibility: "open" | "private";
    description?: string;
    ttlSeconds?: number;
  },
  config: E2eConfig | undefined,
)

Source from the content-addressed store, hash-verified

4921}
4922
4923async function handleCreateChannel(
4924 args: {
4925 name: string;
4926 channelType: "stream" | "forum";
4927 visibility: "open" | "private";
4928 description?: string;
4929 ttlSeconds?: number;
4930 },
4931 config: E2eConfig | undefined,
4932) {
4933 const identity = getIdentity(config);
4934 const ttlDeadline =
4935 typeof args.ttlSeconds === "number"
4936 ? new Date(Date.now() + args.ttlSeconds * 1_000).toISOString()
4937 : null;
4938 if (!identity) {
4939 const owner = createCurrentMember(config, "owner");
4940 const channel = createMockChannel({
4941 id: crypto.randomUUID(),
4942 name: args.name,
4943 channel_type: args.channelType,
4944 visibility: args.visibility,
4945 description: args.description ?? "",
4946 topic: null,
4947 purpose: null,
4948 last_message_at: null,
4949 archived_at: null,
4950 created_by: owner.pubkey,
4951 topic_set_by: null,
4952 topic_set_at: null,
4953 purpose_set_by: null,
4954 purpose_set_at: null,
4955 ttl_seconds: args.ttlSeconds ?? null,
4956 ttl_deadline: ttlDeadline,
4957 topic_required: false,
4958 max_members: null,
4959 nip29_group_id: null,
4960 created_minutes_ago: 0,
4961 updated_minutes_ago: 0,
4962 members: [owner],
4963 });
4964 mockChannels.push(channel);
4965 return toRawChannel(channel, config);
4966 }
4967
4968 const channelId = crypto.randomUUID();
4969 const tags: string[][] = [
4970 ["h", channelId],
4971 ["name", args.name],
4972 ["channel_type", args.channelType],
4973 ["visibility", args.visibility],
4974 ];
4975 if (args.description) {
4976 tags.push(["about", args.description]);
4977 }
4978 if (typeof args.ttlSeconds === "number") {
4979 tags.push(["ttl", String(args.ttlSeconds)]);
4980 }

Callers 1

handleMockCommandFunction · 0.85

Calls 8

createCurrentMemberFunction · 0.85
createMockChannelFunction · 0.85
toRawChannelFunction · 0.85
submitSignedEventFunction · 0.85
relayQueryFunction · 0.85
pushMethod · 0.80
getIdentityFunction · 0.70
getTagFunction · 0.70

Tested by

no test coverage detected