Fix Converse v11 regression - occupant comparator function:
The way we overloaded the MUCOccupants method was no more working.
This commit is contained in:
parent
81632fa467
commit
dd4bca8c06
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user