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
46e54667
Commit
46e54667
authored
Jan 03, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify `insertDayIndicator` method
parent
cc29d169
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
354 additions
and
163 deletions
+354
-163
spec/chatbox.js
spec/chatbox.js
+138
-138
spec/chatroom.js
spec/chatroom.js
+197
-0
src/converse-chatview.js
src/converse-chatview.js
+19
-25
No files found.
spec/chatbox.js
View file @
46e54667
This diff is collapsed.
Click to expand it.
spec/chatroom.js
View file @
46e54667
This diff is collapsed.
Click to expand it.
src/converse-chatview.js
View file @
46e54667
...
...
@@ -382,21 +382,25 @@
);
},
insertDayIndicator
(
date
,
insert_method
)
{
/* Inserts an indicator
* into the chat area, showing the day as given by the
* passed in date.
insertDayIndicator
(
next_msg_el
)
{
/* Inserts an indicator into the chat area, showing the
* day as given by the passed in date.
*
* Parameters:
* (String) date - An ISO8601 date string.
* (Function) insert_method - The method to be used to
* insert the indicator
* (HTMLElement) next_msg_el - The message element before
* which the day indicator element must be inserted.
* This element must have a "data-isodate" attribute
* which specifies its creation date.
*/
const
day_date
=
moment
(
date
).
startOf
(
'
day
'
);
insert_method
(
tpl_new_day
({
isodate
:
day_date
.
format
(),
datestring
:
day_date
.
format
(
"
dddd MMM Do YYYY
"
)
}));
const
date
=
next_msg_el
.
getAttribute
(
'
data-isodate
'
),
day_date
=
moment
(
date
).
startOf
(
'
day
'
);
next_msg_el
.
insertAdjacentHTML
(
'
beforeBegin
'
,
tpl_new_day
({
'
isodate
'
:
day_date
.
format
(),
'
datestring
'
:
day_date
.
format
(
"
dddd MMM Do YYYY
"
)
})
);
},
getLastMessageElement
()
{
...
...
@@ -453,11 +457,6 @@
}
},
getDayIndicatorElement
(
date
)
{
return
this
.
content
.
querySelector
(
`.chat-date[data-isodate="
${
date
.
startOf
(
'
day
'
).
format
()}
"]`
);
},
showMessage
(
attrs
)
{
/* Inserts a chat message into the content area of the chat box.
* Will also insert a new day indicator if the message is on a
...
...
@@ -477,17 +476,12 @@
if
(
_
.
isNull
(
previous_msg_date
))
{
this
.
content
.
insertAdjacentElement
(
'
afterbegin
'
,
message_el
);
this
.
insertDayIndicator
(
current_msg_date
,
prepend_htm
l
);
this
.
insertDayIndicator
(
message_e
l
);
}
else
{
const
previous_msg_el
=
sizzle
(
`[data-isodate="
${
previous_msg_date
}
"]:last`
,
this
.
content
).
pop
();
previous_msg_el
.
insertAdjacentElement
(
'
afterend
'
,
message_el
);
const
day_el
=
this
.
getDayIndicatorElement
(
current_msg_date
)
if
(
current_msg_date
.
isAfter
(
previous_msg_date
,
'
day
'
)
&&
_
.
isNull
(
day_el
))
{
this
.
insertDayIndicator
(
current_msg_date
,
_
.
bind
(
this
.
content
.
insertAdjacentHTML
,
previous_msg_el
,
'
afterend
'
)
);
if
(
current_msg_date
.
isAfter
(
previous_msg_date
,
'
day
'
))
{
this
.
insertDayIndicator
(
message_el
);
}
}
this
.
scrollDown
();
...
...
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