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';
|
const muc_jid = 'room@muc.example.com';
|
||||||
await test_utils.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
|
await test_utils.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
|
||||||
const view = _converse.api.chatviews.get(muc_jid);
|
const view = _converse.api.chatviews.get(muc_jid);
|
||||||
spyOn(view.model, 'findDuplicateFromStanzaID').and.callThrough();
|
spyOn(view.model, 'getStanzaIdQueryAttrs').and.callThrough();
|
||||||
let stanza = u.toStanza(`
|
let stanza = u.toStanza(`
|
||||||
<message xmlns="jabber:client"
|
<message xmlns="jabber:client"
|
||||||
from="room@muc.example.com/some1"
|
from="room@muc.example.com/some1"
|
||||||
@ -226,8 +226,8 @@
|
|||||||
</message>`);
|
</message>`);
|
||||||
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
||||||
await u.waitUntil(() => view.model.messages.length === 1);
|
await u.waitUntil(() => view.model.messages.length === 1);
|
||||||
await u.waitUntil(() => view.model.findDuplicateFromStanzaID.calls.count() === 1);
|
await u.waitUntil(() => view.model.getStanzaIdQueryAttrs.calls.count() === 1);
|
||||||
let result = await view.model.findDuplicateFromStanzaID.calls.all()[0].returnValue;
|
let result = await view.model.getStanzaIdQueryAttrs.calls.all()[0].returnValue;
|
||||||
expect(result instanceof Array).toBe(true);
|
expect(result instanceof Array).toBe(true);
|
||||||
expect(result[0] instanceof Object).toBe(true);
|
expect(result[0] instanceof Object).toBe(true);
|
||||||
expect(result[0]['stanza_id room@muc.example.com']).toBe("5f3dbc5e-e1d3-4077-a492-693f3769c7ad");
|
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>}
|
* @returns {Promise<_converse.Message>}
|
||||||
*/
|
*/
|
||||||
getDuplicateMessage (attrs) {
|
getDuplicateMessage (attrs) {
|
||||||
const predicates = [
|
const queries = [
|
||||||
...this.findDuplicateFromStanzaID(attrs),
|
...this.getStanzaIdQueryAttrs(attrs),
|
||||||
this.findDuplicateFromOriginID(attrs),
|
this.getOriginIdQueryAttrs(attrs),
|
||||||
this.findDuplicateFromMessage(attrs)
|
this.getMessageBodyQueryAttrs(attrs)
|
||||||
].filter(s => s);
|
].filter(s => s);
|
||||||
const msgs = this.messages.models;
|
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};
|
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 '));
|
const keys = Object.keys(attrs).filter(k => k.startsWith('stanza_id '));
|
||||||
return keys.map(key => {
|
return keys.map(key => {
|
||||||
const by_jid = key.replace(/^stanza_id /, '');
|
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) {
|
if (attrs.message && attrs.msgid) {
|
||||||
return {
|
return {
|
||||||
'message': attrs.message,
|
'message': attrs.message,
|
||||||
|
Loading…
Reference in New Issue
Block a user