Use occupant_id
to get own occupant O(1) if available
This commit is contained in:
parent
7028286855
commit
34927b5b77
@ -39,16 +39,6 @@ class ChatRoomOccupants extends Collection {
|
|||||||
return super.create(attrs, options);
|
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 () {
|
async fetchMembers () {
|
||||||
if (!['member', 'admin', 'owner'].includes(this.getOwnOccupant()?.get('affiliation'))) {
|
if (!['member', 'admin', 'owner'].includes(this.getOwnOccupant()?.get('affiliation'))) {
|
||||||
// https://xmpp.org/extensions/xep-0045.html#affil-priv
|
// 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
|
* @property { String } [occupant_id] - The XEP-0421 unique occupant id
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* Try to find an existing occupant based on the passed in
|
* Try to find an existing occupant based on the provided
|
||||||
* data object.
|
* @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.
|
* since it's a dictionary lookup.
|
||||||
*
|
*
|
||||||
* Fetching by jid or nick is O(n), since it requires traversing an array.
|
* 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 }) ||
|
return jid && this.findWhere({ jid }) ||
|
||||||
data.nick && this.findWhere({ 'nick': data.nick });
|
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')
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,8 +7,6 @@ const { Strophe } = converse.env;
|
|||||||
|
|
||||||
function whenNotConnected (o) {
|
function whenNotConnected (o) {
|
||||||
const connection_status = _converse.connfeedback.get('connection_status');
|
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)) {
|
if ([Strophe.Status.RECONNECTING, Strophe.Status.CONNECTING].includes(connection_status)) {
|
||||||
return tpl_spinner();
|
return tpl_spinner();
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,6 @@ describe("The OMEMO module", function() {
|
|||||||
keyCode: 13 // Enter
|
keyCode: 13 // Enter
|
||||||
});
|
});
|
||||||
iq_stanza = await u.waitUntil(() => mock.bundleFetched(_converse, contact_jid, '4e30f35051b7b8b42abe083742187228'), 1000);
|
iq_stanza = await u.waitUntil(() => mock.bundleFetched(_converse, contact_jid, '4e30f35051b7b8b42abe083742187228'), 1000);
|
||||||
console.log("Bundle fetched 4e30f35051b7b8b42abe083742187228");
|
|
||||||
stanza = $iq({
|
stanza = $iq({
|
||||||
'from': contact_jid,
|
'from': contact_jid,
|
||||||
'id': iq_stanza.getAttribute('id'),
|
'id': iq_stanza.getAttribute('id'),
|
||||||
@ -108,7 +107,6 @@ describe("The OMEMO module", function() {
|
|||||||
_converse.connection._dataRecv(mock.createRequest(stanza));
|
_converse.connection._dataRecv(mock.createRequest(stanza));
|
||||||
|
|
||||||
iq_stanza = await u.waitUntil(() => mock.bundleFetched(_converse, _converse.bare_jid, '482886413b977930064a5888b92134fe'), 1000);
|
iq_stanza = await u.waitUntil(() => mock.bundleFetched(_converse, _converse.bare_jid, '482886413b977930064a5888b92134fe'), 1000);
|
||||||
console.log("Bundle fetched 482886413b977930064a5888b92134fe");
|
|
||||||
stanza = $iq({
|
stanza = $iq({
|
||||||
'from': _converse.bare_jid,
|
'from': _converse.bare_jid,
|
||||||
'id': iq_stanza.getAttribute('id'),
|
'id': iq_stanza.getAttribute('id'),
|
||||||
|
Loading…
Reference in New Issue
Block a user