Use occupant_id to get own occupant O(1) if available

This commit is contained in:
JC Brand 2022-08-12 09:21:01 +02:00
parent 7028286855
commit 34927b5b77
3 changed files with 16 additions and 17 deletions

View File

@ -39,16 +39,6 @@ class ChatRoomOccupants extends Collection {
return super.create(attrs, options);
}
/**
* Get the {@link _converse.ChatRoomOccupant} instance which
* represents the current user.
* @method _converse.ChatRoomOccupants#getOwnOccupant
* @returns { _converse.ChatRoomOccupant }
*/
getOwnOccupant () {
return this.findWhere({ 'jid': _converse.bare_jid });
}
async fetchMembers () {
if (!['member', 'admin', 'owner'].includes(this.getOwnOccupant()?.get('affiliation'))) {
// https://xmpp.org/extensions/xep-0045.html#affil-priv
@ -101,10 +91,10 @@ class ChatRoomOccupants extends Collection {
* @property { String } [occupant_id] - The XEP-0421 unique occupant id
*/
/**
* Try to find an existing occupant based on the passed in
* data object.
* Try to find an existing occupant based on the provided
* @link { OccupantData } object.
*
* Fetching the user by occupant_id is the quickest, O(1),
* Fetching the user by `occupant_id` is the quickest, O(1),
* since it's a dictionary lookup.
*
* Fetching by jid or nick is O(n), since it requires traversing an array.
@ -123,6 +113,19 @@ class ChatRoomOccupants extends Collection {
return jid && this.findWhere({ jid }) ||
data.nick && this.findWhere({ 'nick': data.nick });
}
/**
* Get the {@link _converse.ChatRoomOccupant} instance which
* represents the current user.
* @method _converse.ChatRoomOccupants#getOwnOccupant
* @returns { _converse.ChatRoomOccupant }
*/
getOwnOccupant () {
return this.findOccupant({
'jid': _converse.bare_jid,
'occupant_id': this.chatroom.get('occupant_id')
});
}
}

View File

@ -7,8 +7,6 @@ const { Strophe } = converse.env;
function whenNotConnected (o) {
const connection_status = _converse.connfeedback.get('connection_status');
console.log("connection_status");
console.log(connection_status);
if ([Strophe.Status.RECONNECTING, Strophe.Status.CONNECTING].includes(connection_status)) {
return tpl_spinner();
}

View File

@ -87,7 +87,6 @@ describe("The OMEMO module", function() {
keyCode: 13 // Enter
});
iq_stanza = await u.waitUntil(() => mock.bundleFetched(_converse, contact_jid, '4e30f35051b7b8b42abe083742187228'), 1000);
console.log("Bundle fetched 4e30f35051b7b8b42abe083742187228");
stanza = $iq({
'from': contact_jid,
'id': iq_stanza.getAttribute('id'),
@ -108,7 +107,6 @@ describe("The OMEMO module", function() {
_converse.connection._dataRecv(mock.createRequest(stanza));
iq_stanza = await u.waitUntil(() => mock.bundleFetched(_converse, _converse.bare_jid, '482886413b977930064a5888b92134fe'), 1000);
console.log("Bundle fetched 482886413b977930064a5888b92134fe");
stanza = $iq({
'from': _converse.bare_jid,
'id': iq_stanza.getAttribute('id'),