Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
6eb05be4
Commit
6eb05be4
authored
Feb 13, 2019
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
XEP-0359: Better usage of `stanza-id` to check for dupes
parent
5b25d5da
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
93 additions
and
45 deletions
+93
-45
dist/converse.js
dist/converse.js
+19
-25
spec/messages.js
spec/messages.js
+56
-1
src/headless/converse-chatboxes.js
src/headless/converse-chatboxes.js
+3
-0
src/headless/converse-mam.js
src/headless/converse-mam.js
+0
-5
src/headless/converse-muc.js
src/headless/converse-muc.js
+15
-14
No files found.
dist/converse.js
View file @
6eb05be4
...
...
@@ -61982,6 +61982,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
const archive = sizzle(`result[xmlns="${Strophe.NS.MAM}"]`, original_stanza).pop(),
spoiler = sizzle(`spoiler[xmlns="${Strophe.NS.SPOILER}"]`, original_stanza).pop(),
delay = sizzle(`delay[xmlns="${Strophe.NS.DELAY}"]`, original_stanza).pop(),
stanza_id = sizzle(`stanza-id[xmlns="${Strophe.NS.SID}"]`, stanza).pop(),
chat_state = stanza.getElementsByTagName(_converse.COMPOSING).length && _converse.COMPOSING || stanza.getElementsByTagName(_converse.PAUSED).length && _converse.PAUSED || stanza.getElementsByTagName(_converse.INACTIVE).length && _converse.INACTIVE || stanza.getElementsByTagName(_converse.ACTIVE).length && _converse.ACTIVE || stanza.getElementsByTagName(_converse.GONE).length && _converse.GONE;
const attrs = {
...
...
@@ -61992,6 +61993,8 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
'message': _converse.chatboxes.getMessageBody(stanza) || undefined,
'msgid': stanza.getAttribute('id'),
'references': this.getReferencesFromStanza(stanza),
'stanza_id': stanza_id ? stanza_id.getAttribute('id') : undefined,
'stanza_id_by_jid': stanza_id ? stanza_id.getAttribute('by') : undefined,
'subject': _.propertyOf(stanza.querySelector('subject'))('textContent'),
'thread': _.propertyOf(stanza.querySelector('thread'))('textContent'),
'time': delay ? delay.getAttribute('stamp') : moment().format(),
...
...
@@ -65219,13 +65222,6 @@ function getMessageArchiveID(stanza) {
if (!_.isUndefined(result)) {
return result.getAttribute('id');
} // See: https://xmpp.org/extensions/xep-0313.html#archives_id
const stanza_id = sizzle__WEBPACK_IMPORTED_MODULE_3___default()(`stanza-id[xmlns="${Strophe.NS.SID}"]`, stanza).pop();
if (!_.isUndefined(stanza_id)) {
return stanza_id.getAttribute('id');
}
}
...
...
@@ -66942,27 +66938,25 @@ _converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins.add('converse-muc
return data;
},
isDuplicate(message, original_stanza) {
// XXX: original_stanza is not used here, but in converse-mam
const msgid = message.getAttribute('id'),
jid = message.getAttribute('from');
async isDuplicate(message, original_stanza) {
const stanza_id = sizzle(`stanza-id[xmlns="${Strophe.NS.SID}"]`, message).pop();
if (msgid) {
const msg = this.messages.findWhere({
'msgid': msgid,
'from': jid
});
if (msg && msg.get('sender') === 'me' && !msg.get('received')) {
msg.save({
'received': moment().format()
});
if (!stanza_id) {
return;
}
return msg
;
}
const by_jid = stanza_id.getAttribute('by')
;
const result = await _converse.api.disco.supports(Strophe.NS.SID, by_jid);
if (!result.length) {
return false;
}
const msg = this.messages.findWhere({
'stanza_id': stanza_id.getAttribute('id'),
'stanza_id_by_jid': by_jid
});
return !_.isNil(msg);
},
fetchFeaturesIfConfigurationChanged(stanza) {
...
...
@@ -67067,7 +67061,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins.add('converse-muc
stanza = forwarded.querySelector('message');
}
if (this.isDuplicate(stanza, original_stanza)) {
if (
await
this.isDuplicate(stanza, original_stanza)) {
return;
}
spec/messages.js
View file @
6eb05be4
...
...
@@ -2172,7 +2172,6 @@
done
();
}));
it
(
"
can not be expected to have a unique id attribute
"
,
mock
.
initConverse
(
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
...
...
@@ -2204,6 +2203,62 @@
done
();
}));
it
(
"
is ignored if it has the same stanza-id of an already received on
"
,
mock
.
initConverse
(
null
,
[
'
rosterGroupsFetched
'
],
{},
async
function
(
done
,
_converse
)
{
const
features
=
[
'
http://jabber.org/protocol/muc
'
,
'
jabber:iq:register
'
,
'
muc_passwordprotected
'
,
'
muc_hidden
'
,
'
muc_temporary
'
,
'
muc_membersonly
'
,
'
muc_unmoderated
'
,
'
muc_nonanonymous
'
,
Strophe
.
NS
.
SID
,
];
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
'
room
'
,
'
muc.example.com
'
,
'
dummy
'
,
features
);
const
view
=
_converse
.
chatboxviews
.
get
(
'
room@muc.example.com
'
);
spyOn
(
view
.
model
,
'
isDuplicate
'
).
and
.
callThrough
();
let
stanza
=
u
.
toStanza
(
`
<message xmlns="jabber:client"
from="room@muc.example.com/some1"
to="
${
_converse
.
connection
.
jid
}
"
type="groupchat">
<body>Typical body text</body>
<stanza-id xmlns="urn:xmpp:sid:0"
id="5f3dbc5e-e1d3-4077-a492-693f3769c7ad"
by="room@muc.example.com"/>
<origin-id xmlns="urn:xmpp:sid:0" id="de305d54-75b4-431b-adb2-eb6b9e546013"/>
</message>`
);
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
await
test_utils
.
waitUntil
(()
=>
_converse
.
api
.
chats
.
get
().
length
);
await
test_utils
.
waitUntil
(()
=>
view
.
model
.
messages
.
length
===
1
);
await
test_utils
.
waitUntil
(()
=>
view
.
model
.
isDuplicate
.
calls
.
count
()
===
1
);
let
result
=
await
view
.
model
.
isDuplicate
.
calls
.
all
()[
0
].
returnValue
;
expect
(
result
).
toBe
(
false
);
stanza
=
u
.
toStanza
(
`
<message xmlns="jabber:client"
from="room@muc.example.com/some1"
to="
${
_converse
.
connection
.
jid
}
"
type="groupchat">
<body>Typical body text</body>
<stanza-id xmlns="urn:xmpp:sid:0"
id="5f3dbc5e-e1d3-4077-a492-693f3769c7ad"
by="room@muc.example.com"/>
<origin-id xmlns="urn:xmpp:sid:0" id="de305d54-75b4-431b-adb2-eb6b9e546013"/>
</message>`
);
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
await
test_utils
.
waitUntil
(()
=>
view
.
model
.
isDuplicate
.
calls
.
count
()
===
2
);
result
=
await
view
.
model
.
isDuplicate
.
calls
.
all
()[
1
].
returnValue
;
expect
(
result
).
toBe
(
true
);
expect
(
view
.
model
.
messages
.
length
).
toBe
(
1
);
done
();
}));
it
(
"
keeps track whether you are the sender or not
"
,
mock
.
initConverse
(
null
,
[
'
rosterGroupsFetched
'
],
{},
...
...
src/headless/converse-chatboxes.js
View file @
6eb05be4
...
...
@@ -596,6 +596,7 @@ converse.plugins.add('converse-chatboxes', {
const
archive
=
sizzle
(
`result[xmlns="
${
Strophe
.
NS
.
MAM
}
"]`
,
original_stanza
).
pop
(),
spoiler
=
sizzle
(
`spoiler[xmlns="
${
Strophe
.
NS
.
SPOILER
}
"]`
,
original_stanza
).
pop
(),
delay
=
sizzle
(
`delay[xmlns="
${
Strophe
.
NS
.
DELAY
}
"]`
,
original_stanza
).
pop
(),
stanza_id
=
sizzle
(
`stanza-id[xmlns="
${
Strophe
.
NS
.
SID
}
"]`
,
stanza
).
pop
(),
chat_state
=
stanza
.
getElementsByTagName
(
_converse
.
COMPOSING
).
length
&&
_converse
.
COMPOSING
||
stanza
.
getElementsByTagName
(
_converse
.
PAUSED
).
length
&&
_converse
.
PAUSED
||
stanza
.
getElementsByTagName
(
_converse
.
INACTIVE
).
length
&&
_converse
.
INACTIVE
||
...
...
@@ -610,6 +611,8 @@ converse.plugins.add('converse-chatboxes', {
'
message
'
:
_converse
.
chatboxes
.
getMessageBody
(
stanza
)
||
undefined
,
'
msgid
'
:
stanza
.
getAttribute
(
'
id
'
),
'
references
'
:
this
.
getReferencesFromStanza
(
stanza
),
'
stanza_id
'
:
stanza_id
?
stanza_id
.
getAttribute
(
'
id
'
)
:
undefined
,
'
stanza_id_by_jid
'
:
stanza_id
?
stanza_id
.
getAttribute
(
'
by
'
)
:
undefined
,
'
subject
'
:
_
.
propertyOf
(
stanza
.
querySelector
(
'
subject
'
))(
'
textContent
'
),
'
thread
'
:
_
.
propertyOf
(
stanza
.
querySelector
(
'
thread
'
))(
'
textContent
'
),
'
time
'
:
delay
?
delay
.
getAttribute
(
'
stamp
'
)
:
moment
().
format
(),
...
...
src/headless/converse-mam.js
View file @
6eb05be4
...
...
@@ -32,11 +32,6 @@ function getMessageArchiveID (stanza) {
if
(
!
_
.
isUndefined
(
result
))
{
return
result
.
getAttribute
(
'
id
'
);
}
// See: https://xmpp.org/extensions/xep-0313.html#archives_id
const
stanza_id
=
sizzle
(
`stanza-id[xmlns="
${
Strophe
.
NS
.
SID
}
"]`
,
stanza
).
pop
();
if
(
!
_
.
isUndefined
(
stanza_id
))
{
return
stanza_id
.
getAttribute
(
'
id
'
);
}
}
function
queryForArchivedMessages
(
_converse
,
options
,
callback
,
errback
)
{
...
...
src/headless/converse-muc.js
View file @
6eb05be4
...
...
@@ -948,20 +948,21 @@ converse.plugins.add('converse-muc', {
return
data
;
},
isDuplicate
(
message
,
original_stanza
)
{
// XXX: original_stanza is not used here, but in converse-mam
const
msgid
=
message
.
getAttribute
(
'
id
'
),
jid
=
message
.
getAttribute
(
'
from
'
);
if
(
msgid
)
{
const
msg
=
this
.
messages
.
findWhere
({
'
msgid
'
:
msgid
,
'
from
'
:
jid
});
if
(
msg
&&
msg
.
get
(
'
sender
'
)
===
'
me
'
&&
!
msg
.
get
(
'
received
'
))
{
msg
.
save
({
'
received
'
:
moment
().
format
()});
}
return
msg
;
async
isDuplicate
(
message
,
original_stanza
)
{
const
stanza_id
=
sizzle
(
`stanza-id[xmlns="
${
Strophe
.
NS
.
SID
}
"]`
,
message
).
pop
();
if
(
!
stanza_id
)
{
return
false
;
}
const
by_jid
=
stanza_id
.
getAttribute
(
'
by
'
);
const
result
=
await
_converse
.
api
.
disco
.
supports
(
Strophe
.
NS
.
SID
,
by_jid
);
if
(
!
result
.
length
)
{
return
false
;
}
const
msg
=
this
.
messages
.
findWhere
({
'
stanza_id
'
:
stanza_id
.
getAttribute
(
'
id
'
),
'
stanza_id_by_jid
'
:
by_jid
});
return
!
_
.
isNil
(
msg
);
},
fetchFeaturesIfConfigurationChanged
(
stanza
)
{
...
...
@@ -1055,7 +1056,7 @@ converse.plugins.add('converse-muc', {
if
(
forwarded
)
{
stanza
=
forwarded
.
querySelector
(
'
message
'
);
}
if
(
this
.
isDuplicate
(
stanza
,
original_stanza
))
{
if
(
await
this
.
isDuplicate
(
stanza
,
original_stanza
))
{
return
;
}
const
attrs
=
await
this
.
getMessageAttributesFromStanza
(
stanza
,
original_stanza
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment