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
bbf33a8e
Commit
bbf33a8e
authored
May 07, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Combine duplicate `queryForArchivedMessages` methods
parent
dbee62c7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
77 deletions
+41
-77
src/converse-mam.js
src/converse-mam.js
+41
-77
No files found.
src/converse-mam.js
View file @
bbf33a8e
...
...
@@ -197,36 +197,34 @@
},
fetchArchivedMessages
(
options
)
{
/* Fetch archived chat messages from the XMPP server.
*
* Then, upon receiving them, call onMessage on the chat
* box, so that they are displayed inside it.
*/
const
{
_converse
}
=
this
.
__super__
;
if
(
!
_converse
.
disco_entities
.
get
(
_converse
.
bare_jid
)
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
if
(
this
.
disable_mam
)
{
return
;
}
_converse
.
log
(
"
Attempted to fetch archived messages but this
"
+
"
user's server doesn't support XEP-0313
"
,
Strophe
.
LogLevel
.
WARN
);
return
;
}
if
(
this
.
disable_mam
)
{
return
;
const
is_groupchat
=
this
.
model
.
get
(
'
type
'
)
===
CHATROOMS_TYPE
;
let
mam_jid
,
message_handler
;
if
(
is_groupchat
)
{
mam_jid
=
this
.
model
.
get
(
'
jid
'
);
message_handler
=
this
.
model
.
onMessage
.
bind
(
this
.
model
);
}
else
{
mam_jid
=
_converse
.
bare_jid
;
message_handler
=
_converse
.
chatboxes
.
onMessage
.
bind
(
_converse
.
chatboxes
)
}
_converse
.
api
.
disco
.
supports
(
Strophe
.
NS
.
MAM
,
mam_jid
).
then
(
(
results
)
=>
{
// Success
if
(
!
results
.
length
)
{
return
;
}
this
.
addSpinner
();
_converse
.
api
.
archive
.
query
(
_
.
extend
({
'
groupchat
'
:
is_groupchat
,
'
before
'
:
''
,
// Page backwards from the most recent message
'
max
'
:
_converse
.
archived_messages_page_size
,
'
with
'
:
this
.
model
.
get
(
'
jid
'
),
},
options
),
(
messages
)
=>
{
// Success
this
.
clearSpinner
();
if
(
messages
.
length
)
{
_
.
each
(
messages
,
_converse
.
chatboxes
.
onMessage
.
bind
(
_converse
.
chatboxes
));
}
_
.
each
(
messages
,
message_handler
);
},
()
=>
{
// Error
this
.
clearSpinner
();
...
...
@@ -236,6 +234,17 @@
}
);
},
()
=>
{
// Error
_converse
.
log
(
"
Error or timeout while checking for MAM support
"
,
Strophe
.
LogLevel
.
ERROR
);
}
).
catch
((
msg
)
=>
{
this
.
clearSpinner
();
_converse
.
log
(
msg
,
Strophe
.
LogLevel
.
FATAL
);
});
},
onScroll
(
ev
)
{
const
{
_converse
}
=
this
.
__super__
;
...
...
@@ -295,52 +304,7 @@
}
this
.
fetchArchivedMessages
();
this
.
model
.
save
({
'
mam_initialized
'
:
true
});
},
fetchArchivedMessages
(
options
)
{
/* Fetch archived chat messages for this Chat Room
*
* Then, upon receiving them, call onMessage
* so that they are displayed inside it.
*/
const
{
_converse
}
=
this
.
__super__
,
mam_jid
=
this
.
model
.
get
(
'
type
'
)
===
CHATROOMS_TYPE
?
this
.
model
.
get
(
'
jid
'
)
:
_converse
.
bare_jid
;
_converse
.
api
.
disco
.
supports
(
Strophe
.
NS
.
MAM
,
mam_jid
).
then
(
(
results
)
=>
{
// Success
if
(
!
results
.
length
)
{
return
;
}
this
.
addSpinner
();
_converse
.
api
.
archive
.
query
(
_
.
extend
({
'
groupchat
'
:
true
,
'
before
'
:
''
,
// Page backwards from the most recent message
'
with
'
:
this
.
model
.
get
(
'
jid
'
),
'
max
'
:
_converse
.
archived_messages_page_size
},
options
),
(
messages
)
=>
{
this
.
clearSpinner
();
if
(
messages
.
length
)
{
_
.
each
(
messages
,
this
.
model
.
onMessage
.
bind
(
this
.
model
));
}
},
()
=>
{
this
.
clearSpinner
();
_converse
.
log
(
"
Error while trying to fetch archived messages
"
,
Strophe
.
LogLevel
.
WARN
);
}
);
},
()
=>
{
// Error
_converse
.
log
(
"
Error or timeout while checking for MAM support
"
,
Strophe
.
LogLevel
.
ERROR
);
}
).
catch
((
msg
)
=>
{
this
.
clearSpinner
();
_converse
.
log
(
msg
,
Strophe
.
LogLevel
.
FATAL
);
});
}
},
...
...
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