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
5eea22f2
Commit
5eea22f2
authored
Jul 21, 2015
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More work on showing archived chatroom messages.
updates #306
parent
404ab966
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
46 deletions
+39
-46
converse.js
converse.js
+39
-44
spec/mam.js
spec/mam.js
+0
-2
No files found.
converse.js
View file @
5eea22f2
...
@@ -546,39 +546,6 @@
...
@@ -546,39 +546,6 @@
converse
.
connection
.
send
(
pres
);
converse
.
connection
.
send
(
pres
);
};
};
this
.
onMAMQueryResult
=
function
(
iq
,
options
,
queryid
,
callback
)
{
/* Handle the IQ stanza and potential message stanzas returned as
* a result of a MAM (XEP-0313) query.
*
* Parameters:
* (XMLElement) iq - The IQ stanza returned from the XMPP server.
* (Object) options - The MAM-specific options of the query ('with', 'start' and 'end')
* (String) queryid - A unique ID sent with the MAM query.
* (Function) callback - A function to call after we've received all the archived messages.
* If should expect an array of messages and a Strophe.RSM (result set management) object.
*/
var
messages
=
[];
converse
.
connection
.
addHandler
(
function
(
message
)
{
var
$msg
=
$
(
message
),
$fin
,
rsm
,
i
;
if
(
typeof
callback
==
"
function
"
)
{
$fin
=
$msg
.
find
(
'
fin[xmlns="
'
+
Strophe
.
NS
.
MAM
+
'
"]
'
);
if
(
$fin
.
length
)
{
rsm
=
new
Strophe
.
RSM
({
xml
:
$fin
.
find
(
'
set
'
)[
0
]});
_
.
extend
(
rsm
,
_
.
pick
(
options
,
[
'
max
'
]));
_
.
extend
(
rsm
,
_
.
pick
(
options
,
MAM_ATTRIBUTES
));
callback
(
messages
,
rsm
);
return
false
;
// We've received all messages, decommission this handler
}
else
if
(
queryid
==
$msg
.
find
(
'
result
'
).
attr
(
'
queryid
'
))
{
messages
.
push
(
message
);
}
return
true
;
}
else
{
return
false
;
// There's no callback, so no use in continuing this handler.
}
},
Strophe
.
NS
.
MAM
,
'
message
'
);
};
this
.
getVCard
=
function
(
jid
,
callback
,
errback
)
{
this
.
getVCard
=
function
(
jid
,
callback
,
errback
)
{
/* Request the VCard of another user.
/* Request the VCard of another user.
*
*
...
@@ -1324,7 +1291,11 @@
...
@@ -1324,7 +1291,11 @@
function
(
messages
)
{
function
(
messages
)
{
this
.
clearSpinner
();
this
.
clearSpinner
();
if
(
messages
.
length
)
{
if
(
messages
.
length
)
{
_
.
map
(
messages
,
converse
.
chatboxes
.
onMessage
.
bind
(
converse
.
chatboxes
));
if
(
this
.
is_chatroom
)
{
_
.
map
(
messages
,
this
.
onChatRoomMessage
.
bind
(
this
));
}
else
{
_
.
map
(
messages
,
converse
.
chatboxes
.
onMessage
.
bind
(
converse
.
chatboxes
));
}
}
}
}.
bind
(
this
),
}.
bind
(
this
),
_
.
partial
(
converse
.
log
,
"
Error while trying to fetch archived messages
"
,
"
error
"
)
_
.
partial
(
converse
.
log
,
"
Error while trying to fetch archived messages
"
,
"
error
"
)
...
@@ -2776,6 +2747,7 @@
...
@@ -2776,6 +2747,7 @@
this
.
render
();
this
.
render
();
this
.
occupantsview
.
model
.
fetch
({
add
:
true
});
this
.
occupantsview
.
model
.
fetch
({
add
:
true
});
this
.
join
(
null
,
{
'
maxstanzas
'
:
converse
.
muc_history_max_stanzas
});
this
.
join
(
null
,
{
'
maxstanzas
'
:
converse
.
muc_history_max_stanzas
});
this
.
fetchMessages
();
converse
.
emit
(
'
chatRoomOpened
'
,
this
);
converse
.
emit
(
'
chatRoomOpened
'
,
this
);
this
.
$el
.
insertAfter
(
converse
.
chatboxviews
.
get
(
"
controlbox
"
).
$el
);
this
.
$el
.
insertAfter
(
converse
.
chatboxviews
.
get
(
"
controlbox
"
).
$el
);
...
@@ -2790,6 +2762,7 @@
...
@@ -2790,6 +2762,7 @@
this
.
$el
.
attr
(
'
id
'
,
this
.
model
.
get
(
'
box_id
'
))
this
.
$el
.
attr
(
'
id
'
,
this
.
model
.
get
(
'
box_id
'
))
.
html
(
converse
.
templates
.
chatroom
(
this
.
model
.
toJSON
()));
.
html
(
converse
.
templates
.
chatroom
(
this
.
model
.
toJSON
()));
this
.
renderChatArea
();
this
.
renderChatArea
();
this
.
$content
.
on
(
'
scroll
'
,
_
.
debounce
(
this
.
onScroll
.
bind
(
this
),
100
));
setTimeout
(
converse
.
refreshWebkit
,
50
);
setTimeout
(
converse
.
refreshWebkit
,
50
);
return
this
;
return
this
;
},
},
...
@@ -3361,7 +3334,6 @@
...
@@ -3361,7 +3334,6 @@
(
$presence
.
attr
(
'
from
'
)
==
this
.
model
.
get
(
'
id
'
)
+
'
/
'
+
Strophe
.
escapeNode
(
nick
));
(
$presence
.
attr
(
'
from
'
)
==
this
.
model
.
get
(
'
id
'
)
+
'
/
'
+
Strophe
.
escapeNode
(
nick
));
if
(
this
.
model
.
get
(
'
connection_status
'
)
!==
Strophe
.
Status
.
CONNECTED
)
{
if
(
this
.
model
.
get
(
'
connection_status
'
)
!==
Strophe
.
Status
.
CONNECTED
)
{
this
.
model
.
set
(
'
connection_status
'
,
Strophe
.
Status
.
CONNECTED
);
this
.
model
.
set
(
'
connection_status
'
,
Strophe
.
Status
.
CONNECTED
);
this
.
fetchMessages
();
this
.
$
(
'
span.centered.spinner
'
).
remove
();
this
.
$
(
'
span.centered.spinner
'
).
remove
();
this
.
$el
.
find
(
'
.chat-body
'
).
children
().
show
();
this
.
$el
.
find
(
'
.chat-body
'
).
children
().
show
();
}
}
...
@@ -3372,12 +3344,21 @@
...
@@ -3372,12 +3344,21 @@
onChatRoomMessage
:
function
(
message
)
{
onChatRoomMessage
:
function
(
message
)
{
var
$message
=
$
(
message
),
var
$message
=
$
(
message
),
body
=
$message
.
children
(
'
body
'
).
text
(),
archive_id
=
$message
.
find
(
'
result[xmlns="
'
+
Strophe
.
NS
.
MAM
+
'
"]
'
).
attr
(
'
id
'
),
delayed
=
$message
.
find
(
'
delay
'
).
length
>
0
,
$forwarded
=
$message
.
find
(
'
forwarded
'
),
$delay
;
if
(
$forwarded
.
length
)
{
$message
=
$forwarded
.
children
(
'
message
'
);
$delay
=
$forwarded
.
children
(
'
delay
'
);
delayed
=
$delay
.
length
>
0
;
}
var
body
=
$message
.
children
(
'
body
'
).
text
(),
jid
=
$message
.
attr
(
'
from
'
),
jid
=
$message
.
attr
(
'
from
'
),
msgid
=
$message
.
attr
(
'
id
'
),
msgid
=
$message
.
attr
(
'
id
'
),
resource
=
Strophe
.
getResourceFromJid
(
jid
),
resource
=
Strophe
.
getResourceFromJid
(
jid
),
sender
=
resource
&&
Strophe
.
unescapeNode
(
resource
)
||
''
,
sender
=
resource
&&
Strophe
.
unescapeNode
(
resource
)
||
''
,
delayed
=
$message
.
find
(
'
delay
'
).
length
>
0
,
subject
=
$message
.
children
(
'
subject
'
).
text
();
subject
=
$message
.
children
(
'
subject
'
).
text
();
if
(
msgid
&&
this
.
model
.
messages
.
findWhere
({
msgid
:
msgid
}))
{
if
(
msgid
&&
this
.
model
.
messages
.
findWhere
({
msgid
:
msgid
}))
{
...
@@ -3396,7 +3377,7 @@
...
@@ -3396,7 +3377,7 @@
if
(
sender
===
''
)
{
if
(
sender
===
''
)
{
return
true
;
return
true
;
}
}
this
.
model
.
createMessage
(
$message
);
this
.
model
.
createMessage
(
$message
,
$delay
,
archive_id
);
if
(
!
delayed
&&
sender
!==
this
.
model
.
get
(
'
nick
'
)
&&
(
new
RegExp
(
"
\\
b
"
+
this
.
model
.
get
(
'
nick
'
)
+
"
\\
b
"
)).
test
(
body
))
{
if
(
!
delayed
&&
sender
!==
this
.
model
.
get
(
'
nick
'
)
&&
(
new
RegExp
(
"
\\
b
"
+
this
.
model
.
get
(
'
nick
'
)
+
"
\\
b
"
)).
test
(
body
))
{
converse
.
playNotification
();
converse
.
playNotification
();
}
}
...
@@ -6325,7 +6306,7 @@
...
@@ -6325,7 +6306,7 @@
* can be called before passing it in again to this method, to
* can be called before passing it in again to this method, to
* get the next or previous page in the result set.
* get the next or previous page in the result set.
*/
*/
var
date
;
var
date
,
messages
=
[]
;
if
(
typeof
options
==
"
function
"
)
{
if
(
typeof
options
==
"
function
"
)
{
callback
=
options
;
callback
=
options
;
errback
=
callback
;
errback
=
callback
;
...
@@ -6334,7 +6315,6 @@
...
@@ -6334,7 +6315,6 @@
throw
new
Error
(
'
This server does not support XEP-0313, Message Archive Management
'
);
throw
new
Error
(
'
This server does not support XEP-0313, Message Archive Management
'
);
}
}
var
queryid
=
converse
.
connection
.
getUniqueId
();
var
queryid
=
converse
.
connection
.
getUniqueId
();
var
attrs
=
{
'
type
'
:
'
set
'
};
var
attrs
=
{
'
type
'
:
'
set
'
};
if
(
typeof
options
!=
"
undefined
"
&&
options
.
groupchat
)
{
if
(
typeof
options
!=
"
undefined
"
&&
options
.
groupchat
)
{
if
(
!
options
[
'
with
'
])
{
if
(
!
options
[
'
with
'
])
{
...
@@ -6362,16 +6342,31 @@
...
@@ -6362,16 +6342,31 @@
}
}
});
});
stanza
.
up
();
stanza
.
up
();
if
(
options
instanceof
Strophe
.
RSM
)
{
if
(
options
instanceof
Strophe
.
RSM
)
{
stanza
.
cnode
(
options
.
toXML
());
stanza
.
cnode
(
options
.
toXML
());
}
else
if
(
_
.
intersection
(
RSM_ATTRIBUTES
,
_
.
keys
(
options
)).
length
)
{
}
else
if
(
_
.
intersection
(
RSM_ATTRIBUTES
,
_
.
keys
(
options
)).
length
)
{
stanza
.
cnode
(
new
Strophe
.
RSM
(
options
).
toXML
());
stanza
.
cnode
(
new
Strophe
.
RSM
(
options
).
toXML
());
}
}
}
}
converse
.
connection
.
sendIQ
(
stanza
,
converse
.
connection
.
addHandler
(
function
(
message
)
{
_
.
partial
(
converse
.
onMAMQueryResult
,
_
,
options
,
queryid
,
callback
),
var
$msg
=
$
(
message
),
$fin
,
rsm
,
i
;
errback
);
if
(
typeof
callback
==
"
function
"
)
{
$fin
=
$msg
.
find
(
'
fin[xmlns="
'
+
Strophe
.
NS
.
MAM
+
'
"]
'
);
if
(
$fin
.
length
)
{
rsm
=
new
Strophe
.
RSM
({
xml
:
$fin
.
find
(
'
set
'
)[
0
]});
_
.
extend
(
rsm
,
_
.
pick
(
options
,
[
'
max
'
]));
_
.
extend
(
rsm
,
_
.
pick
(
options
,
MAM_ATTRIBUTES
));
callback
(
messages
,
rsm
);
return
false
;
// We've received all messages, decommission this handler
}
else
if
(
queryid
==
$msg
.
find
(
'
result
'
).
attr
(
'
queryid
'
))
{
messages
.
push
(
message
);
}
return
true
;
}
else
{
return
false
;
// There's no callback, so no use in continuing this handler.
}
},
Strophe
.
NS
.
MAM
);
converse
.
connection
.
sendIQ
(
stanza
,
null
,
errback
);
}
}
},
},
'
rooms
'
:
{
'
rooms
'
:
{
...
...
spec/mam.js
View file @
5eea22f2
...
@@ -316,7 +316,6 @@
...
@@ -316,7 +316,6 @@
sent_stanza
=
iq
;
sent_stanza
=
iq
;
IQ_id
=
sendIQ
.
bind
(
this
)(
iq
,
callback
,
errback
);
IQ_id
=
sendIQ
.
bind
(
this
)(
iq
,
callback
,
errback
);
});
});
spyOn
(
converse
,
'
onMAMQueryResult
'
).
andCallThrough
();
var
callback
=
jasmine
.
createSpy
(
'
callback
'
);
var
callback
=
jasmine
.
createSpy
(
'
callback
'
);
converse_api
.
archive
.
query
({
'
with
'
:
'
romeo@capulet.lit
'
,
'
max
'
:
'
10
'
},
callback
);
converse_api
.
archive
.
query
({
'
with
'
:
'
romeo@capulet.lit
'
,
'
max
'
:
'
10
'
},
callback
);
...
@@ -325,7 +324,6 @@
...
@@ -325,7 +324,6 @@
// Send the result stanza, so that the callback is called.
// Send the result stanza, so that the callback is called.
var
stanza
=
$iq
({
'
type
'
:
'
result
'
,
'
id
'
:
IQ_id
});
var
stanza
=
$iq
({
'
type
'
:
'
result
'
,
'
id
'
:
IQ_id
});
converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
expect
(
converse
.
onMAMQueryResult
).
toHaveBeenCalled
();
/* <message id='aeb213' to='juliet@capulet.lit/chamber'>
/* <message id='aeb213' to='juliet@capulet.lit/chamber'>
* <result xmlns='urn:xmpp:mam:0' queryid='f27' id='28482-98726-73623'>
* <result xmlns='urn:xmpp:mam:0' queryid='f27' id='28482-98726-73623'>
...
...
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