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
b77d76b3
Commit
b77d76b3
authored
Jul 10, 2015
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Started adding the API for querying archived messages.
parent
eeeaddbe
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
256 additions
and
11 deletions
+256
-11
converse.js
converse.js
+42
-0
main.js
main.js
+1
-1
spec/mam.js
spec/mam.js
+213
-10
No files found.
converse.js
View file @
b77d76b3
...
...
@@ -160,6 +160,7 @@
Strophe
.
addNamespace
(
'
MUC_USER
'
,
Strophe
.
NS
.
MUC
+
"
#user
"
);
Strophe
.
addNamespace
(
'
REGISTER
'
,
'
jabber:iq:register
'
);
Strophe
.
addNamespace
(
'
ROSTERX
'
,
'
http://jabber.org/protocol/rosterx
'
);
Strophe
.
addNamespace
(
'
RSM
'
,
'
http://jabber.org/protocol/rsm
'
);
Strophe
.
addNamespace
(
'
XFORM
'
,
'
jabber:x:data
'
);
// Add Strophe Statuses
...
...
@@ -6106,6 +6107,47 @@
return
_
.
map
(
jids
,
getWrappedChatBox
);
}
},
'
archive
'
:
{
'
query
'
:
function
(
options
,
callback
,
errback
)
{
var
date
;
// Available options are jid, limit, start, end, after, before
if
(
typeof
options
==
"
function
"
)
{
callback
=
options
;
errback
=
callback
;
}
if
(
!
converse
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
throw
new
Error
(
'
This server does not support XEP-0313, Message Archive Management
'
);
}
var
stanza
=
$iq
({
'
type
'
:
'
set
'
}).
c
(
'
query
'
,
{
'
xmlns
'
:
Strophe
.
NS
.
MAM
,
'
queryid
'
:
converse
.
connection
.
getUniqueId
()});
if
(
typeof
options
!=
"
undefined
"
)
{
stanza
.
c
(
'
x
'
,
{
'
xmlns
'
:
'
jabber:x:data
'
})
.
c
(
'
field
'
,
{
'
var
'
:
'
FORM_TYPE
'
})
.
c
(
'
value
'
).
t
(
Strophe
.
NS
.
MAM
).
up
().
up
();
if
(
options
.
jid
)
{
stanza
.
c
(
'
field
'
,
{
'
var
'
:
'
with
'
}).
c
(
'
value
'
).
t
(
options
.
jid
).
up
().
up
();
}
_
.
each
([
'
start
'
,
'
end
'
],
function
(
t
)
{
if
(
options
[
t
])
{
date
=
moment
(
options
[
t
]);
if
(
date
.
isValid
())
{
stanza
.
c
(
'
field
'
,
{
'
var
'
:
t
}).
c
(
'
value
'
).
t
(
date
.
format
()).
up
().
up
();
}
else
{
throw
new
TypeError
(
'
archive.query: invalid date provided for:
'
+
t
);
}
}
});
stanza
.
up
();
if
(
options
.
limit
)
{
stanza
.
c
(
'
set
'
,
{
'
xmlns
'
:
Strophe
.
NS
.
RSM
}).
c
(
'
max
'
).
t
(
options
.
limit
).
up
();
}
if
(
options
.
after
)
{
stanza
.
c
(
'
after
'
).
t
(
options
.
after
).
up
();
}
}
converse
.
connection
.
sendIQ
(
stanza
,
callback
,
errback
);
}
},
'
rooms
'
:
{
'
open
'
:
function
(
jids
,
nick
)
{
if
(
!
nick
)
{
...
...
main.js
View file @
b77d76b3
...
...
@@ -26,7 +26,7 @@ require.config({
"
jquery-private
"
:
"
src/jquery-private
"
,
"
jquery.browser
"
:
"
components/jquery.browser/dist/jquery.browser
"
,
"
jquery.easing
"
:
"
components/jquery-easing-original/index
"
,
// XXX: Only required for https://conversejs.org website
"
moment
"
:
"
components/momentjs/m
in/moment.min
"
,
"
moment
"
:
"
components/momentjs/m
oment
"
,
"
strophe-base64
"
:
"
components/strophejs/src/base64
"
,
"
strophe-bosh
"
:
"
components/strophejs/src/bosh
"
,
"
strophe-core
"
:
"
components/strophejs/src/core
"
,
...
...
spec/mam.js
View file @
b77d76b3
...
...
@@ -12,22 +12,225 @@
var
Strophe
=
converse_api
.
env
.
Strophe
;
var
$iq
=
converse_api
.
env
.
$iq
;
var
$pres
=
converse_api
.
env
.
$pres
;
// See:
// https://xmpp.org/rfcs/rfc3921.html
// See: https://xmpp.org/rfcs/rfc3921.html
describe
(
"
Message Archive Management
"
,
$
.
proxy
(
function
(
mock
,
test_utils
)
{
// Implement the protocol defined in https://xmpp.org/extensions/xep-0313.html#config
describe
(
"
The default preference
"
,
$
.
proxy
(
function
(
mock
,
test_utils
)
{
beforeEach
(
function
()
{
test_utils
.
closeAllChatBoxes
();
test_utils
.
removeControlBox
();
converse
.
roster
.
browserStorage
.
_clear
();
test_utils
.
initConverse
();
test_utils
.
openControlBox
();
test_utils
.
openContactsPanel
();
describe
(
"
The archive.query API
"
,
$
.
proxy
(
function
(
mock
,
test_utils
)
{
it
(
"
can be used to query for all archived messages
"
,
function
()
{
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
);
});
if
(
!
converse
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
converse
.
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
}
converse_api
.
archive
.
query
();
var
queryid
=
$
(
sent_stanza
.
toString
()).
find
(
'
query
'
).
attr
(
'
queryid
'
);
expect
(
sent_stanza
.
toString
()).
toBe
(
"
<iq type='set' xmlns='jabber:client' id='
"
+
IQ_id
+
"
'><query xmlns='urn:xmpp:mam:0' queryid='
"
+
queryid
+
"
'/></iq>
"
);
});
it
(
"
can be used to query for all messages to/from a particular JID
"
,
function
()
{
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
);
});
if
(
!
converse
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
converse
.
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
}
converse_api
.
archive
.
query
({
'
jid
'
:
'
juliet@capulet.lit
'
});
var
queryid
=
$
(
sent_stanza
.
toString
()).
find
(
'
query
'
).
attr
(
'
queryid
'
);
expect
(
sent_stanza
.
toString
()).
toBe
(
"
<iq type='set' xmlns='jabber:client' id='
"
+
IQ_id
+
"
'>
"
+
"
<query xmlns='urn:xmpp:mam:0' queryid='
"
+
queryid
+
"
'>
"
+
"
<x xmlns='jabber:x:data'>
"
+
"
<field var='FORM_TYPE'>
"
+
"
<value>urn:xmpp:mam:0</value>
"
+
"
</field>
"
+
"
<field var='with'>
"
+
"
<value>juliet@capulet.lit</value>
"
+
"
</field>
"
+
"
</x>
"
+
"
</query>
"
+
"
</iq>
"
);
});
it
(
"
can be used to query for all messages in a certain timespan
"
,
function
()
{
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
);
});
if
(
!
converse
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
converse
.
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
}
// Mock the browser's method for returning the timezone
var
getTimezoneOffset
=
Date
.
prototype
.
getTimezoneOffset
;
Date
.
prototype
.
getTimezoneOffset
=
function
()
{
return
-
120
;
};
converse_api
.
archive
.
query
({
'
start
'
:
'
2010-06-07T00:00:00Z
'
,
'
end
'
:
'
2010-07-07T13:23:54Z
'
});
var
queryid
=
$
(
sent_stanza
.
toString
()).
find
(
'
query
'
).
attr
(
'
queryid
'
);
expect
(
sent_stanza
.
toString
()).
toBe
(
"
<iq type='set' xmlns='jabber:client' id='
"
+
IQ_id
+
"
'>
"
+
"
<query xmlns='urn:xmpp:mam:0' queryid='
"
+
queryid
+
"
'>
"
+
"
<x xmlns='jabber:x:data'>
"
+
"
<field var='FORM_TYPE'>
"
+
"
<value>urn:xmpp:mam:0</value>
"
+
"
</field>
"
+
"
<field var='start'>
"
+
"
<value>2010-06-07T02:00:00+02:00</value>
"
+
"
</field>
"
+
"
<field var='end'>
"
+
"
<value>2010-07-07T15:23:54+02:00</value>
"
+
"
</field>
"
+
"
</x>
"
+
"
</query>
"
+
"
</iq>
"
);
// Restore
Date
.
prototype
.
getTimezoneOffset
=
getTimezoneOffset
;
});
it
(
"
throws a TypeError if an invalid date is provided
"
,
function
()
{
expect
(
_
.
partial
(
converse_api
.
archive
.
query
,
{
'
start
'
:
'
not a real date
'
})).
toThrow
(
new
TypeError
(
'
archive.query: invalid date provided for: start
'
)
);
});
it
(
"
can be used to query for all messages after a certain time
"
,
function
()
{
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
);
});
if
(
!
converse
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
converse
.
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
}
// Mock the browser's method for returning the timezone
var
getTimezoneOffset
=
Date
.
prototype
.
getTimezoneOffset
;
Date
.
prototype
.
getTimezoneOffset
=
function
()
{
return
-
120
;
};
converse_api
.
archive
.
query
({
'
start
'
:
'
2010-06-07T00:00:00Z
'
});
var
queryid
=
$
(
sent_stanza
.
toString
()).
find
(
'
query
'
).
attr
(
'
queryid
'
);
expect
(
sent_stanza
.
toString
()).
toBe
(
"
<iq type='set' xmlns='jabber:client' id='
"
+
IQ_id
+
"
'>
"
+
"
<query xmlns='urn:xmpp:mam:0' queryid='
"
+
queryid
+
"
'>
"
+
"
<x xmlns='jabber:x:data'>
"
+
"
<field var='FORM_TYPE'>
"
+
"
<value>urn:xmpp:mam:0</value>
"
+
"
</field>
"
+
"
<field var='start'>
"
+
"
<value>2010-06-07T02:00:00+02:00</value>
"
+
"
</field>
"
+
"
</x>
"
+
"
</query>
"
+
"
</iq>
"
);
// Restore
Date
.
prototype
.
getTimezoneOffset
=
getTimezoneOffset
;
});
it
(
"
can be used to query for a limited set of results
"
,
function
()
{
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
);
});
if
(
!
converse
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
converse
.
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
}
// Mock the browser's method for returning the timezone
var
getTimezoneOffset
=
Date
.
prototype
.
getTimezoneOffset
;
Date
.
prototype
.
getTimezoneOffset
=
function
()
{
return
-
120
;
};
converse_api
.
archive
.
query
({
'
start
'
:
'
2010-06-07T00:00:00Z
'
,
'
limit
'
:
10
});
var
queryid
=
$
(
sent_stanza
.
toString
()).
find
(
'
query
'
).
attr
(
'
queryid
'
);
expect
(
sent_stanza
.
toString
()).
toBe
(
"
<iq type='set' xmlns='jabber:client' id='
"
+
IQ_id
+
"
'>
"
+
"
<query xmlns='urn:xmpp:mam:0' queryid='
"
+
queryid
+
"
'>
"
+
"
<x xmlns='jabber:x:data'>
"
+
"
<field var='FORM_TYPE'>
"
+
"
<value>urn:xmpp:mam:0</value>
"
+
"
</field>
"
+
"
<field var='start'>
"
+
"
<value>2010-06-07T02:00:00+02:00</value>
"
+
"
</field>
"
+
"
</x>
"
+
"
<set xmlns='http://jabber.org/protocol/rsm'>
"
+
"
<max>10</max>
"
+
"
</set>
"
+
"
</query>
"
+
"
</iq>
"
);
// Restore
Date
.
prototype
.
getTimezoneOffset
=
getTimezoneOffset
;
});
it
(
"
can be used to page through results
"
,
function
()
{
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
);
});
if
(
!
converse
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
converse
.
features
.
create
({
'
var
'
:
Strophe
.
NS
.
MAM
});
}
// Mock the browser's method for returning the timezone
var
getTimezoneOffset
=
Date
.
prototype
.
getTimezoneOffset
;
Date
.
prototype
.
getTimezoneOffset
=
function
()
{
return
-
120
;
};
converse_api
.
archive
.
query
({
'
start
'
:
'
2010-06-07T00:00:00Z
'
,
'
after
'
:
'
09af3-cc343-b409f
'
,
'
limit
'
:
10
});
var
queryid
=
$
(
sent_stanza
.
toString
()).
find
(
'
query
'
).
attr
(
'
queryid
'
);
expect
(
sent_stanza
.
toString
()).
toBe
(
"
<iq type='set' xmlns='jabber:client' id='
"
+
IQ_id
+
"
'>
"
+
"
<query xmlns='urn:xmpp:mam:0' queryid='
"
+
queryid
+
"
'>
"
+
"
<x xmlns='jabber:x:data'>
"
+
"
<field var='FORM_TYPE'>
"
+
"
<value>urn:xmpp:mam:0</value>
"
+
"
</field>
"
+
"
<field var='start'>
"
+
"
<value>2010-06-07T02:00:00+02:00</value>
"
+
"
</field>
"
+
"
</x>
"
+
"
<set xmlns='http://jabber.org/protocol/rsm'>
"
+
"
<max>10</max>
"
+
"
<after>09af3-cc343-b409f</after>
"
+
"
</set>
"
+
"
</query>
"
+
"
</iq>
"
);
// Restore
Date
.
prototype
.
getTimezoneOffset
=
getTimezoneOffset
;
});
},
converse
,
mock
,
test_utils
));
describe
(
"
The default preference
"
,
$
.
proxy
(
function
(
mock
,
test_utils
)
{
it
(
"
is set once server support for MAM has been confirmed
"
,
function
()
{
var
sent_stanza
,
IQ_id
;
var
sendIQ
=
converse
.
connection
.
sendIQ
;
...
...
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