Rename methods to clarify their purpose
This commit is contained in:
parent
0653505a40
commit
7d91b17552
@ -213,7 +213,7 @@
|
||||
const muc_jid = 'room@muc.example.com';
|
||||
await test_utils.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
|
||||
const view = _converse.api.chatviews.get(muc_jid);
|
||||
spyOn(view.model, 'findDuplicateFromStanzaID').and.callThrough();
|
||||
spyOn(view.model, 'getStanzaIdQueryAttrs').and.callThrough();
|
||||
let stanza = u.toStanza(`
|
||||
<message xmlns="jabber:client"
|
||||
from="room@muc.example.com/some1"
|
||||
@ -226,8 +226,8 @@
|
||||
</message>`);
|
||||
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
||||
await u.waitUntil(() => view.model.messages.length === 1);
|
||||
await u.waitUntil(() => view.model.findDuplicateFromStanzaID.calls.count() === 1);
|
||||
let result = await view.model.findDuplicateFromStanzaID.calls.all()[0].returnValue;
|
||||
await u.waitUntil(() => view.model.getStanzaIdQueryAttrs.calls.count() === 1);
|
||||
let result = await view.model.getStanzaIdQueryAttrs.calls.all()[0].returnValue;
|
||||
expect(result instanceof Array).toBe(true);
|
||||
expect(result[0] instanceof Object).toBe(true);
|
||||
expect(result[0]['stanza_id room@muc.example.com']).toBe("5f3dbc5e-e1d3-4077-a492-693f3769c7ad");
|
||||
|
@ -671,20 +671,20 @@ converse.plugins.add('converse-chat', {
|
||||
* @returns {Promise<_converse.Message>}
|
||||
*/
|
||||
getDuplicateMessage (attrs) {
|
||||
const predicates = [
|
||||
...this.findDuplicateFromStanzaID(attrs),
|
||||
this.findDuplicateFromOriginID(attrs),
|
||||
this.findDuplicateFromMessage(attrs)
|
||||
const queries = [
|
||||
...this.getStanzaIdQueryAttrs(attrs),
|
||||
this.getOriginIdQueryAttrs(attrs),
|
||||
this.getMessageBodyQueryAttrs(attrs)
|
||||
].filter(s => s);
|
||||
const msgs = this.messages.models;
|
||||
return find(msgs, m => predicates.reduce((out, p) => (out || isMatch(m.attributes, p)), false));
|
||||
return find(msgs, m => queries.reduce((out, q) => (out || isMatch(m.attributes, q)), false));
|
||||
},
|
||||
|
||||
findDuplicateFromOriginID (attrs) {
|
||||
getOriginIdQueryAttrs (attrs) {
|
||||
return attrs.origin_id && {'origin_id': attrs.origin_id, 'from': attrs.from};
|
||||
},
|
||||
|
||||
findDuplicateFromStanzaID (attrs) {
|
||||
getStanzaIdQueryAttrs (attrs) {
|
||||
const keys = Object.keys(attrs).filter(k => k.startsWith('stanza_id '));
|
||||
return keys.map(key => {
|
||||
const by_jid = key.replace(/^stanza_id /, '');
|
||||
@ -694,7 +694,7 @@ converse.plugins.add('converse-chat', {
|
||||
});
|
||||
},
|
||||
|
||||
findDuplicateFromMessage (attrs) {
|
||||
getMessageBodyQueryAttrs (attrs) {
|
||||
if (attrs.message && attrs.msgid) {
|
||||
return {
|
||||
'message': attrs.message,
|
||||
|
Loading…
Reference in New Issue
Block a user