22Copyright 2024 New Vector Ltd.
33Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
44Copyright 2015, 2016 OpenMarket Ltd
5+ Copyright 2025 hazzuk.
56
67SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
78Please 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