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
1a9771c7
Commit
1a9771c7
authored
Jul 12, 2015
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test code which receives archived messages and calls callback
updates #306
parent
27afd32a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
10 deletions
+60
-10
converse.js
converse.js
+7
-7
spec/mam.js
spec/mam.js
+53
-3
No files found.
converse.js
View file @
1a9771c7
...
@@ -558,23 +558,23 @@
...
@@ -558,23 +558,23 @@
var
messages
=
[];
var
messages
=
[];
converse
.
connection
.
addHandler
(
converse
.
connection
.
addHandler
(
function
(
message
)
{
function
(
message
)
{
var
$msg
=
$
(
message
),
$fin
;
var
$msg
=
$
(
message
),
$fin
,
rsm
,
i
;
if
(
typeof
callback
==
"
function
"
)
{
if
(
typeof
callback
==
"
function
"
)
{
$fin
=
$msg
.
find
(
'
fin[xmlns="
'
+
Strophe
.
NS
.
MAM
+
'
"]
'
);
$fin
=
$msg
.
find
(
'
fin[xmlns="
'
+
Strophe
.
NS
.
MAM
+
'
"]
'
);
if
(
$fin
.
length
)
{
if
(
$fin
.
length
)
{
callback
(
rsm
=
new
Strophe
.
RSM
({
xml
:
$fin
.
find
(
'
set
'
)[
0
]});
messages
,
_
.
extend
(
rsm
,
_
.
pick
(
options
,
[
'
max
'
,
'
after
'
,
'
before
'
]));
new
Strophe
.
RSM
(
_
.
extend
({
xml
:
$fin
.
find
(
'
set
'
)[
0
]},
_
.
pick
(
options
,
MAM_ATTRIBUTES
)))
_
.
extend
(
rsm
,
_
.
pick
(
options
,
MAM_ATTRIBUTES
));
);
callback
(
messages
,
rsm
);
return
false
;
// We've received all messages, decommission this handler
return
false
;
// We've received all messages, decommission this handler
}
else
if
(
queryid
==
$msg
.
find
(
'
result
[xmlns="
'
+
Strophe
.
NS
.
MAM
+
'
"]
'
).
attr
(
'
queryid
'
))
{
}
else
if
(
queryid
==
$msg
.
find
(
'
result
'
).
attr
(
'
queryid
'
))
{
messages
.
push
(
message
);
messages
.
push
(
message
);
}
}
return
true
;
return
true
;
}
else
{
}
else
{
return
false
;
// There's no callback, so no use in continuing this handler.
return
false
;
// There's no callback, so no use in continuing this handler.
}
}
},
null
,
'
message
'
);
},
Strophe
.
NS
.
MAM
,
'
message
'
);
};
};
this
.
getVCard
=
function
(
jid
,
callback
,
errback
)
{
this
.
getVCard
=
function
(
jid
,
callback
,
errback
)
{
...
...
spec/mam.js
View file @
1a9771c7
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
var
Strophe
=
converse_api
.
env
.
Strophe
;
var
Strophe
=
converse_api
.
env
.
Strophe
;
var
$iq
=
converse_api
.
env
.
$iq
;
var
$iq
=
converse_api
.
env
.
$iq
;
var
$pres
=
converse_api
.
env
.
$pres
;
var
$pres
=
converse_api
.
env
.
$pres
;
var
$msg
=
converse_api
.
env
.
$msg
;
// See: https://xmpp.org/rfcs/rfc3921.html
// See: https://xmpp.org/rfcs/rfc3921.html
describe
(
"
Message Archive Management
"
,
$
.
proxy
(
function
(
mock
,
test_utils
)
{
describe
(
"
Message Archive Management
"
,
$
.
proxy
(
function
(
mock
,
test_utils
)
{
...
@@ -261,15 +262,15 @@
...
@@ -261,15 +262,15 @@
// 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.
if
(
!
converse
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
converse
.
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
}
var
sent_stanza
,
IQ_id
;
var
sent_stanza
,
IQ_id
;
var
sendIQ
=
converse
.
connection
.
sendIQ
;
var
sendIQ
=
converse
.
connection
.
sendIQ
;
spyOn
(
converse
.
connection
,
'
sendIQ
'
).
andCallFake
(
function
(
iq
,
callback
,
errback
)
{
spyOn
(
converse
.
connection
,
'
sendIQ
'
).
andCallFake
(
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
);
});
});
if
(
!
converse
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
converse
.
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
}
// Mock the browser's method for returning the timezone
// Mock the browser's method for returning the timezone
var
getTimezoneOffset
=
Date
.
prototype
.
getTimezoneOffset
;
var
getTimezoneOffset
=
Date
.
prototype
.
getTimezoneOffset
;
Date
.
prototype
.
getTimezoneOffset
=
function
()
{
Date
.
prototype
.
getTimezoneOffset
=
function
()
{
...
@@ -305,6 +306,55 @@
...
@@ -305,6 +306,55 @@
Date
.
prototype
.
getTimezoneOffset
=
getTimezoneOffset
;
Date
.
prototype
.
getTimezoneOffset
=
getTimezoneOffset
;
});
});
it
(
"
accepts a callback function, which it passes the messages and a Strophe.RSM object
"
,
function
()
{
if
(
!
converse
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
converse
.
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
}
var
sent_stanza
,
IQ_id
;
var
sendIQ
=
converse
.
connection
.
sendIQ
;
spyOn
(
converse
.
connection
,
'
sendIQ
'
).
andCallFake
(
function
(
iq
,
callback
,
errback
)
{
sent_stanza
=
iq
;
IQ_id
=
sendIQ
.
bind
(
this
)(
iq
,
callback
,
errback
);
});
spyOn
(
converse
,
'
onMAMQueryResult
'
).
andCallThrough
();
var
callback
=
jasmine
.
createSpy
(
'
callback
'
);
converse_api
.
archive
.
query
({
'
with
'
:
'
romeo@capulet.lit
'
,
'
max
'
:
'
10
'
},
callback
);
var
queryid
=
$
(
sent_stanza
.
toString
()).
find
(
'
query
'
).
attr
(
'
queryid
'
);
// Send the result stanza, so that the callback is called.
var
stanza
=
$iq
({
'
type
'
:
'
result
'
,
'
id
'
:
IQ_id
});
converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
expect
(
converse
.
onMAMQueryResult
).
toHaveBeenCalled
();
/* Send a <fin> message to indicate the end of the result set.
*
* <message>
* <fin xmlns='urn:xmpp:mam:0' complete='true'>
* <set xmlns='http://jabber.org/protocol/rsm'>
* <first index='0'>23452-4534-1</first>
* <last>390-2342-22</last>
* <count>16</count>
* </set>
* </fin>
* </message>
*/
stanza
=
$msg
().
c
(
'
fin
'
,
{
'
xmlns
'
:
'
urn:xmpp:mam:0
'
,
'
complete
'
:
'
true
'
})
.
c
(
'
set
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/rsm
'
})
.
c
(
'
first
'
,
{
'
index
'
:
'
0
'
}).
t
(
'
23452-4534-1
'
).
up
()
.
c
(
'
last
'
).
t
(
'
390-2342-22
'
).
up
()
.
c
(
'
count
'
).
t
(
'
16
'
);
converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
expect
(
callback
).
toHaveBeenCalled
();
var
args
=
callback
.
argsForCall
[
0
];
expect
(
args
[
1
][
'
with
'
]).
toBe
(
'
romeo@capulet.lit
'
);
expect
(
args
[
1
].
max
).
toBe
(
'
10
'
);
expect
(
args
[
1
].
count
).
toBe
(
'
16
'
);
expect
(
args
[
1
].
first
).
toBe
(
'
23452-4534-1
'
);
expect
(
args
[
1
].
last
).
toBe
(
'
390-2342-22
'
);
});
},
converse
,
mock
,
test_utils
));
},
converse
,
mock
,
test_utils
));
describe
(
"
The default preference
"
,
$
.
proxy
(
function
(
mock
,
test_utils
)
{
describe
(
"
The default preference
"
,
$
.
proxy
(
function
(
mock
,
test_utils
)
{
...
...
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