MCPcopy
hub / github.com/element-hq/element-web / enableStateEventEncryption

Function enableStateEventEncryption

apps/web/src/createRoom.ts:442–469  ·  view source on GitHub ↗
(client: MatrixClient, room: Room, opts: IOpts)

Source from the content-addressed store, hash-verified

440}
441
442async function enableStateEventEncryption(client: MatrixClient, room: Room, opts: IOpts): Promise<void> {
443 // Don't send our state events until encryption is enabled. If this times
444 // out after 30 seconds, we throw since we don't want to send the events
445 // unencrypted.
446 await waitForRoomEncryption(room, 30000);
447
448 // Set room name
449 if (opts.name) {
450 await client.setRoomName(room.roomId, opts.name);
451 }
452
453 // Set room topic
454 if (opts.topic) {
455 const htmlTopic = htmlSerializeFromMdIfNeeded(opts.topic, { forceHTML: false });
456 await client.setRoomTopic(room.roomId, opts.topic, htmlTopic);
457 }
458
459 // Set room avatar
460 if (opts.avatar) {
461 let url: string;
462 if (opts.avatar instanceof File) {
463 ({ content_uri: url } = await client.uploadContent(opts.avatar));
464 } else {
465 url = opts.avatar;
466 }
467 await client.sendStateEvent(room.roomId, EventType.RoomAvatar, { url }, "");
468 }
469}
470
471/**
472 * Wait until the supplied room has an `m.room.encryption` event, or time out

Callers 1

createRoomFunction · 0.85

Calls 4

waitForRoomEncryptionFunction · 0.85
uploadContentMethod · 0.80
sendStateEventMethod · 0.45

Tested by

no test coverage detected