Skip to content
This repository was archived by the owner on Feb 11, 2026. It is now read-only.

Commit 60a4645

Browse files
committed
feat(create room): set default room avatar
When creating a room, elecord will provide a default avatar. There are two defaults depending on the room type.
1 parent 28dc149 commit 60a4645

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

res/img/rooms/hash.png

619 Bytes
Loading

res/img/rooms/speaker.png

1.64 KB
Loading

src/createRoom.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Copyright 2024 New Vector Ltd.
33
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
44
Copyright 2015, 2016 OpenMarket Ltd
5+
Copyright 2025 hazzuk.
56
67
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
78
Please see LICENSE files in the repository root for full details.
@@ -75,6 +76,10 @@ const DEFAULT_EVENT_POWER_LEVELS = {
7576
[EventType.RoomEncryption]: 100,
7677
};
7778

79+
// elecord, default room avatars
80+
const speakerImg = require("../res/img/rooms/speaker.png") as string;
81+
const hashImg = require("../res/img/rooms/hash.png") as string;
82+
7883
/**
7984
* Create a new room, and switch to it.
8085
*
@@ -101,6 +106,33 @@ export default async function createRoom(client: MatrixClient, opts: IOpts): Pro
101106
if (opts.guestAccess === undefined) opts.guestAccess = true;
102107
if (opts.encryption === undefined) opts.encryption = false;
103108

109+
// elecord, set default room avatar
110+
if (!opts.avatar) {
111+
let filePromise: Promise<File>;
112+
113+
// fetch image and convert to file
114+
async function fetchImageAsFile(url: string, fileName: string): Promise<File> {
115+
const response = await fetch(url);
116+
if (!response.ok) {
117+
throw new Error(`Failed to fetch image at ${url}: ${response.statusText}`);
118+
}
119+
const blob = await response.blob();
120+
return new File([blob], fileName, { type: blob.type });
121+
}
122+
123+
// determine default avatar based on room type
124+
switch (opts.roomType) {
125+
case RoomType.ElementVideo:
126+
case RoomType.UnstableCall:
127+
filePromise = fetchImageAsFile(speakerImg, "speaker.png");
128+
break;
129+
default:
130+
filePromise = fetchImageAsFile(hashImg, "hash.png");
131+
}
132+
// set room avatar option
133+
opts.avatar = await filePromise;
134+
}
135+
104136
if (client.isGuest()) {
105137
dis.dispatch({ action: "require_registration" });
106138
return null;

0 commit comments

Comments
 (0)