(
args: {
channelId: string;
name?: string;
description?: string;
visibility?: "open" | "private";
ttlSeconds?: number | null;
},
config: E2eConfig | undefined,
)
| 5215 | } |
| 5216 | |
| 5217 | async function handleUpdateChannel( |
| 5218 | args: { |
| 5219 | channelId: string; |
| 5220 | name?: string; |
| 5221 | description?: string; |
| 5222 | visibility?: "open" | "private"; |
| 5223 | ttlSeconds?: number | null; |
| 5224 | }, |
| 5225 | config: E2eConfig | undefined, |
| 5226 | ) { |
| 5227 | const delayMs = config?.mock?.updateChannelDelayMs ?? 0; |
| 5228 | if (delayMs > 0) { |
| 5229 | await new Promise((resolve) => window.setTimeout(resolve, delayMs)); |
| 5230 | } |
| 5231 | |
| 5232 | const identity = getIdentity(config); |
| 5233 | if (!identity) { |
| 5234 | const channel = getMockChannel(args.channelId); |
| 5235 | if (args.name !== undefined) { |
| 5236 | channel.name = args.name; |
| 5237 | } |
| 5238 | if (args.description !== undefined) { |
| 5239 | channel.description = args.description; |
| 5240 | } |
| 5241 | if (args.visibility !== undefined) { |
| 5242 | channel.visibility = args.visibility; |
| 5243 | } |
| 5244 | if (args.ttlSeconds !== undefined) { |
| 5245 | channel.ttl_seconds = args.ttlSeconds; |
| 5246 | channel.ttl_deadline = |
| 5247 | args.ttlSeconds === null |
| 5248 | ? null |
| 5249 | : new Date(Date.now() + args.ttlSeconds * 1000).toISOString(); |
| 5250 | } |
| 5251 | touchMockChannel(channel); |
| 5252 | return toRawChannelDetail(channel, config); |
| 5253 | } |
| 5254 | |
| 5255 | const tags: string[][] = [["h", args.channelId]]; |
| 5256 | if (args.name !== undefined) { |
| 5257 | tags.push(["name", args.name]); |
| 5258 | } |
| 5259 | if (args.description !== undefined) { |
| 5260 | tags.push(["about", args.description]); |
| 5261 | } |
| 5262 | if (args.visibility !== undefined) { |
| 5263 | tags.push(["visibility", args.visibility]); |
| 5264 | } |
| 5265 | if (args.ttlSeconds !== undefined) { |
| 5266 | tags.push(["ttl", args.ttlSeconds === null ? "" : String(args.ttlSeconds)]); |
| 5267 | } |
| 5268 | await submitSignedEvent(config, { kind: 9002, content: "", tags }); |
| 5269 | |
| 5270 | // Re-fetch updated metadata |
| 5271 | const metaEvents = await relayQuery(config, [ |
| 5272 | { kinds: [39000], "#d": [args.channelId], limit: 1 }, |
| 5273 | ]); |
| 5274 | const ev = metaEvents[0]; |
no test coverage detected