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
c038794f
Commit
c038794f
authored
Aug 03, 2019
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
converse-mam: Light refactoring and cleanup
parent
c2db6673
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
39 deletions
+30
-39
src/headless/converse-mam.js
src/headless/converse-mam.js
+30
-39
No files found.
src/headless/converse-mam.js
View file @
c038794f
...
...
@@ -11,10 +11,11 @@
*/
import
"
./converse-disco
"
;
import
"
./converse-rsm
"
;
import
{
intersection
,
pick
}
from
'
lodash
'
import
converse
from
"
./converse-core
"
;
import
sizzle
from
"
sizzle
"
;
const
{
Strophe
,
$iq
,
$build
,
_
,
dayjs
}
=
converse
.
env
;
const
{
Strophe
,
$iq
,
$build
,
dayjs
}
=
converse
.
env
;
const
u
=
converse
.
env
.
utils
;
// XEP-0313 Message Archive Management
...
...
@@ -64,16 +65,17 @@ converse.plugins.add('converse-mam', {
const
MAMEnabledChat
=
{
fetchNewestMessages
()
{
/
* Fetches messages that might have been archived *after*
/**
* Fetches messages that might have been archived *after*
* the last archived message in our local cache.
*/
fetchNewestMessages
()
{
if
(
this
.
disable_mam
)
{
return
;
}
const
most_recent_msg
=
u
.
getMostRecentMessage
(
this
);
if
(
_
.
isNil
(
most_recent_msg
)
)
{
if
(
!
most_recent_msg
)
{
this
.
fetchArchivedMessages
();
}
else
{
const
stanza_id
=
most_recent_msg
.
get
(
`stanza_id
${
this
.
get
(
'
jid
'
)}
`
);
...
...
@@ -100,24 +102,14 @@ converse.plugins.add('converse-mam', {
}
else
{
message_handler
=
_converse
.
chatboxes
.
onMessage
.
bind
(
_converse
.
chatboxes
)
}
let
result
=
{};
try
{
result
=
await
_converse
.
api
.
archive
.
query
(
const
result
=
await
_converse
.
api
.
archive
.
query
(
Object
.
assign
({
'
groupchat
'
:
is_groupchat
,
'
before
'
:
''
,
// Page backwards from the most recent message
'
max
'
:
_converse
.
archived_messages_page_size
,
'
with
'
:
this
.
get
(
'
jid
'
),
},
options
));
}
catch
(
e
)
{
_converse
.
log
(
"
Error or timeout while trying to fetch
"
+
"
archived messages
"
,
Strophe
.
LogLevel
.
ERROR
);
_converse
.
log
(
e
,
Strophe
.
LogLevel
.
ERROR
);
}
if
(
result
.
messages
)
{
result
.
messages
.
forEach
(
message_handler
);
}
},
async
findDuplicateFromArchiveID
(
stanza
)
{
...
...
@@ -165,7 +157,7 @@ converse.plugins.add('converse-mam', {
}
};
_converse
.
onMAMPreferences
=
function
(
feature
,
iq
)
{
_converse
.
onMAMPreferences
=
function
(
iq
,
feature
)
{
/* Handle returned IQ stanza containing Message Archive
* Management (XEP-0313) preferences.
*
...
...
@@ -184,7 +176,7 @@ converse.plugins.add('converse-mam', {
'
xmlns
'
:
Strophe
.
NS
.
MAM
,
'
default
'
:
_converse
.
message_archiving
});
_
.
each
(
preference
.
children
,
child
=>
stanza
.
cnode
(
child
).
up
());
Array
.
from
(
preference
.
children
).
forEach
(
child
=>
stanza
.
cnode
(
child
).
up
());
// XXX: Strictly speaking, the server should respond with the updated prefs
// (see example 18: https://xmpp.org/extensions/xep-0313.html#config)
...
...
@@ -205,7 +197,7 @@ converse.plugins.add('converse-mam', {
}
if
(
prefs
[
'
default
'
]
!==
_converse
.
message_archiving
)
{
_converse
.
api
.
sendIQ
(
$iq
({
'
type
'
:
'
get
'
}).
c
(
'
prefs
'
,
{
'
xmlns
'
:
Strophe
.
NS
.
MAM
}))
.
then
(
_
.
partial
(
_converse
.
onMAMPreferences
,
feature
))
.
then
(
iq
=>
_converse
.
onMAMPreferences
(
iq
,
feature
))
.
catch
(
_converse
.
onMAMError
);
}
}
...
...
@@ -418,7 +410,7 @@ converse.plugins.add('converse-mam', {
* result.messages.forEach(m => this.showMessage(m));
*
*/
'
query
'
:
async
function
(
options
)
{
async
query
(
options
)
{
if
(
!
_converse
.
api
.
connection
.
connected
())
{
throw
new
Error
(
'
Can
\'
t call `api.archive.query` before having established an XMPP session
'
);
}
...
...
@@ -474,30 +466,29 @@ converse.plugins.add('converse-mam', {
return
true
;
}
const
result
=
message
.
querySelector
(
'
result
'
);
if
(
!
_
.
isNull
(
result
)
&&
result
.
getAttribute
(
'
queryid
'
)
===
queryid
)
{
if
(
result
!==
null
&&
result
.
getAttribute
(
'
queryid
'
)
===
queryid
)
{
messages
.
push
(
message
);
}
return
true
;
},
Strophe
.
NS
.
MAM
);
let
iq
;
let
iq
_result
,
rsm
;
try
{
iq
=
await
_converse
.
api
.
sendIQ
(
stanza
,
_converse
.
message_archiving_timeout
)
iq
_result
=
await
_converse
.
api
.
sendIQ
(
stanza
,
_converse
.
message_archiving_timeout
)
}
catch
(
e
)
{
_converse
.
connection
.
deleteHandler
(
message_handler
);
throw
(
e
);
_converse
.
log
(
"
Error or timeout while trying to fetch
"
+
"
archived messages
"
,
Strophe
.
LogLevel
.
ERROR
);
_converse
.
log
(
e
,
Strophe
.
LogLevel
.
ERROR
);
}
_converse
.
connection
.
deleteHandler
(
message_handler
);
const
set
=
iq
.
querySelector
(
'
set
'
);
let
rsm
;
if
(
!
_
.
isNull
(
set
)
)
{
const
set
=
iq_result
?
iq_result
.
querySelector
(
'
set
'
)
:
null
;
if
(
set
!==
null
)
{
rsm
=
new
_converse
.
RSM
({
'
xml
'
:
set
});
Object
.
assign
(
rsm
,
_
.
pick
(
options
,
_
.
concat
(
MAM_ATTRIBUTES
,
[
'
max
'
])));
}
return
{
messages
,
rsm
}
return
{
messages
,
rsm
}
}
}
});
...
...
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