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
79bfb456
Commit
79bfb456
authored
Dec 06, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use async/await in MAM code and tests
parent
6e05f3b6
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
337 additions
and
367 deletions
+337
-367
spec/mam.js
spec/mam.js
+319
-330
src/converse-omemo.js
src/converse-omemo.js
+2
-2
src/headless/converse-chatboxes.js
src/headless/converse-chatboxes.js
+12
-21
src/headless/converse-mam.js
src/headless/converse-mam.js
+4
-14
No files found.
spec/mam.js
View file @
79bfb456
...
@@ -2,12 +2,12 @@
...
@@ -2,12 +2,12 @@
define
([
"
jasmine
"
,
"
mock
"
,
"
test-utils
"
],
factory
);
define
([
"
jasmine
"
,
"
mock
"
,
"
test-utils
"
],
factory
);
}
(
this
,
function
(
jasmine
,
mock
,
test_utils
)
{
}
(
this
,
function
(
jasmine
,
mock
,
test_utils
)
{
"
use strict
"
;
"
use strict
"
;
var
_
=
converse
.
env
.
_
;
const
_
=
converse
.
env
.
_
;
var
Backbone
=
converse
.
env
.
Backbone
;
const
Backbone
=
converse
.
env
.
Backbone
;
var
Strophe
=
converse
.
env
.
Strophe
;
const
Strophe
=
converse
.
env
.
Strophe
;
var
$iq
=
converse
.
env
.
$iq
;
const
$iq
=
converse
.
env
.
$iq
;
var
$msg
=
converse
.
env
.
$msg
;
const
$msg
=
converse
.
env
.
$msg
;
var
moment
=
converse
.
env
.
moment
;
const
moment
=
converse
.
env
.
moment
;
// See: https://xmpp.org/rfcs/rfc3921.html
// See: https://xmpp.org/rfcs/rfc3921.html
describe
(
"
Message Archive Management
"
,
function
()
{
describe
(
"
Message Archive Management
"
,
function
()
{
...
@@ -18,21 +18,18 @@
...
@@ -18,21 +18,18 @@
it
(
"
aren't shown as duplicates
"
,
it
(
"
aren't shown as duplicates
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
discoInitialized
'
],
{},
null
,
[
'
discoInitialized
'
],
{},
function
(
done
,
_converse
)
{
async
function
(
done
,
_converse
)
{
let
view
,
stanza
;
test_utils
.
openAndEnterChatRoom
(
_converse
,
'
trek-radio
'
,
'
conference.lightwitch.org
'
,
'
jcbrand
'
)
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
'
trek-radio
'
,
'
conference.lightwitch.org
'
,
'
jcbrand
'
);
.
then
(()
=>
{
const
view
=
_converse
.
chatboxviews
.
get
(
'
trek-radio@conference.lightwitch.org
'
);
view
=
_converse
.
chatboxviews
.
get
(
'
trek-radio@conference.lightwitch.org
'
);
let
stanza
=
Strophe
.
xmlHtmlNode
(
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)">
`<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>
<body>negan</body>
<stanza-id xmlns="urn:xmpp:sid:0" id="45fbbf2a-1059-479d-9283-c8effaf05621" by="trek-radio@conference.lightwitch.org"/>
<stanza-id xmlns="urn:xmpp:sid:0" id="45fbbf2a-1059-479d-9283-c8effaf05621" by="trek-radio@conference.lightwitch.org"/>
</message>`
).
firstElementChild
;
</message>`
).
firstElementChild
;
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
return
test_utils
.
waitUntil
(()
=>
view
.
content
.
querySelectorAll
(
'
.chat-msg
'
).
length
)
await
test_utils
.
waitUntil
(()
=>
view
.
content
.
querySelectorAll
(
'
.chat-msg
'
).
length
);
}).
then
(()
=>
{
// XXX: we wait here until the first message appears before
// XXX: we wait here until the first message appears before
// sending the duplicate. If we don't do that, then the
// sending the duplicate. If we don't do that, then the
// duplicate appears before the promise for `createMessage`
// duplicate appears before the promise for `createMessage`
...
@@ -44,7 +41,8 @@
...
@@ -44,7 +41,8 @@
stanza
=
Strophe
.
xmlHtmlNode
(
stanza
=
Strophe
.
xmlHtmlNode
(
`<message xmlns="jabber:client" to="jcbrand@lightwitch.org/converse.js-73057452">
`<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">
<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"/>
<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">
<message from="trek-radio@conference.lightwitch.org/comndrdukath#0805 (STO)" type="groupchat">
<body>negan</body>
<body>negan</body>
</message>
</message>
...
@@ -54,12 +52,12 @@
...
@@ -54,12 +52,12 @@
spyOn
(
view
.
model
,
'
isDuplicate
'
).
and
.
callThrough
();
spyOn
(
view
.
model
,
'
isDuplicate
'
).
and
.
callThrough
();
view
.
model
.
onMessage
(
stanza
);
view
.
model
.
onMessage
(
stanza
);
return
test_utils
.
waitUntil
(()
=>
view
.
model
.
isDuplicate
.
calls
.
count
());
await
test_utils
.
waitUntil
(()
=>
view
.
model
.
isDuplicate
.
calls
.
count
());
}).
then
(()
=>
{
expect
(
view
.
content
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
view
.
content
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
done
();
done
();
}).
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
FATAL
));
}));
}))
});
});
describe
(
"
The archive.query API
"
,
function
()
{
describe
(
"
The archive.query API
"
,
function
()
{
...
@@ -88,20 +86,20 @@
...
@@ -88,20 +86,20 @@
it
(
"
can be used to query for all messages to/from a particular JID
"
,
it
(
"
can be used to query for all messages to/from a particular JID
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[],
{},
null
,
[],
{},
function
(
done
,
_converse
)
{
async
function
(
done
,
_converse
)
{
_converse
.
api
.
disco
.
entities
.
get
(
_converse
.
domain
).
then
(
function
(
entity
)
{
const
entity
=
await
_converse
.
api
.
disco
.
entities
.
get
(
_converse
.
domain
);
if
(
!
entity
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
if
(
!
entity
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
_converse
.
disco_entities
.
get
(
_converse
.
domain
).
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
_converse
.
disco_entities
.
get
(
_converse
.
domain
).
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
}
}
var
sent_stanza
,
IQ_id
;
let
sent_stanza
,
IQ_id
;
var
sendIQ
=
_converse
.
connection
.
sendIQ
;
const
sendIQ
=
_converse
.
connection
.
sendIQ
;
spyOn
(
_converse
.
connection
,
'
sendIQ
'
).
and
.
callFake
(
function
(
iq
,
callback
,
errback
)
{
spyOn
(
_converse
.
connection
,
'
sendIQ
'
).
and
.
callFake
(
function
(
iq
,
callback
,
errback
)
{
sent_stanza
=
iq
;
sent_stanza
=
iq
;
IQ_id
=
sendIQ
.
bind
(
this
)(
iq
,
callback
,
errback
);
IQ_id
=
sendIQ
.
bind
(
this
)(
iq
,
callback
,
errback
);
});
});
_converse
.
api
.
archive
.
query
({
'
with
'
:
'
juliet@capulet.lit
'
});
_converse
.
api
.
archive
.
query
({
'
with
'
:
'
juliet@capulet.lit
'
});
var
queryid
=
sent_stanza
.
nodeTree
.
querySelector
(
'
query
'
).
getAttribute
(
'
queryid
'
);
const
queryid
=
sent_stanza
.
nodeTree
.
querySelector
(
'
query
'
).
getAttribute
(
'
queryid
'
);
expect
(
sent_stanza
.
toString
()).
toBe
(
expect
(
sent_stanza
.
toString
()).
toBe
(
`<iq id="
${
IQ_id
}
" type="set" xmlns="jabber:client">`
+
`<iq id="
${
IQ_id
}
" type="set" xmlns="jabber:client">`
+
`<query queryid="
${
queryid
}
" xmlns="urn:xmpp:mam:2">`
+
`<query queryid="
${
queryid
}
" xmlns="urn:xmpp:mam:2">`
+
...
@@ -116,29 +114,28 @@
...
@@ -116,29 +114,28 @@
`</query>`
+
`</query>`
+
`</iq>`
);
`</iq>`
);
done
();
done
();
});
}));
}));
it
(
"
can be used to query for archived messages from a chat room
"
,
it
(
"
can be used to query for archived messages from a chat room
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[],
{},
null
,
[],
{},
function
(
done
,
_converse
)
{
async
function
(
done
,
_converse
)
{
_converse
.
api
.
disco
.
entities
.
get
(
_converse
.
domain
).
then
(
function
(
entity
)
{
const
entity
=
await
_converse
.
api
.
disco
.
entities
.
get
(
_converse
.
domain
);
if
(
!
entity
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
if
(
!
entity
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
_converse
.
disco_entities
.
get
(
_converse
.
domain
).
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
_converse
.
disco_entities
.
get
(
_converse
.
domain
).
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
}
}
var
sent_stanza
,
IQ_id
;
let
sent_stanza
,
IQ_id
;
var
sendIQ
=
_converse
.
connection
.
sendIQ
;
const
sendIQ
=
_converse
.
connection
.
sendIQ
;
spyOn
(
_converse
.
connection
,
'
sendIQ
'
).
and
.
callFake
(
function
(
iq
,
callback
,
errback
)
{
spyOn
(
_converse
.
connection
,
'
sendIQ
'
).
and
.
callFake
(
function
(
iq
,
callback
,
errback
)
{
sent_stanza
=
iq
;
sent_stanza
=
iq
;
IQ_id
=
sendIQ
.
bind
(
this
)(
iq
,
callback
,
errback
);
IQ_id
=
sendIQ
.
bind
(
this
)(
iq
,
callback
,
errback
);
});
});
var
callback
=
jasmine
.
createSpy
(
'
callback
'
);
const
callback
=
jasmine
.
createSpy
(
'
callback
'
);
_converse
.
api
.
archive
.
query
({
'
with
'
:
'
coven@chat.shakespeare.lit
'
,
'
groupchat
'
:
true
},
callback
);
_converse
.
api
.
archive
.
query
({
'
with
'
:
'
coven@chat.shakespeare.lit
'
,
'
groupchat
'
:
true
},
callback
);
var
queryid
=
sent_stanza
.
nodeTree
.
querySelector
(
'
query
'
).
getAttribute
(
'
queryid
'
);
const
queryid
=
sent_stanza
.
nodeTree
.
querySelector
(
'
query
'
).
getAttribute
(
'
queryid
'
);
expect
(
sent_stanza
.
toString
()).
toBe
(
expect
(
sent_stanza
.
toString
()).
toBe
(
`<iq id="
${
IQ_id
}
" to="coven@chat.shakespeare.lit" type="set" xmlns="jabber:client">`
+
`<iq id="
${
IQ_id
}
" to="coven@chat.shakespeare.lit" type="set" xmlns="jabber:client">`
+
...
@@ -151,7 +148,6 @@
...
@@ -151,7 +148,6 @@
`</query>`
+
`</query>`
+
`</iq>`
);
`</iq>`
);
done
();
done
();
});
}));
}));
it
(
"
checks whether returned MAM messages from a MUC room are from the right JID
"
,
it
(
"
checks whether returned MAM messages from a MUC room are from the right JID
"
,
...
@@ -235,26 +231,26 @@
...
@@ -235,26 +231,26 @@
it
(
"
can be used to query for all messages in a certain timespan
"
,
it
(
"
can be used to query for all messages in a certain timespan
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[],
{},
null
,
[],
{},
function
(
done
,
_converse
)
{
async
function
(
done
,
_converse
)
{
var
sent_stanza
,
IQ_id
;
let
sent_stanza
,
IQ_id
;
var
sendIQ
=
_converse
.
connection
.
sendIQ
;
const
sendIQ
=
_converse
.
connection
.
sendIQ
;
spyOn
(
_converse
.
connection
,
'
sendIQ
'
).
and
.
callFake
(
function
(
iq
,
callback
,
errback
)
{
spyOn
(
_converse
.
connection
,
'
sendIQ
'
).
and
.
callFake
(
function
(
iq
,
callback
,
errback
)
{
sent_stanza
=
iq
;
sent_stanza
=
iq
;
IQ_id
=
sendIQ
.
bind
(
this
)(
iq
,
callback
,
errback
);
IQ_id
=
sendIQ
.
bind
(
this
)(
iq
,
callback
,
errback
);
});
});
_converse
.
api
.
disco
.
entities
.
get
().
then
(
function
(
entities
)
{
const
entities
=
await
_converse
.
api
.
disco
.
entities
.
get
();
if
(
!
entities
.
get
(
_converse
.
domain
).
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
if
(
!
entities
.
get
(
_converse
.
domain
).
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
_converse
.
disco_entities
.
get
(
_converse
.
domain
).
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
_converse
.
disco_entities
.
get
(
_converse
.
domain
).
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
}
}
var
start
=
'
2010-06-07T00:00:00Z
'
;
const
start
=
'
2010-06-07T00:00:00Z
'
;
var
end
=
'
2010-07-07T13:23:54Z
'
;
const
end
=
'
2010-07-07T13:23:54Z
'
;
_converse
.
api
.
archive
.
query
({
_converse
.
api
.
archive
.
query
({
'
start
'
:
start
,
'
start
'
:
start
,
'
end
'
:
end
'
end
'
:
end
});
});
var
queryid
=
sent_stanza
.
nodeTree
.
querySelector
(
'
query
'
).
getAttribute
(
'
queryid
'
);
const
queryid
=
sent_stanza
.
nodeTree
.
querySelector
(
'
query
'
).
getAttribute
(
'
queryid
'
);
expect
(
sent_stanza
.
toString
()).
toBe
(
expect
(
sent_stanza
.
toString
()).
toBe
(
`<iq id="
${
IQ_id
}
" type="set" xmlns="jabber:client">`
+
`<iq id="
${
IQ_id
}
" type="set" xmlns="jabber:client">`
+
`<query queryid="
${
queryid
}
" xmlns="urn:xmpp:mam:2">`
+
`<query queryid="
${
queryid
}
" xmlns="urn:xmpp:mam:2">`
+
...
@@ -273,7 +269,6 @@
...
@@ -273,7 +269,6 @@
`</iq>`
`</iq>`
);
);
done
();
done
();
});
}));
}));
it
(
"
throws a TypeError if an invalid date is provided
"
,
it
(
"
throws a TypeError if an invalid date is provided
"
,
...
@@ -294,14 +289,14 @@
...
@@ -294,14 +289,14 @@
it
(
"
can be used to query for all messages after a certain time
"
,
it
(
"
can be used to query for all messages after a certain time
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[],
{},
null
,
[],
{},
function
(
done
,
_converse
)
{
async
function
(
done
,
_converse
)
{
_converse
.
api
.
disco
.
entities
.
get
(
_converse
.
domain
).
then
(
function
(
entity
)
{
const
entity
=
await
_converse
.
api
.
disco
.
entities
.
get
(
_converse
.
domain
);
if
(
!
entity
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
if
(
!
entity
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
_converse
.
disco_entities
.
get
(
_converse
.
domain
).
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
_converse
.
disco_entities
.
get
(
_converse
.
domain
).
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
}
}
var
sent_stanza
,
IQ_id
;
let
sent_stanza
,
IQ_id
;
var
sendIQ
=
_converse
.
connection
.
sendIQ
;
const
sendIQ
=
_converse
.
connection
.
sendIQ
;
spyOn
(
_converse
.
connection
,
'
sendIQ
'
).
and
.
callFake
(
function
(
iq
,
callback
,
errback
)
{
spyOn
(
_converse
.
connection
,
'
sendIQ
'
).
and
.
callFake
(
function
(
iq
,
callback
,
errback
)
{
sent_stanza
=
iq
;
sent_stanza
=
iq
;
IQ_id
=
sendIQ
.
bind
(
this
)(
iq
,
callback
,
errback
);
IQ_id
=
sendIQ
.
bind
(
this
)(
iq
,
callback
,
errback
);
...
@@ -309,9 +304,9 @@
...
@@ -309,9 +304,9 @@
if
(
!
_converse
.
disco_entities
.
get
(
_converse
.
domain
).
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
if
(
!
_converse
.
disco_entities
.
get
(
_converse
.
domain
).
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
_converse
.
disco_entities
.
get
(
_converse
.
domain
).
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
_converse
.
disco_entities
.
get
(
_converse
.
domain
).
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
}
}
var
start
=
'
2010-06-07T00:00:00Z
'
;
const
start
=
'
2010-06-07T00:00:00Z
'
;
_converse
.
api
.
archive
.
query
({
'
start
'
:
start
});
_converse
.
api
.
archive
.
query
({
'
start
'
:
start
});
var
queryid
=
sent_stanza
.
nodeTree
.
querySelector
(
'
query
'
).
getAttribute
(
'
queryid
'
);
const
queryid
=
sent_stanza
.
nodeTree
.
querySelector
(
'
query
'
).
getAttribute
(
'
queryid
'
);
expect
(
sent_stanza
.
toString
()).
toBe
(
expect
(
sent_stanza
.
toString
()).
toBe
(
`<iq id="
${
IQ_id
}
" type="set" xmlns="jabber:client">`
+
`<iq id="
${
IQ_id
}
" type="set" xmlns="jabber:client">`
+
`<query queryid="
${
queryid
}
" xmlns="urn:xmpp:mam:2">`
+
`<query queryid="
${
queryid
}
" xmlns="urn:xmpp:mam:2">`
+
...
@@ -327,28 +322,26 @@
...
@@ -327,28 +322,26 @@
`</iq>`
`</iq>`
);
);
done
();
done
();
});
}));
}));
it
(
"
can be used to query for a limited set of results
"
,
it
(
"
can be used to query for a limited set of results
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[],
{},
null
,
[],
{},
function
(
done
,
_converse
)
{
async
function
(
done
,
_converse
)
{
_converse
.
api
.
disco
.
entities
.
get
(
_converse
.
domain
).
then
(
function
(
entity
)
{
const
entity
=
await
_converse
.
api
.
disco
.
entities
.
get
(
_converse
.
domain
);
if
(
!
entity
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
if
(
!
entity
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
_converse
.
disco_entities
.
get
(
_converse
.
domain
).
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
_converse
.
disco_entities
.
get
(
_converse
.
domain
).
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
}
}
let
sent_stanza
,
IQ_id
;
var
sent_stanza
,
IQ_id
;
const
sendIQ
=
_converse
.
connection
.
sendIQ
;
var
sendIQ
=
_converse
.
connection
.
sendIQ
;
spyOn
(
_converse
.
connection
,
'
sendIQ
'
).
and
.
callFake
(
function
(
iq
,
callback
,
errback
)
{
spyOn
(
_converse
.
connection
,
'
sendIQ
'
).
and
.
callFake
(
function
(
iq
,
callback
,
errback
)
{
sent_stanza
=
iq
;
sent_stanza
=
iq
;
IQ_id
=
sendIQ
.
bind
(
this
)(
iq
,
callback
,
errback
);
IQ_id
=
sendIQ
.
bind
(
this
)(
iq
,
callback
,
errback
);
});
});
var
start
=
'
2010-06-07T00:00:00Z
'
;
const
start
=
'
2010-06-07T00:00:00Z
'
;
_converse
.
api
.
archive
.
query
({
'
start
'
:
start
,
'
max
'
:
10
});
_converse
.
api
.
archive
.
query
({
'
start
'
:
start
,
'
max
'
:
10
});
var
queryid
=
sent_stanza
.
nodeTree
.
querySelector
(
'
query
'
).
getAttribute
(
'
queryid
'
);
const
queryid
=
sent_stanza
.
nodeTree
.
querySelector
(
'
query
'
).
getAttribute
(
'
queryid
'
);
expect
(
sent_stanza
.
toString
()).
toBe
(
expect
(
sent_stanza
.
toString
()).
toBe
(
`<iq id="
${
IQ_id
}
" type="set" xmlns="jabber:client">`
+
`<iq id="
${
IQ_id
}
" type="set" xmlns="jabber:client">`
+
`<query queryid="
${
queryid
}
" xmlns="urn:xmpp:mam:2">`
+
`<query queryid="
${
queryid
}
" xmlns="urn:xmpp:mam:2">`
+
...
@@ -367,31 +360,30 @@
...
@@ -367,31 +360,30 @@
`</iq>`
`</iq>`
);
);
done
();
done
();
});
}));
}));
it
(
"
can be used to page through results
"
,
it
(
"
can be used to page through results
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[],
{},
null
,
[],
{},
function
(
done
,
_converse
)
{
async
function
(
done
,
_converse
)
{
_converse
.
api
.
disco
.
entities
.
get
(
_converse
.
domain
).
then
(
function
(
entity
)
{
const
entity
=
await
_converse
.
api
.
disco
.
entities
.
get
(
_converse
.
domain
);
if
(
!
entity
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
if
(
!
entity
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
_converse
.
disco_entities
.
get
(
_converse
.
domain
).
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
_converse
.
disco_entities
.
get
(
_converse
.
domain
).
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
}
}
var
sent_stanza
,
IQ_id
;
let
sent_stanza
,
IQ_id
;
var
sendIQ
=
_converse
.
connection
.
sendIQ
;
const
sendIQ
=
_converse
.
connection
.
sendIQ
;
spyOn
(
_converse
.
connection
,
'
sendIQ
'
).
and
.
callFake
(
function
(
iq
,
callback
,
errback
)
{
spyOn
(
_converse
.
connection
,
'
sendIQ
'
).
and
.
callFake
(
function
(
iq
,
callback
,
errback
)
{
sent_stanza
=
iq
;
sent_stanza
=
iq
;
IQ_id
=
sendIQ
.
bind
(
this
)(
iq
,
callback
,
errback
);
IQ_id
=
sendIQ
.
bind
(
this
)(
iq
,
callback
,
errback
);
});
});
var
start
=
'
2010-06-07T00:00:00Z
'
;
const
start
=
'
2010-06-07T00:00:00Z
'
;
_converse
.
api
.
archive
.
query
({
_converse
.
api
.
archive
.
query
({
'
start
'
:
start
,
'
start
'
:
start
,
'
after
'
:
'
09af3-cc343-b409f
'
,
'
after
'
:
'
09af3-cc343-b409f
'
,
'
max
'
:
10
'
max
'
:
10
});
});
var
queryid
=
sent_stanza
.
nodeTree
.
querySelector
(
'
query
'
).
getAttribute
(
'
queryid
'
);
const
queryid
=
sent_stanza
.
nodeTree
.
querySelector
(
'
query
'
).
getAttribute
(
'
queryid
'
);
expect
(
sent_stanza
.
toString
()).
toBe
(
expect
(
sent_stanza
.
toString
()).
toBe
(
`<iq id="
${
IQ_id
}
" type="set" xmlns="jabber:client">`
+
`<iq id="
${
IQ_id
}
" type="set" xmlns="jabber:client">`
+
`<query queryid="
${
queryid
}
" xmlns="urn:xmpp:mam:2">`
+
`<query queryid="
${
queryid
}
" xmlns="urn:xmpp:mam:2">`
+
...
@@ -410,26 +402,25 @@
...
@@ -410,26 +402,25 @@
`</query>`
+
`</query>`
+
`</iq>`
);
`</iq>`
);
done
();
done
();
});
}));
}));
it
(
"
accepts
\"
before
\"
with an empty string as value to reverse the order
"
,
it
(
"
accepts
\"
before
\"
with an empty string as value to reverse the order
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[],
{},
null
,
[],
{},
function
(
done
,
_converse
)
{
async
function
(
done
,
_converse
)
{
_converse
.
api
.
disco
.
entities
.
get
(
_converse
.
domain
).
then
(
function
(
entity
)
{
const
entity
=
await
_converse
.
api
.
disco
.
entities
.
get
(
_converse
.
domain
);
if
(
!
entity
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
if
(
!
entity
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
_converse
.
disco_entities
.
get
(
_converse
.
domain
).
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
_converse
.
disco_entities
.
get
(
_converse
.
domain
).
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
}
}
var
sent_stanza
,
IQ_id
;
let
sent_stanza
,
IQ_id
;
var
sendIQ
=
_converse
.
connection
.
sendIQ
;
const
sendIQ
=
_converse
.
connection
.
sendIQ
;
spyOn
(
_converse
.
connection
,
'
sendIQ
'
).
and
.
callFake
(
function
(
iq
,
callback
,
errback
)
{
spyOn
(
_converse
.
connection
,
'
sendIQ
'
).
and
.
callFake
(
function
(
iq
,
callback
,
errback
)
{
sent_stanza
=
iq
;
sent_stanza
=
iq
;
IQ_id
=
sendIQ
.
bind
(
this
)(
iq
,
callback
,
errback
);
IQ_id
=
sendIQ
.
bind
(
this
)(
iq
,
callback
,
errback
);
});
});
_converse
.
api
.
archive
.
query
({
'
before
'
:
''
,
'
max
'
:
10
});
_converse
.
api
.
archive
.
query
({
'
before
'
:
''
,
'
max
'
:
10
});
var
queryid
=
sent_stanza
.
nodeTree
.
querySelector
(
'
query
'
).
getAttribute
(
'
queryid
'
);
const
queryid
=
sent_stanza
.
nodeTree
.
querySelector
(
'
query
'
).
getAttribute
(
'
queryid
'
);
expect
(
sent_stanza
.
toString
()).
toBe
(
expect
(
sent_stanza
.
toString
()).
toBe
(
`<iq id="
${
IQ_id
}
" type="set" xmlns="jabber:client">`
+
`<iq id="
${
IQ_id
}
" type="set" xmlns="jabber:client">`
+
`<query queryid="
${
queryid
}
" xmlns="urn:xmpp:mam:2">`
+
`<query queryid="
${
queryid
}
" xmlns="urn:xmpp:mam:2">`
+
...
@@ -445,20 +436,19 @@
...
@@ -445,20 +436,19 @@
`</query>`
+
`</query>`
+
`</iq>`
);
`</iq>`
);
done
();
done
();
});
}));
}));
it
(
"
accepts a Strophe.RSM object for the query options
"
,
it
(
"
accepts a Strophe.RSM object for the query options
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[],
{},
null
,
[],
{},
function
(
done
,
_converse
)
{
async
function
(
done
,
_converse
)
{
_converse
.
api
.
disco
.
entities
.
get
(
_converse
.
domain
).
then
(
function
(
entity
)
{
const
entity
=
await
_converse
.
api
.
disco
.
entities
.
get
(
_converse
.
domain
);
if
(
!
entity
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
if
(
!
entity
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
_converse
.
disco_entities
.
get
(
_converse
.
domain
).
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
_converse
.
disco_entities
.
get
(
_converse
.
domain
).
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
}
}
var
sent_stanza
,
IQ_id
;
let
sent_stanza
,
IQ_id
;
var
sendIQ
=
_converse
.
connection
.
sendIQ
;
const
sendIQ
=
_converse
.
connection
.
sendIQ
;
spyOn
(
_converse
.
connection
,
'
sendIQ
'
).
and
.
callFake
(
function
(
iq
,
callback
,
errback
)
{
spyOn
(
_converse
.
connection
,
'
sendIQ
'
).
and
.
callFake
(
function
(
iq
,
callback
,
errback
)
{
sent_stanza
=
iq
;
sent_stanza
=
iq
;
IQ_id
=
sendIQ
.
bind
(
this
)(
iq
,
callback
,
errback
);
IQ_id
=
sendIQ
.
bind
(
this
)(
iq
,
callback
,
errback
);
...
@@ -467,12 +457,12 @@
...
@@ -467,12 +457,12 @@
// and pass it in. However, in the callback method an RSM object is
// and pass it in. However, in the callback method an RSM object is
// returned which can be reused for easy paging. This test is
// returned which can be reused for easy paging. This test is
// more for that usecase.
// more for that usecase.
var
rsm
=
new
Strophe
.
RSM
({
'
max
'
:
'
10
'
});
const
rsm
=
new
Strophe
.
RSM
({
'
max
'
:
'
10
'
});
rsm
[
'
with
'
]
=
'
romeo@montague.lit
'
;
// eslint-disable-line dot-notation
rsm
[
'
with
'
]
=
'
romeo@montague.lit
'
;
// eslint-disable-line dot-notation
rsm
.
start
=
'
2010-06-07T00:00:00Z
'
;
rsm
.
start
=
'
2010-06-07T00:00:00Z
'
;
_converse
.
api
.
archive
.
query
(
rsm
);
_converse
.
api
.
archive
.
query
(
rsm
);
var
queryid
=
sent_stanza
.
nodeTree
.
querySelector
(
'
query
'
).
getAttribute
(
'
queryid
'
);
const
queryid
=
sent_stanza
.
nodeTree
.
querySelector
(
'
query
'
).
getAttribute
(
'
queryid
'
);
expect
(
sent_stanza
.
toString
()).
toBe
(
expect
(
sent_stanza
.
toString
()).
toBe
(
`<iq id="
${
IQ_id
}
" type="set" xmlns="jabber:client">`
+
`<iq id="
${
IQ_id
}
" type="set" xmlns="jabber:client">`
+
`<query queryid="
${
queryid
}
" xmlns="urn:xmpp:mam:2">`
+
`<query queryid="
${
queryid
}
" xmlns="urn:xmpp:mam:2">`
+
...
@@ -493,7 +483,6 @@
...
@@ -493,7 +483,6 @@
`</query>`
+
`</query>`
+
`</iq>`
);
`</iq>`
);
done
();
done
();
});
}));
}));
it
(
"
accepts a callback function, which it passes the messages and a Strophe.RSM object
"
,
it
(
"
accepts a callback function, which it passes the messages and a Strophe.RSM object
"
,
...
...
src/converse-omemo.js
View file @
79bfb456
...
@@ -331,10 +331,10 @@ converse.plugins.add('converse-omemo', {
...
@@ -331,10 +331,10 @@ converse.plugins.add('converse-omemo', {
}
}
},
},
getMessageAttributesFromStanza
(
stanza
,
original_stanza
)
{
async
getMessageAttributesFromStanza
(
stanza
,
original_stanza
)
{
const
{
_converse
}
=
this
.
__super__
,
const
{
_converse
}
=
this
.
__super__
,
encrypted
=
sizzle
(
`encrypted[xmlns="
${
Strophe
.
NS
.
OMEMO
}
"]`
,
original_stanza
).
pop
(),
encrypted
=
sizzle
(
`encrypted[xmlns="
${
Strophe
.
NS
.
OMEMO
}
"]`
,
original_stanza
).
pop
(),
attrs
=
this
.
__super__
.
getMessageAttributesFromStanza
.
apply
(
this
,
arguments
);
attrs
=
await
this
.
__super__
.
getMessageAttributesFromStanza
.
apply
(
this
,
arguments
);
if
(
!
encrypted
||
!
_converse
.
config
.
get
(
'
trusted
'
))
{
if
(
!
encrypted
||
!
_converse
.
config
.
get
(
'
trusted
'
))
{
return
attrs
;
return
attrs
;
...
...
src/headless/converse-chatboxes.js
View file @
79bfb456
...
@@ -557,15 +557,14 @@ converse.plugins.add('converse-chatboxes', {
...
@@ -557,15 +557,14 @@ converse.plugins.add('converse-chatboxes', {
return
attrs
;
return
attrs
;
},
},
createMessage
(
message
,
original_stanza
)
{
async
createMessage
(
message
,
original_stanza
)
{
/* Create a Backbone.Message object inside this chat box
/* Create a Backbone.Message object inside this chat box
* based on the identified message stanza.
* based on the identified message stanza.
*/
*/
const
that
=
this
;
const
attrs
=
await
this
.
getMessageAttributesFromStanza
(
message
,
original_stanza
),
function
_create
(
attrs
)
{
is_csn
=
u
.
isOnlyChatStateNotification
(
attrs
);
const
is_csn
=
u
.
isOnlyChatStateNotification
(
attrs
);
if
(
is_csn
&&
(
attrs
.
is_delayed
||
if
(
is_csn
&&
(
attrs
.
is_delayed
||
(
attrs
.
type
===
'
groupchat
'
&&
Strophe
.
getResourceFromJid
(
attrs
.
from
)
==
this
.
get
(
'
nick
'
))))
{
(
attrs
.
type
===
'
groupchat
'
&&
Strophe
.
getResourceFromJid
(
attrs
.
from
)
==
that
.
get
(
'
nick
'
))))
{
// XXX: MUC leakage
// XXX: MUC leakage
// No need showing delayed or our own CSN messages
// No need showing delayed or our own CSN messages
return
;
return
;
...
@@ -573,15 +572,7 @@ converse.plugins.add('converse-chatboxes', {
...
@@ -573,15 +572,7 @@ converse.plugins.add('converse-chatboxes', {
// TODO: handle <subject> messages (currently being done by ChatRoom)
// TODO: handle <subject> messages (currently being done by ChatRoom)
return
;
return
;
}
else
{
}
else
{
return
that
.
messages
.
create
(
attrs
);
return
this
.
messages
.
create
(
attrs
);
}
}
const
result
=
this
.
getMessageAttributesFromStanza
(
message
,
original_stanza
)
if
(
typeof
result
.
then
===
"
function
"
)
{
return
new
Promise
((
resolve
,
reject
)
=>
result
.
then
(
attrs
=>
resolve
(
_create
(
attrs
))));
}
else
{
const
message
=
_create
(
result
)
return
Promise
.
resolve
(
message
);
}
}
},
},
...
...
src/headless/converse-mam.js
View file @
79bfb456
...
@@ -133,21 +133,11 @@ converse.plugins.add('converse-mam', {
...
@@ -133,21 +133,11 @@ converse.plugins.add('converse-mam', {
// New functions which don't exist yet can also be added.
// New functions which don't exist yet can also be added.
ChatBox
:
{
ChatBox
:
{
getMessageAttributesFromStanza
(
message
,
original_stanza
)
{
async
getMessageAttributesFromStanza
(
message
,
original_stanza
)
{
function
_process
(
attrs
)
{
const
attrs
=
await
this
.
__super__
.
getMessageAttributesFromStanza
.
apply
(
this
,
arguments
);
const
archive_id
=
getMessageArchiveID
(
original_stanza
);
attrs
.
archive_id
=
getMessageArchiveID
(
original_stanza
);
if
(
archive_id
)
{
attrs
.
archive_id
=
archive_id
;
}
return
attrs
;
return
attrs
;
}
}
const
result
=
this
.
__super__
.
getMessageAttributesFromStanza
.
apply
(
this
,
arguments
)
if
(
result
instanceof
Promise
)
{
return
new
Promise
((
resolve
,
reject
)
=>
result
.
then
((
attrs
)
=>
resolve
(
_process
(
attrs
))).
catch
(
reject
));
}
else
{
return
_process
(
result
);
}
}
},
},
ChatBoxView
:
{
ChatBoxView
:
{
...
...
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