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
16db6195
Commit
16db6195
authored
May 16, 2019
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move MAM methods to the model
parent
94bea16c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
38 deletions
+41
-38
src/converse-mam-views.js
src/converse-mam-views.js
+41
-38
No files found.
src/converse-mam-views.js
View file @
16db6195
...
...
@@ -25,16 +25,8 @@ converse.plugins.add('converse-mam-views', {
//
// New functions which don't exist yet can also be added.
ChatBoxView
:
{
render
()
{
const
result
=
this
.
__super__
.
render
.
apply
(
this
,
arguments
);
if
(
!
this
.
disable_mam
)
{
this
.
content
.
addEventListener
(
'
scroll
'
,
_
.
debounce
(
this
.
onScroll
.
bind
(
this
),
100
));
}
return
result
;
},
ChatBox
:
{
fetchNewestMessages
()
{
/* Fetches messages that might have been archived *after*
* the last archived message in our local cache.
...
...
@@ -43,12 +35,12 @@ converse.plugins.add('converse-mam-views', {
return
;
}
const
{
_converse
}
=
this
.
__super__
;
const
most_recent_msg
=
u
.
getMostRecentMessage
(
this
.
model
);
const
most_recent_msg
=
u
.
getMostRecentMessage
(
this
);
if
(
_
.
isNil
(
most_recent_msg
))
{
this
.
fetchArchivedMessages
();
}
else
{
const
stanza_id
=
most_recent_msg
.
get
(
`stanza_id
${
this
.
model
.
get
(
'
jid
'
)}
`
);
const
stanza_id
=
most_recent_msg
.
get
(
`stanza_id
${
this
.
get
(
'
jid
'
)}
`
);
if
(
stanza_id
)
{
this
.
fetchArchivedMessages
({
'
after
'
:
stanza_id
});
}
else
{
...
...
@@ -62,18 +54,17 @@ converse.plugins.add('converse-mam-views', {
return
;
}
const
{
_converse
}
=
this
.
__super__
;
const
is_groupchat
=
this
.
model
.
get
(
'
type
'
)
===
CHATROOMS_TYPE
;
const
mam_jid
=
is_groupchat
?
this
.
model
.
get
(
'
jid
'
)
:
_converse
.
bare_jid
;
const
is_groupchat
=
this
.
get
(
'
type
'
)
===
CHATROOMS_TYPE
;
const
mam_jid
=
is_groupchat
?
this
.
get
(
'
jid
'
)
:
_converse
.
bare_jid
;
if
(
!
(
await
_converse
.
api
.
disco
.
supports
(
Strophe
.
NS
.
MAM
,
mam_jid
)))
{
return
;
}
let
message_handler
;
if
(
is_groupchat
)
{
message_handler
=
this
.
model
.
onMessage
.
bind
(
this
.
model
);
message_handler
=
this
.
onMessage
.
bind
(
this
);
}
else
{
message_handler
=
_converse
.
chatboxes
.
onMessage
.
bind
(
_converse
.
chatboxes
)
}
this
.
addSpinner
();
let
result
;
try
{
result
=
await
_converse
.
api
.
archive
.
query
(
...
...
@@ -81,19 +72,28 @@ converse.plugins.add('converse-mam-views', {
'
groupchat
'
:
is_groupchat
,
'
before
'
:
''
,
// Page backwards from the most recent message
'
max
'
:
_converse
.
archived_messages_page_size
,
'
with
'
:
this
.
model
.
get
(
'
jid
'
),
'
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
);
}
finally
{
this
.
clearSpinner
();
}
if
(
result
.
messages
)
{
result
.
messages
.
forEach
(
message_handler
);
}
}
},
ChatBoxView
:
{
render
()
{
const
result
=
this
.
__super__
.
render
.
apply
(
this
,
arguments
);
if
(
!
this
.
disable_mam
)
{
this
.
content
.
addEventListener
(
'
scroll
'
,
_
.
debounce
(
this
.
onScroll
.
bind
(
this
),
100
));
}
return
result
;
},
onScroll
(
ev
)
{
...
...
@@ -103,42 +103,45 @@ converse.plugins.add('converse-mam-views', {
const
by_jid
=
this
.
model
.
get
(
'
jid
'
);
const
stanza_id
=
oldest_message
.
get
(
`stanza_id
${
by_jid
}
`
);
if
(
stanza_id
)
{
this
.
fetchArchivedMessages
({
'
before
'
:
stanza_id
});
this
.
model
.
fetchArchivedMessages
({
'
before
'
:
stanza_id
});
}
else
{
this
.
fetchArchivedMessages
({
this
.
model
.
fetchArchivedMessages
({
'
end
'
:
oldest_message
.
get
(
'
time
'
)
});
}
}
}
,
}
},
ChatRoom
View
:
{
ChatRoom
:
{
initialize
()
{
const
{
_converse
}
=
this
.
__super__
;
this
.
__super__
.
initialize
.
apply
(
this
,
arguments
);
this
.
model
.
on
(
'
change:mam_enabled
'
,
this
.
fetchArchivedMessagesIfNecessary
,
this
);
this
.
model
.
on
(
'
change:connection_status
'
,
this
.
fetchArchivedMessagesIfNecessary
,
this
);
this
.
on
(
'
change:mam_enabled
'
,
this
.
fetchArchivedMessagesIfNecessary
,
this
);
this
.
on
(
'
change:connection_status
'
,
this
.
fetchArchivedMessagesIfNecessary
,
this
);
},
fetchArchivedMessagesIfNecessary
()
{
if
(
this
.
get
(
'
connection_status
'
)
!==
converse
.
ROOMSTATUS
.
ENTERED
||
!
this
.
get
(
'
mam_enabled
'
)
||
this
.
get
(
'
mam_initialized
'
))
{
return
;
}
this
.
fetchArchivedMessages
();
this
.
save
({
'
mam_initialized
'
:
true
});
}
},
ChatRoomView
:
{
renderChatArea
()
{
const
result
=
this
.
__super__
.
renderChatArea
.
apply
(
this
,
arguments
);
if
(
!
this
.
disable_mam
)
{
this
.
content
.
addEventListener
(
'
scroll
'
,
_
.
debounce
(
this
.
onScroll
.
bind
(
this
),
100
));
}
return
result
;
},
fetchArchivedMessagesIfNecessary
()
{
if
(
this
.
model
.
get
(
'
connection_status
'
)
!==
converse
.
ROOMSTATUS
.
ENTERED
||
!
this
.
model
.
get
(
'
mam_enabled
'
)
||
this
.
model
.
get
(
'
mam_initialized
'
))
{
return
;
}
this
.
fetchArchivedMessages
();
this
.
model
.
save
({
'
mam_initialized
'
:
true
});
}
}
},
...
...
@@ -150,13 +153,13 @@ converse.plugins.add('converse-mam-views', {
const
{
_converse
}
=
this
;
/* Event handlers */
_converse
.
api
.
listen
.
on
(
'
afterMessagesFetched
'
,
view
=>
view
.
fetchNewestMessages
());
_converse
.
api
.
listen
.
on
(
'
afterMessagesFetched
'
,
view
=>
view
.
model
.
fetchNewestMessages
());
_converse
.
api
.
listen
.
on
(
'
reconnected
'
,
()
=>
{
const
private_chats
=
_converse
.
chatboxviews
.
filter
(
view
=>
_
.
at
(
view
,
'
model.attributes.type
'
)[
0
]
===
'
chatbox
'
);
_
.
each
(
private_chats
,
(
view
)
=>
view
.
fetchNewestMessages
())
_
.
each
(
private_chats
,
view
=>
view
.
model
.
fetchNewestMessages
())
});
}
});
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