Skip to content
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

Merged
merged 4 commits into from Jan 17, 2018

Conversation

nickvergessen
Copy link
Member

@nickvergessen nickvergessen commented Jan 15, 2018

@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".

ug-test_-gesprach-nextcloud-_2018-01-15_16 10 07

Fix #559

@nickvergessen nickvergessen added this to the 3.1 (Nextcloud 13.0.2/3) milestone Jan 15, 2018
Copy link
Member

@danxuliu danxuliu left a 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)) {
Copy link
Member

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?

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 {
Copy link
Member

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).

}


return relativePrefix + ', ' + OC.Util.formatDate(timestamp, 'LL');
Copy link
Member

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 ;-)

var date = moment(timestamp, 'x'),
today = moment(),
dayOfYear = OC.Util.formatDate(date, 'YYYY-DDD'),
dateOfToday = OC.Util.formatDate(today, 'YYYY-DDD');
Copy link
Member

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(),
Copy link
Member

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.

@jancborchardt
Copy link
Member

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.

@nickvergessen
Copy link
Member Author

bildschirmfoto von 2018-01-16 11-18-40

We are using relative dates now for the first 24h, afterwards it switches to Time (or should we include the date too, because the date divider might not be visible?
Or can we pin the last date divider with some css magic?

nickvergessen and others added 3 commits January 16, 2018 18:04
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>
@danxuliu danxuliu force-pushed the bugfix/559/date-divider-improvements branch from 46e43c6 to af8e1aa Compare January 16, 2018 20:44
@danxuliu
Copy link
Member

danxuliu commented Jan 17, 2018

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 live-relative-timestamp CSS class it will be set anyway after 30 seconds. Also, the relative date in the header is not automatically updated, so when chatting near midnight you will end with two Today headers. Probably it will be needed to use a custom function to update the relative time akin to the one used in the server.

@nickvergessen

should we include the date too, because the date divider might not be visible?

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.

Or can we pin the last date divider with some css magic?

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 ;-) ).

@nickvergessen
Copy link
Member Author

Fixed the issue with live-relative-timestamp

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.

Done

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 ;-) ).

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>
Copy link
Member

@danxuliu danxuliu left a 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.

@nickvergessen
Copy link
Member Author

What do you mean?
after midnight it still says 1 day ago, although it should be 2 days ago now?

@nickvergessen
Copy link
Member Author

Merging as discussed

@nickvergessen nickvergessen merged commit 8f88fe8 into stable13 Jan 17, 2018
@nickvergessen nickvergessen deleted the bugfix/559/date-divider-improvements branch January 17, 2018 12:05
marcoambrosini pushed a commit that referenced this pull request Oct 9, 2019
Close the datepicker on unfocus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants