-
-
Notifications
You must be signed in to change notification settings - Fork 764
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement support for XEP-0421 occupant ids
This let's us populate the `from_real_jid` attribute for messages in cases where the user's nickname has changed. Updates #2241
- Loading branch information
Showing
11 changed files
with
217 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/*global mock, converse */ | ||
|
||
const { u } = converse.env; | ||
|
||
describe("A MUC occupant", function () { | ||
|
||
it("does not stores the XEP-0421 occupant id if the feature isn't advertised", | ||
mock.initConverse([], {}, async function (_converse) { | ||
// TODO | ||
})); | ||
|
||
it("stores the XEP-0421 occupant id received from a presence stanza", | ||
mock.initConverse([], {}, async function (_converse) { | ||
|
||
const muc_jid = 'lounge@montague.lit'; | ||
const nick = 'romeo'; | ||
const model = await mock.openAndEnterChatRoom(_converse, muc_jid, nick); | ||
|
||
for (let i=0; i<mock.chatroom_names.length; i++) { | ||
// See example 21 https://xmpp.org/extensions/xep-0045.html#enter-pres | ||
const id = u.getUniqueId(); | ||
const name = mock.chatroom_names[i]; | ||
const presence = u.toStanza(` | ||
<presence | ||
from="${muc_jid}/${name}" | ||
id="${u.getUniqueId()}" | ||
to="${_converse.bare_jid}"> | ||
<x xmlns="http://jabber.org/protocol/muc#user" /> | ||
<occupant-id xmlns="urn:xmpp:occupant-id:0" id="${id}" /> | ||
</presence>`); | ||
_converse.connection._dataRecv(mock.createRequest(presence)); | ||
expect(model.getOccupantByNickname(name).get('occupant_id')).toBe(id); | ||
} | ||
expect(model.occupants.length).toBe(mock.chatroom_names.length + 1); | ||
})); | ||
|
||
it("is updated with the XEP-0421 occupant id received from a message stanza", | ||
mock.initConverse([], {}, async function (_converse) { | ||
|
||
const muc_jid = 'lounge@montague.lit'; | ||
const nick = 'romeo'; | ||
const model = await mock.openAndEnterChatRoom(_converse, muc_jid, nick); | ||
|
||
const occupant_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit'; | ||
|
||
const presence = u.toStanza(` | ||
<presence | ||
from="${muc_jid}/thirdwitch" | ||
id="${u.getUniqueId()}" | ||
to="${_converse.bare_jid}"> | ||
<x xmlns="http://jabber.org/protocol/muc#user"> | ||
<item jid="${occupant_jid}" /> | ||
</x> | ||
<occupant-id xmlns="urn:xmpp:occupant-id:0" id="dd72603deec90a38ba552f7c68cbcc61bca202cd" /> | ||
</presence>`); | ||
_converse.connection._dataRecv(mock.createRequest(presence)); | ||
expect(model.getOccupantByNickname('thirdwitch').get('occupant_id')).toBe('dd72603deec90a38ba552f7c68cbcc61bca202cd'); | ||
|
||
const stanza = u.toStanza(` | ||
<message | ||
from='${muc_jid}/3rdwitch' | ||
id='hysf1v37' | ||
to='${_converse.bare_jid}' | ||
type='groupchat'> | ||
<body>Harpier cries: 'tis time, 'tis time.</body> | ||
<occupant-id xmlns="urn:xmpp:occupant-id:0" id="dd72603deec90a38ba552f7c68cbcc61bca202cd" /> | ||
</message>`); | ||
_converse.connection._dataRecv(mock.createRequest(stanza)); | ||
|
||
await u.waitUntil(() => model.messages.length); | ||
expect(model.messages.at(0).get('occupant_id')).toBe("dd72603deec90a38ba552f7c68cbcc61bca202cd"); | ||
expect(model.messages.at(0).get('from_real_jid')).toBe(occupant_jid); | ||
expect(model.getOccupantByID("dd72603deec90a38ba552f7c68cbcc61bca202cd").get('nick')).toBe('3rdwitch'); | ||
})); | ||
|
||
it("will be added to a MUC message based on the XEP-0421 occupant id", | ||
mock.initConverse([], {}, async function (_converse) { | ||
|
||
const muc_jid = 'lounge@montague.lit'; | ||
const nick = 'romeo'; | ||
const model = await mock.openAndEnterChatRoom(_converse, muc_jid, nick); | ||
const occupant_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit'; | ||
|
||
const stanza = u.toStanza(` | ||
<message | ||
from='${muc_jid}/3rdwitch' | ||
id='hysf1v37' | ||
to='${_converse.bare_jid}' | ||
type='groupchat'> | ||
<body>Harpier cries: 'tis time, 'tis time.</body> | ||
<occupant-id xmlns="urn:xmpp:occupant-id:0" id="dd72603deec90a38ba552f7c68cbcc61bca202cd" /> | ||
</message>`); | ||
_converse.connection._dataRecv(mock.createRequest(stanza)); | ||
|
||
await u.waitUntil(() => model.messages.length); | ||
let message = model.messages.at(0); | ||
expect(message.get('occupant_id')).toBe("dd72603deec90a38ba552f7c68cbcc61bca202cd"); | ||
expect(message.occupant).toBeUndefined(); | ||
expect(message.getDisplayName()).toBe('3rdwitch'); | ||
|
||
const presence = u.toStanza(` | ||
<presence | ||
from="${muc_jid}/thirdwitch" | ||
id="${u.getUniqueId()}" | ||
to="${_converse.bare_jid}"> | ||
<x xmlns="http://jabber.org/protocol/muc#user"> | ||
<item jid="${occupant_jid}" /> | ||
</x> | ||
<occupant-id xmlns="urn:xmpp:occupant-id:0" id="dd72603deec90a38ba552f7c68cbcc61bca202cd" /> | ||
</presence>`); | ||
_converse.connection._dataRecv(mock.createRequest(presence)); | ||
expect(model.getOccupantByNickname('thirdwitch').get('occupant_id')).toBe('dd72603deec90a38ba552f7c68cbcc61bca202cd'); | ||
|
||
message = model.messages.at(0); | ||
const occupant = model.getOccupantByID("dd72603deec90a38ba552f7c68cbcc61bca202cd"); | ||
expect(occupant.get('nick')).toBe('thirdwitch'); | ||
expect(message.occupant).toEqual(occupant); | ||
expect(message.getDisplayName()).toBe('thirdwitch'); | ||
})); | ||
}); |
Oops, something went wrong.