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
e8fba4a7
Commit
e8fba4a7
authored
Jul 19, 2015
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored showNewDay to indicate day changes between messages.
updates #306
parent
06a6d6c4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
25 deletions
+37
-25
converse.js
converse.js
+35
-23
spec/chatbox.js
spec/chatbox.js
+1
-1
src/templates/new_day.html
src/templates/new_day.html
+1
-1
No files found.
converse.js
View file @
e8fba4a7
...
@@ -1387,7 +1387,7 @@
...
@@ -1387,7 +1387,7 @@
clearSpinner
:
function
()
{
clearSpinner
:
function
()
{
if
(
this
.
$content
.
children
(
'
:first
'
).
is
(
'
span.spinner
'
))
{
if
(
this
.
$content
.
children
(
'
:first
'
).
is
(
'
span.spinner
'
))
{
this
.
$content
.
children
(
'
:first
'
).
first
().
remove
();
this
.
$content
.
children
(
'
:first
'
).
remove
();
}
}
},
},
...
@@ -1401,11 +1401,9 @@
...
@@ -1401,11 +1401,9 @@
has_scrollbar
=
this
.
$content
.
get
(
0
).
scrollHeight
>
this
.
$content
[
0
].
clientHeight
,
has_scrollbar
=
this
.
$content
.
get
(
0
).
scrollHeight
>
this
.
$content
[
0
].
clientHeight
,
template
,
username
,
insertMessage
;
template
,
username
,
insertMessage
;
// FIXME: A better approach here is probably to look at what is
// TODO: A better approach here is probably to look at what is
// already inside the content area, and from the determine if
// already inside the content area, and from that determine if
// the message must be prepended or appended.
// the message must be prepended or appended. Similar to showNewDay
// That way we could probably also better show day indicators.
// That code should perhaps go into onMessageAdded
if
(
num_messages
&&
msg_time
.
isBefore
(
this
.
model
.
messages
.
at
(
0
).
get
(
'
time
'
)))
{
if
(
num_messages
&&
msg_time
.
isBefore
(
this
.
model
.
messages
.
at
(
0
).
get
(
'
time
'
)))
{
insertMessage
=
_
.
compose
(
insertMessage
=
_
.
compose
(
this
.
scrollDownMessageHeight
.
bind
(
this
),
this
.
scrollDownMessageHeight
.
bind
(
this
),
...
@@ -1435,7 +1433,7 @@
...
@@ -1435,7 +1433,7 @@
var
message
=
template
({
var
message
=
template
({
'
sender
'
:
msg_dict
.
sender
,
'
sender
'
:
msg_dict
.
sender
,
'
time
'
:
msg_time
.
format
(
'
hh:mm
'
),
'
time
'
:
msg_time
.
format
(
'
hh:mm
'
),
'
isodate
'
:
msg_time
,
'
isodate
'
:
msg_time
.
format
()
,
'
username
'
:
username
,
'
username
'
:
username
,
'
message
'
:
''
,
'
message
'
:
''
,
'
extra_classes
'
:
extra_classes
'
extra_classes
'
:
extra_classes
...
@@ -1462,21 +1460,35 @@
...
@@ -1462,21 +1460,35 @@
},
},
showNewDay
:
function
(
message
)
{
showNewDay
:
function
(
message
)
{
/* If this message is on a different day than the one received
/* Messages may be received chronologically, from old to new or
* prior, then indicate it on the chatbox.
* new to old.
*
* If this message is older than the oldest, or newer then the
* newest, we show a new day indication in the chat content
* area.
*
* Parameters:
* (XMLElement) message - The message stanza received from the XMPP server.
*/
*/
var
time
=
message
.
get
(
'
time
'
),
var
first_message_date
=
this
.
$content
.
children
(
'
:first
'
).
data
(
'
isodate
'
);
idx
=
_
.
indexOf
(
this
.
model
.
messages
.
pluck
(
'
time
'
),
time
)
-
1
,
if
(
typeof
(
first_message_date
)
==
"
undefined
"
)
{
this_date
,
prev_date
;
return
message
;
if
(
idx
>=
0
)
{
}
prev_date
=
moment
(
this
.
model
.
messages
.
at
(
idx
).
get
(
'
time
'
));
var
last_message_date
=
this
.
$content
.
children
(
'
:last
'
).
data
(
'
isodate
'
);
if
(
prev_date
.
isBefore
(
time
,
'
day
'
))
{
var
this_date
=
moment
(
message
.
get
(
'
time
'
));
this_date
=
moment
(
time
);
var
day_date
;
this
.
$content
.
append
(
converse
.
templates
.
new_day
({
if
(
this_date
.
isBefore
(
first_message_date
,
'
day
'
))
{
isodate
:
this_date
.
format
(
"
YYYY-MM-DD
"
),
day_date
=
moment
(
first_message_date
).
startOf
(
'
day
'
);
datestring
:
this_date
.
format
(
"
dddd MMM Do YYYY
"
)
this
.
$content
.
prepend
(
converse
.
templates
.
new_day
({
}));
isodate
:
day_date
.
format
(),
}
datestring
:
day_date
.
format
(
"
dddd MMM Do YYYY
"
)
}));
}
else
if
(
this_date
.
isAfter
(
last_message_date
,
'
day
'
))
{
day_date
=
moment
(
this_date
).
startOf
(
'
day
'
);
this
.
$content
.
append
(
converse
.
templates
.
new_day
({
isodate
:
this_date
.
format
(),
datestring
:
this_date
.
format
(
"
dddd MMM Do YYYY
"
)
}));
}
}
return
message
;
return
message
;
},
},
...
@@ -1513,8 +1525,7 @@
...
@@ -1513,8 +1525,7 @@
* Parameters:
* Parameters:
* (string) text - The chat message text.
* (string) text - The chat message text.
*/
*/
// TODO: We might want to send to specfic resources. Especially
// TODO: We might want to send to specfic resources. Especially in the OTR case.
// in the OTR case.
var
timestamp
=
(
new
Date
()).
getTime
();
var
timestamp
=
(
new
Date
()).
getTime
();
var
bare_jid
=
this
.
model
.
get
(
'
jid
'
);
var
bare_jid
=
this
.
model
.
get
(
'
jid
'
);
var
message
=
$msg
({
from
:
converse
.
connection
.
jid
,
to
:
bare_jid
,
type
:
'
chat
'
,
id
:
timestamp
})
var
message
=
$msg
({
from
:
converse
.
connection
.
jid
,
to
:
bare_jid
,
type
:
'
chat
'
,
id
:
timestamp
})
...
@@ -4258,6 +4269,7 @@
...
@@ -4258,6 +4269,7 @@
onRosterPush
:
function
(
iq
)
{
onRosterPush
:
function
(
iq
)
{
/* Handle roster updates from the XMPP server.
/* Handle roster updates from the XMPP server.
* See: https://xmpp.org/rfcs/rfc6121.html#roster-syntax-actions-push
* See: https://xmpp.org/rfcs/rfc6121.html#roster-syntax-actions-push
*
* Parameters:
* Parameters:
* (XMLElement) IQ - The IQ stanza received from the XMPP server.
* (XMLElement) IQ - The IQ stanza received from the XMPP server.
*/
*/
...
...
spec/chatbox.js
View file @
e8fba4a7
...
@@ -652,7 +652,7 @@
...
@@ -652,7 +652,7 @@
var
message_date
=
new
Date
();
var
message_date
=
new
Date
();
expect
(
$time
.
length
).
toEqual
(
1
);
expect
(
$time
.
length
).
toEqual
(
1
);
expect
(
$time
.
attr
(
'
class
'
)).
toEqual
(
'
chat-date
'
);
expect
(
$time
.
attr
(
'
class
'
)).
toEqual
(
'
chat-date
'
);
expect
(
$time
.
attr
(
'
datetime
'
)).
toEqual
(
moment
(
message_date
).
format
(
"
YYYY-MM-DD
"
));
expect
(
$time
.
data
(
'
isodate
'
)).
toEqual
(
moment
(
message_date
).
format
(
));
expect
(
$time
.
text
()).
toEqual
(
moment
(
message_date
).
format
(
"
dddd MMM Do YYYY
"
));
expect
(
$time
.
text
()).
toEqual
(
moment
(
message_date
).
format
(
"
dddd MMM Do YYYY
"
));
// Normal checks for the 2nd message
// Normal checks for the 2nd message
...
...
src/templates/new_day.html
View file @
e8fba4a7
<time
class=
"chat-date"
dat
etim
e=
"{{isodate}}"
>
{{datestring}}
</time>
<time
class=
"chat-date"
dat
a-isodat
e=
"{{isodate}}"
>
{{datestring}}
</time>
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