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
31e884f7
Commit
31e884f7
authored
Jan 09, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add code to check for duplicates
parent
64149810
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
5 deletions
+61
-5
spec/mam.js
spec/mam.js
+33
-0
src/converse-mam.js
src/converse-mam.js
+26
-3
src/converse-muc.js
src/converse-muc.js
+2
-2
No files found.
spec/mam.js
View file @
31e884f7
...
@@ -13,6 +13,39 @@
...
@@ -13,6 +13,39 @@
describe
(
"
Message Archive Management
"
,
function
()
{
describe
(
"
Message Archive Management
"
,
function
()
{
// Implement the protocol defined in https://xmpp.org/extensions/xep-0313.html#config
// Implement the protocol defined in https://xmpp.org/extensions/xep-0313.html#config
describe
(
"
Archived Messages
"
,
function
()
{
it
(
"
aren't shown as duplicates
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
discoInitialized
'
],
{},
function
(
done
,
_converse
)
{
test_utils
.
openAndEnterChatRoom
(
_converse
,
'
trek-radio
'
,
'
conference.lightwitch.org
'
,
'
jcbrand
'
).
then
(
function
()
{
var
chatroomview
=
_converse
.
chatboxviews
.
get
(
'
trek-radio@conference.lightwitch.org
'
);
var
stanza
=
Strophe
.
xmlHtmlNode
(
`<message xmlns="jabber:client" to="jcbrand@lightwitch.org/converse.js-73057452" type="groupchat" from="trek-radio@conference.lightwitch.org/comndrdukath#0805 (STO)">
<body>negan</body>
<stanza-id xmlns="urn:xmpp:sid:0" id="45fbbf2a-1059-479d-9283-c8effaf05621" by="trek-radio@conference.lightwitch.org"/>
</message>`
).
firstElementChild
;
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
stanza
=
Strophe
.
xmlHtmlNode
(
`<message xmlns="jabber:client" to="jcbrand@lightwitch.org/converse.js-73057452">
<result xmlns="urn:xmpp:mam:2" queryid="82d9db27-6cf8-4787-8c2c-5a560263d823" id="45fbbf2a-1059-479d-9283-c8effaf05621">
<forwarded xmlns="urn:xmpp:forward:0"><delay xmlns="urn:xmpp:delay" stamp="2018-01-09T06:17:23Z"/>
<message from="trek-radio@conference.lightwitch.org/comndrdukath#0805 (STO)" type="groupchat">
<body>negan</body>
</message>
</forwarded>
</result>
</message>`
).
firstElementChild
;
chatroomview
.
onChatRoomMessage
(
stanza
);
expect
(
chatroomview
.
content
.
querySelectorAll
(
'
.chat-message
'
).
length
).
toBe
(
1
);
done
();
});
}))
});
describe
(
"
The archive.query API
"
,
function
()
{
describe
(
"
The archive.query API
"
,
function
()
{
it
(
"
can be used to query for all archived messages
"
,
it
(
"
can be used to query for all archived messages
"
,
...
...
src/converse-mam.js
View file @
31e884f7
...
@@ -25,6 +25,18 @@
...
@@ -25,6 +25,18 @@
const
MAM_ATTRIBUTES
=
[
'
with
'
,
'
start
'
,
'
end
'
];
const
MAM_ATTRIBUTES
=
[
'
with
'
,
'
start
'
,
'
end
'
];
function
getMessageArchiveID
(
stanza
)
{
const
result
=
sizzle
(
`result[xmlns="
${
Strophe
.
NS
.
MAM
}
"]`
,
stanza
).
pop
();
if
(
!
_
.
isUndefined
(
result
))
{
return
result
.
getAttribute
(
'
id
'
);
}
const
stanza_id
=
sizzle
(
`stanza-id[xmlns="
${
Strophe
.
NS
.
SID
}
"]`
,
stanza
).
pop
();
if
(
!
_
.
isUndefined
(
stanza_id
))
{
return
stanza_id
.
getAttribute
(
'
id
'
);
}
}
converse
.
plugins
.
add
(
'
converse-mam
'
,
{
converse
.
plugins
.
add
(
'
converse-mam
'
,
{
optional_dependencies
:
[
'
converse-chatview
'
,
'
converse-muc
'
],
optional_dependencies
:
[
'
converse-chatview
'
,
'
converse-muc
'
],
...
@@ -38,9 +50,9 @@
...
@@ -38,9 +50,9 @@
ChatBox
:
{
ChatBox
:
{
getMessageAttributes
(
message
,
delay
,
original_stanza
)
{
getMessageAttributes
(
message
,
delay
,
original_stanza
)
{
const
attrs
=
this
.
__super__
.
getMessageAttributes
.
apply
(
this
,
arguments
);
const
attrs
=
this
.
__super__
.
getMessageAttributes
.
apply
(
this
,
arguments
);
const
result
=
sizzle
(
`stanza-id[xmlns="
${
Strophe
.
NS
.
SID
}
"]`
,
original_stanza
).
pop
(
);
const
archive_id
=
getMessageArchiveID
(
original_stanza
);
if
(
!
_
.
isUndefined
(
result
)
)
{
if
(
archive_id
)
{
attrs
.
archive_id
=
result
.
getAttribute
(
'
id
'
)
;
attrs
.
archive_id
=
archive_id
;
}
}
return
attrs
;
return
attrs
;
}
}
...
@@ -191,6 +203,17 @@
...
@@ -191,6 +203,17 @@
this
.
model
.
on
(
'
change:connection_status
'
,
this
.
fetchArchivedMessagesIfNecessary
,
this
);
this
.
model
.
on
(
'
change:connection_status
'
,
this
.
fetchArchivedMessagesIfNecessary
,
this
);
},
},
isDuplicate
(
message
,
original_stanza
)
{
const
result
=
this
.
__super__
.
isDuplicate
.
apply
(
this
,
arguments
);
if
(
result
)
{
return
result
;
}
const
archive_id
=
getMessageArchiveID
(
original_stanza
);
if
(
archive_id
)
{
return
this
.
model
.
messages
.
filter
({
'
archive_id
'
:
archive_id
}).
length
>
0
;
}
},
renderChatArea
()
{
renderChatArea
()
{
const
result
=
this
.
__super__
.
renderChatArea
.
apply
(
this
,
arguments
);
const
result
=
this
.
__super__
.
renderChatArea
.
apply
(
this
,
arguments
);
if
(
!
this
.
disable_mam
)
{
if
(
!
this
.
disable_mam
)
{
...
...
src/converse-muc.js
View file @
31e884f7
...
@@ -2127,7 +2127,7 @@
...
@@ -2127,7 +2127,7 @@
return
false
;
return
false
;
},
},
isDuplicate
(
message
)
{
isDuplicate
(
message
,
original_stanza
)
{
const
msgid
=
message
.
getAttribute
(
'
id
'
),
const
msgid
=
message
.
getAttribute
(
'
id
'
),
jid
=
message
.
getAttribute
(
'
from
'
),
jid
=
message
.
getAttribute
(
'
from
'
),
resource
=
Strophe
.
getResourceFromJid
(
jid
),
resource
=
Strophe
.
getResourceFromJid
(
jid
),
...
@@ -2162,7 +2162,7 @@
...
@@ -2162,7 +2162,7 @@
sender
=
resource
&&
Strophe
.
unescapeNode
(
resource
)
||
''
,
sender
=
resource
&&
Strophe
.
unescapeNode
(
resource
)
||
''
,
subject
=
_
.
propertyOf
(
message
.
querySelector
(
'
subject
'
))(
'
textContent
'
);
subject
=
_
.
propertyOf
(
message
.
querySelector
(
'
subject
'
))(
'
textContent
'
);
if
(
this
.
isDuplicate
(
message
))
{
if
(
this
.
isDuplicate
(
message
,
original_stanza
))
{
return
true
;
return
true
;
}
}
if
(
subject
)
{
if
(
subject
)
{
...
...
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