@@ -1783,12 +1783,11 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
17831783 allowDefault = true ,
17841784 useAuthentication : boolean = false ,
17851785 ) : string | null {
1786- const roomAvatarEvent = this . currentState . getStateEvents ( EventType . RoomAvatar , "" ) ;
1787- if ( ! roomAvatarEvent && ! allowDefault ) {
1786+ const mainUrl = this . getMxcAvatarUrl ( ) ;
1787+ if ( ! mainUrl && ! allowDefault ) {
17881788 return null ;
17891789 }
17901790
1791- const mainUrl = roomAvatarEvent ? roomAvatarEvent . getContent ( ) . url : null ;
17921791 if ( mainUrl ) {
17931792 return getHttpUriForMxc (
17941793 baseUrl ,
@@ -1810,7 +1809,8 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
18101809 * @returns the mxc avatar url or falsy
18111810 */
18121811 public getMxcAvatarUrl ( ) : string | null {
1813- return this . currentState . getStateEvents ( EventType . RoomAvatar , "" ) ?. getContent ( ) ?. url || null ;
1812+ const url = this . currentState . getStateEvents ( EventType . RoomAvatar , "" ) ?. getContent ( ) . url ;
1813+ return typeof url === "string" ? url : null ;
18141814 }
18151815
18161816 /**
@@ -1820,21 +1820,18 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
18201820 * @returns The room's canonical alias, or null if there is none
18211821 */
18221822 public getCanonicalAlias ( ) : string | null {
1823- const canonicalAlias = this . currentState . getStateEvents ( EventType . RoomCanonicalAlias , "" ) ;
1824- if ( canonicalAlias ) {
1825- return canonicalAlias . getContent ( ) . alias || null ;
1826- }
1827- return null ;
1823+ const canonicalAlias = this . currentState . getStateEvents ( EventType . RoomCanonicalAlias , "" ) ?. getContent ( ) . alias ;
1824+ return typeof canonicalAlias === "string" ? canonicalAlias : null ;
18281825 }
18291826
18301827 /**
18311828 * Get this room's alternative aliases
18321829 * @returns The room's alternative aliases, or an empty array
18331830 */
18341831 public getAltAliases ( ) : string [ ] {
1835- const canonicalAlias = this . currentState . getStateEvents ( EventType . RoomCanonicalAlias , "" ) ;
1836- if ( canonicalAlias ) {
1837- return canonicalAlias . getContent ( ) . alt_aliases || [ ] ;
1832+ const altAliases = this . currentState . getStateEvents ( EventType . RoomCanonicalAlias , "" ) ?. getContent ( ) . alt_aliases ;
1833+ if ( Array . isArray ( altAliases ) ) {
1834+ return altAliases . filter ( ( alias ) => typeof alias === "string" ) ;
18381835 }
18391836 return [ ] ;
18401837 }
@@ -3640,13 +3637,11 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
36403637 */
36413638 private calculateRoomName ( userId : string , ignoreRoomNameEvent = false ) : string {
36423639 if ( ! ignoreRoomNameEvent ) {
3643- // check for an alias, if any. for now, assume first alias is the
3644- // official one.
3645- const mRoomName = this . currentState . getStateEvents ( EventType . RoomName , "" ) ;
3646- if ( mRoomName ?. getContent ( ) . name ) {
3640+ const name = this . currentState . getStateEvents ( EventType . RoomName , "" ) ?. getContent ( ) . name ;
3641+ if ( typeof name === "string" ) {
36473642 return this . roomNameGenerator ( {
36483643 type : RoomNameType . Actual ,
3649- name : mRoomName . getContent ( ) . name ,
3644+ name,
36503645 } ) ;
36513646 }
36523647 }
0 commit comments