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
a0f1a5cf
Commit
a0f1a5cf
authored
May 16, 2019
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fetch chat messages in the model, not the view
parent
e7ceb22a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
30 deletions
+37
-30
spec/converse.js
spec/converse.js
+4
-4
src/converse-chatview.js
src/converse-chatview.js
+4
-21
src/converse-headline.js
src/converse-headline.js
+3
-1
src/converse-mam-views.js
src/converse-mam-views.js
+1
-1
src/converse-muc-views.js
src/converse-muc-views.js
+3
-2
src/headless/converse-chatboxes.js
src/headless/converse-chatboxes.js
+22
-1
No files found.
spec/converse.js
View file @
a0f1a5cf
...
...
@@ -307,8 +307,8 @@
expect
(
box
instanceof
Object
).
toBeTruthy
();
expect
(
box
.
get
(
'
box_id
'
)).
toBe
(
`box-
${
btoa
(
jid
)}
`
);
const
chatbox
view
=
_converse
.
chatboxviews
.
get
(
jid
);
expect
(
u
.
isVisible
(
chatboxview
.
el
)).
toBeTruthy
(
);
const
view
=
_converse
.
chatboxviews
.
get
(
jid
);
await
test_utils
.
waitUntil
(()
=>
u
.
isVisible
(
view
.
el
)
);
// Test for multiple JIDs
test_utils
.
openChatBoxFor
(
_converse
,
jid2
);
await
test_utils
.
waitUntil
(()
=>
_converse
.
chatboxes
.
length
==
2
);
...
...
@@ -339,8 +339,8 @@
_
.
keys
(
box
),
[
'
close
'
,
'
endOTR
'
,
'
focus
'
,
'
get
'
,
'
initiateOTR
'
,
'
is_chatroom
'
,
'
maximize
'
,
'
minimize
'
,
'
open
'
,
'
set
'
]
);
const
chatbox
view
=
_converse
.
chatboxviews
.
get
(
jid
);
expect
(
u
.
isVisible
(
chatboxview
.
el
)).
toBeTruthy
(
);
const
view
=
_converse
.
chatboxviews
.
get
(
jid
);
await
test_utils
.
waitUntil
(()
=>
u
.
isVisible
(
view
.
el
)
);
// Test for multiple JIDs
const
list
=
await
_converse
.
api
.
chats
.
open
([
jid
,
jid2
]);
expect
(
Array
.
isArray
(
list
)).
toBeTruthy
();
...
...
src/converse-chatview.js
View file @
a0f1a5cf
...
...
@@ -337,7 +337,6 @@ converse.plugins.add('converse-chatview', {
initialize
()
{
this
.
initDebounced
();
this
.
model
.
messages
.
on
(
'
add
'
,
this
.
onMessageAdded
,
this
);
this
.
model
.
messages
.
on
(
'
rendered
'
,
this
.
scrollDown
,
this
);
...
...
@@ -347,8 +346,7 @@ converse.plugins.add('converse-chatview', {
this
.
model
.
presence
.
on
(
'
change:show
'
,
this
.
onPresenceChanged
,
this
);
this
.
model
.
on
(
'
showHelpMessages
'
,
this
.
showHelpMessages
,
this
);
this
.
render
();
this
.
fetchMessages
();
this
.
updateAfterMessagesFetched
();
/**
* Triggered once the _converse.ChatBoxView has been initialized
* @event _converse#chatBoxInitialized
...
...
@@ -530,27 +528,12 @@ converse.plugins.add('converse-chatview', {
});
},
afterMessagesFetched
()
{
async
updateAfterMessagesFetched
()
{
await
this
.
model
.
messages
.
fetched
;
await
Promise
.
all
(
this
.
model
.
messages
.
map
(
m
=>
this
.
onMessageAdded
(
m
)));
this
.
insertIntoDOM
();
this
.
scrollDown
();
this
.
content
.
addEventListener
(
'
scroll
'
,
this
.
markScrolled
.
bind
(
this
));
/**
* Triggered whenever a `_converse.ChatBox` instance has fetched its messages from
* `sessionStorage` but **NOT** from the server.
* @event _converse#afterMessagesFetched
* @type {_converse.ChatBoxView | _converse.ChatRoomView}
* @example _converse.api.listen.on('afterMessagesFetched', view => { ... });
*/
_converse
.
api
.
trigger
(
'
afterMessagesFetched
'
,
this
);
},
fetchMessages
()
{
this
.
model
.
messages
.
fetch
({
'
add
'
:
true
,
'
success
'
:
this
.
afterMessagesFetched
.
bind
(
this
),
'
error
'
:
this
.
afterMessagesFetched
.
bind
(
this
),
});
return
this
;
},
insertIntoDOM
()
{
...
...
src/converse-headline.js
View file @
a0f1a5cf
...
...
@@ -88,7 +88,9 @@ converse.plugins.add('converse-headline', {
this
.
model
.
on
(
'
destroy
'
,
this
.
hide
,
this
);
this
.
model
.
on
(
'
change:minimized
'
,
this
.
onMinimizedChanged
,
this
);
this
.
render
().
insertHeading
().
fetchMessages
().
insertIntoDOM
().
hide
();
this
.
render
().
insertHeading
()
this
.
updateAfterMessagesFetched
();
this
.
insertIntoDOM
().
hide
();
_converse
.
api
.
trigger
(
'
chatBoxInitialized
'
,
this
);
},
...
...
src/converse-mam-views.js
View file @
a0f1a5cf
...
...
@@ -153,7 +153,7 @@ converse.plugins.add('converse-mam-views', {
const
{
_converse
}
=
this
;
/* Event handlers */
_converse
.
api
.
listen
.
on
(
'
afterMessagesFetched
'
,
view
=>
view
.
model
.
fetchNewestMessages
());
_converse
.
api
.
listen
.
on
(
'
afterMessagesFetched
'
,
chatbox
=>
chatbox
.
fetchNewestMessages
());
_converse
.
api
.
listen
.
on
(
'
reconnected
'
,
()
=>
{
const
private_chats
=
_converse
.
chatboxviews
.
filter
(
...
...
src/converse-muc-views.js
View file @
a0f1a5cf
...
...
@@ -564,6 +564,7 @@ converse.plugins.add('converse-muc-views', {
this
.
createEmojiPicker
();
this
.
render
();
this
.
updateAfterMessagesFetched
();
this
.
createOccupantsView
();
this
.
insertIntoDOM
();
this
.
registerHandlers
();
...
...
@@ -581,7 +582,7 @@ converse.plugins.add('converse-muc-views', {
}
this
.
populateAndJoin
();
}
else
{
this
.
fetchMessages
();
this
.
model
.
fetchMessages
();
}
/**
* Triggered once a groupchat has been opened
...
...
@@ -1195,7 +1196,7 @@ converse.plugins.add('converse-muc-views', {
populateAndJoin
()
{
this
.
model
.
occupants
.
fetchMembers
();
this
.
join
();
this
.
fetchMessages
();
this
.
model
.
fetchMessages
();
},
/**
...
...
src/headless/converse-chatboxes.js
View file @
a0f1a5cf
...
...
@@ -272,7 +272,6 @@ converse.plugins.add('converse-chatboxes', {
// from being persisted if there's no jid, but that gets
// called after model instantiation, so we have to deal
// with invalid models here also.
//
// This happens when the controlbox is in browser storage,
// but we're in embedded mode.
return
;
...
...
@@ -288,6 +287,7 @@ converse.plugins.add('converse-chatboxes', {
}
this
.
on
(
'
change:chat_state
'
,
this
.
sendChatState
,
this
);
this
.
initMessages
();
this
.
fetchMessages
();
},
initMessages
()
{
...
...
@@ -304,6 +304,27 @@ converse.plugins.add('converse-chatboxes', {
});
},
afterMessagesFetched
()
{
/**
* Triggered whenever a `_converse.ChatBox` instance has fetched its messages from
* `sessionStorage` but **NOT** from the server.
* @event _converse#afterMessagesFetched
* @type {_converse.ChatBox | _converse.ChatRoom}
* @example _converse.api.listen.on('afterMessagesFetched', view => { ... });
*/
_converse
.
api
.
trigger
(
'
afterMessagesFetched
'
,
this
);
},
fetchMessages
()
{
this
.
messages
.
fetched
=
new
Promise
(
resolve
=>
{
this
.
messages
.
fetch
({
'
add
'
:
true
,
'
success
'
:
_
.
flow
(
this
.
afterMessagesFetched
.
bind
(
this
),
resolve
),
'
error
'
:
_
.
flow
(
this
.
afterMessagesFetched
.
bind
(
this
),
resolve
)
});
});
},
validate
(
attrs
,
options
)
{
const
{
_converse
}
=
this
.
__super__
;
if
(
!
attrs
.
jid
)
{
...
...
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