diff options
author | ThibG <thib@sitedethib.com> | 2020-01-26 23:13:48 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2020-01-26 23:13:48 +0100 |
commit | 42d2a915e4aa31533032e37aaa46354cee2386da (patch) | |
tree | b8022ad85fed21d21ed0f6e307d24f60dbe5eb07 /app | |
parent | 401f32f9eedf9f41c097ee01c1f6203eae568663 (diff) |
Change last_status_at to be a date, not datetime (#12966)
* Return last_status_at as date, not datetime * Fix relative timestamp for dates when delay is inferior to 1 day * Also fix public directory * Fix error when last_status_at isn't set
Diffstat (limited to 'app')
-rw-r--r-- | app/javascript/mastodon/components/relative_timestamp.js | 16 | ||||
-rw-r--r-- | app/serializers/rest/account_serializer.rb | 4 | ||||
-rw-r--r-- | app/views/directories/index.html.haml | 2 | ||||
-rw-r--r-- | app/views/relationships/_account.html.haml | 2 |
4 files changed, 17 insertions, 7 deletions
diff --git a/app/javascript/mastodon/components/relative_timestamp.js b/app/javascript/mastodon/components/relative_timestamp.js index aa4b73cfe..711181dcd 100644 --- a/app/javascript/mastodon/components/relative_timestamp.js +++ b/app/javascript/mastodon/components/relative_timestamp.js @@ -3,6 +3,7 @@ import { injectIntl, defineMessages } from 'react-intl'; import PropTypes from 'prop-types'; const messages = defineMessages({ + today: { id: 'relative_time.today', defaultMessage: 'today' }, just_now: { id: 'relative_time.just_now', defaultMessage: 'now' }, seconds: { id: 'relative_time.seconds', defaultMessage: '{number}s' }, minutes: { id: 'relative_time.minutes', defaultMessage: '{number}m' }, @@ -65,12 +66,14 @@ const getUnitDelay = units => { } }; -export const timeAgoString = (intl, date, now, year) => { +export const timeAgoString = (intl, date, now, year, timeGiven = true) => { const delta = now - date.getTime(); let relativeTime; - if (delta < 10 * SECOND) { + if (delta < DAY && !timeGiven) { + relativeTime = intl.formatMessage(messages.today); + } else if (delta < 10 * SECOND) { relativeTime = intl.formatMessage(messages.just_now); } else if (delta < 7 * DAY) { if (delta < MINUTE) { @@ -91,12 +94,14 @@ export const timeAgoString = (intl, date, now, year) => { return relativeTime; }; -const timeRemainingString = (intl, date, now) => { +const timeRemainingString = (intl, date, now, timeGiven = true) => { const delta = date.getTime() - now; let relativeTime; - if (delta < 10 * SECOND) { + if (delta < DAY && !timeGiven) { + relativeTime = intl.formatMessage(messages.today); + } else if (delta < 10 * SECOND) { relativeTime = intl.formatMessage(messages.moments_remaining); } else if (delta < MINUTE) { relativeTime = intl.formatMessage(messages.seconds_remaining, { number: Math.floor(delta / SECOND) }); @@ -173,8 +178,9 @@ class RelativeTimestamp extends React.Component { render () { const { timestamp, intl, year, futureDate } = this.props; + const timeGiven = timestamp.includes('T'); const date = new Date(timestamp); - const relativeTime = futureDate ? timeRemainingString(intl, date, this.state.now) : timeAgoString(intl, date, this.state.now, year); + const relativeTime = futureDate ? timeRemainingString(intl, date, this.state.now, timeGiven) : timeAgoString(intl, date, this.state.now, year, timeGiven); return ( <time dateTime={timestamp} title={intl.formatDate(date, dateFormatOptions)}> diff --git a/app/serializers/rest/account_serializer.rb b/app/serializers/rest/account_serializer.rb index fd361a34c..0db1916b0 100644 --- a/app/serializers/rest/account_serializer.rb +++ b/app/serializers/rest/account_serializer.rb @@ -55,4 +55,8 @@ class REST::AccountSerializer < ActiveModel::Serializer def moved_and_not_nested? object.moved? && object.moved_to_account.moved_to_account_id.nil? end + + def last_status_at + object.last_status_at&.to_date&.iso8601 + end end diff --git a/app/views/directories/index.html.haml b/app/views/directories/index.html.haml index 6bf2ec81e..333a257e1 100644 --- a/app/views/directories/index.html.haml +++ b/app/views/directories/index.html.haml @@ -47,7 +47,7 @@ %small= t('accounts.followers', count: account.followers_count).downcase .accounts-table__count - if account.last_status_at.present? - %time.time-ago{ datetime: account.last_status_at.iso8601, title: l(account.last_status_at) }= l account.last_status_at + %time.time-ago{ datetime: account.last_status_at.to_date.iso8601, title: l(account.last_status_at.to_date) }= l account.last_status_at.to_date - else = t('accounts.never_active') diff --git a/app/views/relationships/_account.html.haml b/app/views/relationships/_account.html.haml index 6c22deb51..af5a4aaf7 100644 --- a/app/views/relationships/_account.html.haml +++ b/app/views/relationships/_account.html.haml @@ -14,7 +14,7 @@ %small= t('accounts.followers', count: account.followers_count).downcase %td.accounts-table__count - if account.last_status_at.present? - %time.time-ago{ datetime: account.last_status_at.iso8601, title: l(account.last_status_at) }= l account.last_status_at + %time.time-ago{ datetime: account.last_status_at.to_date.iso8601, title: l(account.last_status_at.to_date) }= l account.last_status_at - else \- %small= t('accounts.last_active') |