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
Hide 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,44 +197,53 @@
...
@@ -197,44 +197,53 @@
},
},
fetchArchivedMessages
(
options
)
{
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__
;
const
{
_converse
}
=
this
.
__super__
;
if
(
!
_converse
.
disco_entities
.
get
(
_converse
.
bare_jid
)
if
(
this
.
disable_mam
)
{
return
;
}
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
MAM
}))
{
_converse
.
log
(
const
is_groupchat
=
this
.
model
.
get
(
'
type
'
)
===
CHATROOMS_TYPE
;
"
Attempted to fetch archived messages but this
"
+
"
user's server doesn't support XEP-0313
"
,
let
mam_jid
,
message_handler
;
Strophe
.
LogLevel
.
WARN
);
if
(
is_groupchat
)
{
return
;
mam_jid
=
this
.
model
.
get
(
'
jid
'
);
}
message_handler
=
this
.
model
.
onMessage
.
bind
(
this
.
model
);
if
(
this
.
disable_mam
)
{
}
else
{
return
;
mam_jid
=
_converse
.
bare_jid
;
message_handler
=
_converse
.
chatboxes
.
onMessage
.
bind
(
_converse
.
chatboxes
)
}
}
this
.
addSpinner
();
_converse
.
api
.
archive
.
query
(
_converse
.
api
.
disco
.
supports
(
Strophe
.
NS
.
MAM
,
mam_jid
).
then
(
_
.
extend
({
(
results
)
=>
{
// Success
'
before
'
:
''
,
// Page backwards from the most recent message
if
(
!
results
.
length
)
{
return
;
}
'
max
'
:
_converse
.
archived_messages_page_size
,
this
.
addSpinner
();
'
with
'
:
this
.
model
.
get
(
'
jid
'
),
_converse
.
api
.
archive
.
query
(
},
options
),
_
.
extend
({
(
messages
)
=>
{
// Success
'
groupchat
'
:
is_groupchat
,
this
.
clearSpinner
();
'
before
'
:
''
,
// Page backwards from the most recent message
if
(
messages
.
length
)
{
'
max
'
:
_converse
.
archived_messages_page_size
,
_
.
each
(
messages
,
_converse
.
chatboxes
.
onMessage
.
bind
(
_converse
.
chatboxes
));
'
with
'
:
this
.
model
.
get
(
'
jid
'
),
}
},
options
),
(
messages
)
=>
{
// Success
this
.
clearSpinner
();
_
.
each
(
messages
,
message_handler
);
},
()
=>
{
// Error
this
.
clearSpinner
();
_converse
.
log
(
"
Error or timeout while trying to fetch
"
+
"
archived messages
"
,
Strophe
.
LogLevel
.
ERROR
);
}
);
},
},
()
=>
{
// Error
()
=>
{
// Error
this
.
clearSpinner
();
_converse
.
log
(
_converse
.
log
(
"
Error or timeout while trying to fetch
"
+
"
Error or timeout while checking for MAM support
"
,
"
archived messages
"
,
Strophe
.
LogLevel
.
ERROR
);
Strophe
.
LogLevel
.
ERROR
);
}
}
);
).
catch
((
msg
)
=>
{
this
.
clearSpinner
();
_converse
.
log
(
msg
,
Strophe
.
LogLevel
.
FATAL
);
});
},
},
onScroll
(
ev
)
{
onScroll
(
ev
)
{
...
@@ -295,52 +304,7 @@
...
@@ -295,52 +304,7 @@
}
}
this
.
fetchArchivedMessages
();
this
.
fetchArchivedMessages
();
this
.
model
.
save
({
'
mam_initialized
'
:
true
});
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