diff --git a/conversejs/lib/plugins/livechat-specific.ts b/conversejs/lib/plugins/livechat-specific.ts index ef62eaeb..cfec5b8e 100644 --- a/conversejs/lib/plugins/livechat-specific.ts +++ b/conversejs/lib/plugins/livechat-specific.ts @@ -7,7 +7,6 @@ import { customizeToolbar } from './livechat-specific/toolbar' import { initReconnectionStuff } from './livechat-specific/reconnection' import { chatRoomOverrides } from './livechat-specific/chatroom' import { chatRoomMessageOverrides } from './livechat-specific/chatroom-message' -import { chatRoomOccupantsOverrides } from './livechat-specific/chatroom-occupants' export const livechatSpecificsPlugin = { dependencies: ['converse-muc', 'converse-muc-views'], @@ -38,7 +37,6 @@ export const livechatSpecificsPlugin = { }, overrides: { ChatRoom: chatRoomOverrides(), - ChatRoomMessage: chatRoomMessageOverrides(), - ChatRoomOccupants: chatRoomOccupantsOverrides() + ChatRoomMessage: chatRoomMessageOverrides() } } diff --git a/conversejs/lib/plugins/livechat-specific/chatroom-occupants.ts b/conversejs/lib/plugins/livechat-specific/chatroom-occupants.ts deleted file mode 100644 index 51685231..00000000 --- a/conversejs/lib/plugins/livechat-specific/chatroom-occupants.ts +++ /dev/null @@ -1,21 +0,0 @@ -// SPDX-FileCopyrightText: 2024 John Livingston -// -// SPDX-License-Identifier: AGPL-3.0-only - -export function chatRoomOccupantsOverrides (): {[key: string]: Function} { - return { - comparator: function (this: any, occupant1: any, occupant2: any): Number { - // Overriding Occupants comparators, to display anonymous users at the end of the list. - const nick1: string = occupant1.getDisplayName() - const nick2: string = occupant2.getDisplayName() - const b1 = nick1.startsWith('Anonymous ') - const b2 = nick2.startsWith('Anonymous ') - if (b1 === b2) { - // Both startswith anonymous, or non of it: fallback to the standard comparator. - return this.__super__.comparator(occupant1, occupant2) - } - // Else: Anonymous always last. - return b1 ? 1 : -1 - } - } -} diff --git a/conversejs/lib/plugins/livechat-specific/chatroom.ts b/conversejs/lib/plugins/livechat-specific/chatroom.ts index b41871ab..297c0ed4 100644 --- a/conversejs/lib/plugins/livechat-specific/chatroom.ts +++ b/conversejs/lib/plugins/livechat-specific/chatroom.ts @@ -23,6 +23,26 @@ export function chatRoomOverrides (): {[key: string]: Function} { // See https://github.com/conversejs/converse.js/issues/3428 for more info. // FIXME: if #3428 is fixed, remove this override. return this.isEntered() && this.getOwnRole() !== 'visitor' + }, + initOccupants: function initOccupants (this: any) { + const r = this.__super__.initOccupants() + + const originalComparatorFunction: Function = this.occupants.comparator + this.occupants.comparator = function (this: any, occupant1: any, occupant2: any): Number { + // Overriding Occupants comparators, to display anonymous users at the end of the list. + const nick1: string = occupant1.getDisplayName() + const nick2: string = occupant2.getDisplayName() + const b1 = nick1.startsWith('Anonymous ') + const b2 = nick2.startsWith('Anonymous ') + if (b1 === b2) { + // Both startswith anonymous, or non of it: fallback to the standard comparator. + return originalComparatorFunction.call(this, occupant1, occupant2) + } + // Else: Anonymous always last. + return b1 ? 1 : -1 + } + + return r } } }