Fix Converse v11 regression - occupant comparator function:

The way we overloaded the MUCOccupants method was no more working.
This commit is contained in:
John Livingston 2024-07-25 18:32:38 +02:00
parent 81632fa467
commit dd4bca8c06
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
3 changed files with 21 additions and 24 deletions

View File

@ -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()
}
}

View File

@ -1,21 +0,0 @@
// SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
//
// 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
}
}
}

View File

@ -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
}
}
}