-
Notifications
You must be signed in to change notification settings - Fork 442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a relative prefix to the date divider in the chat #591
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides the code comments, the relative dates should be automatically updated when changing to a new day.
if (this._lastAddedMessageModel && !this._modelsHaveSameDate(this._lastAddedMessageModel, model)) { | ||
// 'LL' formats a localized date including day of month, month | ||
// name and year | ||
if (!this._lastAddedMessageModel || !this._modelsHaveSameDate(this._lastAddedMessageModel, model)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be sure, the condition was changed to make the date divider appear before the first message, right?
js/views/chatview.js
Outdated
if (this._oldestOnTopLayout) { | ||
$el.attr('data-date', OC.Util.formatDate(model.get('date'), 'LL')); | ||
$el.attr('data-date', this._getDateSeparator(model.get('date'))); | ||
$el.addClass('showDate'); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to the change in the outer if condition it must be checked here that there is a this._lastAddedMessageModel
(otherwise the line below would fail).
js/views/chatview.js
Outdated
} | ||
|
||
|
||
return relativePrefix + ', ' + OC.Util.formatDate(timestamp, 'LL'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole text should be internationalized, as depending on the locale a different separator (or even order of the prefix and date) could be needed.
Also please add a comment like 'LL' formats a localized date including day of month, month name and year to know what it does ;-)
js/views/chatview.js
Outdated
var date = moment(timestamp, 'x'), | ||
today = moment(), | ||
dayOfYear = OC.Util.formatDate(date, 'YYYY-DDD'), | ||
dateOfToday = OC.Util.formatDate(today, 'YYYY-DDD'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dateOfToday
-> currentDayOfYear
/dayOfYearNow
/dayOfYearToday
/whatever including dayOfYear
;-)
@@ -242,6 +240,29 @@ | |||
} | |||
}, | |||
|
|||
_getDateSeparator: function(timestamp) { | |||
var date = moment(timestamp, 'x'), | |||
today = moment(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be better to call it now
instead of today
? Not really sure which one would be clearer, though.
Looks nice! :) I think the relative dates of even the multiple months ago are useful when you scroll back. @nickvergessen so now that the date display on the right of each message duplicates the divider info, can we just show the timestamp of the specific message there on the right? Then that part also has a shorter and predictable width. |
Signed-off-by: Joas Schilling <coding@schilljs.com>
When using the oldest to newest layout now the first (oldest) message always shows the date. When using the newest to oldest layout, however, there is no date shown in the first (newest) message; in this case it would be good to show it only if the newest message was not sent today, but the newest to oldest layout is currently not used anywhere (and it is likely to be removed from the code), so there was no need to spend time on that. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
46e43c6
to
af8e1aa
Compare
I have rewritten a little the commit history to fix a lint issue, add the review changes to the original commit and split adding the relative prefix from showing the date in the first message. However, there are still some issues. Although the relative date is not set initially due to the use of the
Not sure about the date; it may be too much visually, and if you need to find the date you can hover on the time... or, in touch screens, scroll back until you find the date header. That could be quite annoying, though, so I do not know. In any case I would add back the seconds, at the very least to the tooltip and maybe to the text itself too, as otherwise it would not be possible to know them in touch screens.
I am not aware of any CSS-only way to pin the last divider and, although it could be a cool effect, for the time being I would not add it to keep the code simple (there are enough bugs to fix already ;-) ). |
Fixed the issue with
Done
Yeah, that's why I asked for some simple CSS, lets just keep it like that for now then. |
Signed-off-by: Joas Schilling <coding@schilljs.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocking to prevent a merge, as dates in the headers are not updated yet when the day changes.
What do you mean? |
Merging as discussed |
Close the datepicker on unfocus
@jancborchardt it's not exactly the steps you mentioned, but instead its automatically done by momentjs.
I think it's good enough, but since "a month ago" is repeating with each day in the past, I'd also be fine with only showing relative until it's no longer displayed as "days ago".
No one needs relative dates for "7 months ago".
Fix #559