diff --git a/src/addons/mod/chat/pages/chat/chat.ts b/src/addons/mod/chat/pages/chat/chat.ts index dd0add80e..2c0d46706 100644 --- a/src/addons/mod/chat/pages/chat/chat.ts +++ b/src/addons/mod/chat/pages/chat/chat.ts @@ -166,7 +166,7 @@ export class AddonModChatChatPage implements OnInit, OnDestroy, CanLeave { const message = this.messages[index]; - if (message.beep && message.beep != String(this.currentUserId)) { + if (message.beep && message.beep !== this.currentUserId) { this.loadMessageBeepWho(message); } } @@ -212,11 +212,11 @@ export class AddonModChatChatPage implements OnInit, OnDestroy, CanLeave { * @param id User Id before parsing. * @returns User fullname. */ - protected async getUserFullname(id: string): Promise { - const idNumber = parseInt(id, 10); + protected async getUserFullname(id: string | number): Promise { + const idNumber = Number(id); if (isNaN(idNumber)) { - return id; + return String(id); } const user = this.users.find((user) => user.id == idNumber); @@ -235,10 +235,10 @@ export class AddonModChatChatPage implements OnInit, OnDestroy, CanLeave { return user.fullname; } - return id; + return String(id); } catch { // Ignore errors. - return id; + return String(id); } } diff --git a/src/addons/mod/chat/pages/session-messages/session-messages.ts b/src/addons/mod/chat/pages/session-messages/session-messages.ts index e3143eec7..682bb738e 100644 --- a/src/addons/mod/chat/pages/session-messages/session-messages.ts +++ b/src/addons/mod/chat/pages/session-messages/session-messages.ts @@ -112,7 +112,7 @@ export class AddonModChatSessionMessagesPage implements OnInit { const message = this.messages[index]; - if (message.beep && message.beep != String(this.currentUserId)) { + if (message.beep && message.beep !== this.currentUserId) { this.loadMessageBeepWho(message); } } @@ -135,11 +135,11 @@ export class AddonModChatSessionMessagesPage implements OnInit { * @param id User Id before parsing. * @returns User fullname. */ - protected async getUserFullname(id: string): Promise { - const idNumber = parseInt(id, 10); + protected async getUserFullname(id: string | number): Promise { + const idNumber = Number(id); if (isNaN(idNumber)) { - return id; + return String(id); } try { @@ -148,7 +148,7 @@ export class AddonModChatSessionMessagesPage implements OnInit { return user.fullname; } catch { // Error getting profile. - return id; + return String(id); } } diff --git a/src/addons/mod/chat/services/chat-helper.ts b/src/addons/mod/chat/services/chat-helper.ts index 49f466243..2380408df 100644 --- a/src/addons/mod/chat/services/chat-helper.ts +++ b/src/addons/mod/chat/services/chat-helper.ts @@ -54,6 +54,9 @@ export class AddonModChatHelperProvider { formattedMessage.showDate = this.showDate(message, prevMessage); formattedMessage.beep = (message.message.substring(0, 5) == 'beep ' && message.message.substring(5).trim()) || undefined; + if (formattedMessage.beep && !isNaN(Number(formattedMessage.beep))) { + formattedMessage.beep = Number(formattedMessage.beep); + } formattedMessage.special = !!formattedMessage.beep || ( message).issystem || ( message).system; @@ -133,7 +136,7 @@ export const AddonModChatHelper = makeSingleton(AddonModChatHelperProvider); */ type AddonModChatInfoForView = { showDate?: boolean; // If date should be displayed before the message. - beep?: string; // User id of the beeped user or 'all'. + beep?: string | number; // User id of the beeped user or 'all'. special?: boolean; // True if is an special message (system, beep or command). showUserData?: boolean; // If user data should be displayed. showTail?: boolean; // If tail should be displayed (decoration).