diff --git a/Gemfile.lock b/Gemfile.lock index 620651983e5..a4b76c79690 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -127,7 +127,7 @@ GEM sshkit (~> 1.3) capistrano-yarn (2.0.2) capistrano (~> 3.0) - capybara (3.16.0) + capybara (3.16.1) addressable mini_mime (>= 0.1.3) nokogiri (~> 1.8) @@ -254,7 +254,7 @@ GEM hashdiff (0.3.7) hashie (3.6.0) heapy (0.1.4) - highline (2.0.0) + highline (2.0.1) hiredis (0.6.3) hkdf (0.3.0) html2text (0.2.1) @@ -274,7 +274,7 @@ GEM rainbow (>= 2.0.0) i18n (1.6.0) concurrent-ruby (~> 1.0) - i18n-tasks (0.9.28) + i18n-tasks (0.9.29) activesupport (>= 4.0.2) ast (>= 2.1.0) erubi @@ -395,7 +395,7 @@ GEM parallel (1.14.0) parallel_tests (2.28.0) parallel - parser (2.6.0.0) + parser (2.6.2.0) ast (~> 2.4.0) pastel (0.7.2) equatable (~> 0.5.0) diff --git a/app/controllers/activitypub/collections_controller.rb b/app/controllers/activitypub/collections_controller.rb index 995da9c55dc..853f4f9077c 100644 --- a/app/controllers/activitypub/collections_controller.rb +++ b/app/controllers/activitypub/collections_controller.rb @@ -6,13 +6,19 @@ class ActivityPub::CollectionsController < Api::BaseController before_action :set_account before_action :set_size before_action :set_statuses + before_action :set_cache_headers def show - render json: collection_presenter, - serializer: ActivityPub::CollectionSerializer, - adapter: ActivityPub::Adapter, - content_type: 'application/activity+json', - skip_activities: true + skip_session! + + render_cached_json(['activitypub', 'collection', @account, params[:id]], content_type: 'application/activity+json') do + ActiveModelSerializers::SerializableResource.new( + collection_presenter, + serializer: ActivityPub::CollectionSerializer, + adapter: ActivityPub::Adapter, + skip_activities: true + ) + end end private diff --git a/app/controllers/activitypub/outboxes_controller.rb b/app/controllers/activitypub/outboxes_controller.rb index be4289b21c3..438fa226e09 100644 --- a/app/controllers/activitypub/outboxes_controller.rb +++ b/app/controllers/activitypub/outboxes_controller.rb @@ -7,8 +7,14 @@ class ActivityPub::OutboxesController < Api::BaseController before_action :set_account before_action :set_statuses + before_action :set_cache_headers def show + unless page_requested? + skip_session! + expires_in 1.minute, public: true + end + render json: outbox_presenter, serializer: ActivityPub::OutboxSerializer, adapter: ActivityPub::Adapter, content_type: 'application/activity+json' end diff --git a/app/controllers/follower_accounts_controller.rb b/app/controllers/follower_accounts_controller.rb index 213c209abdb..1462b94fce2 100644 --- a/app/controllers/follower_accounts_controller.rb +++ b/app/controllers/follower_accounts_controller.rb @@ -3,6 +3,8 @@ class FollowerAccountsController < ApplicationController include AccountControllerConcern + before_action :set_cache_headers + def index respond_to do |format| format.html do @@ -18,6 +20,11 @@ class FollowerAccountsController < ApplicationController format.json do raise Mastodon::NotPermittedError if params[:page].present? && @account.user_hides_network? + if params[:page].blank? + skip_session! + expires_in 3.minutes, public: true + end + render json: collection_presenter, serializer: ActivityPub::CollectionSerializer, adapter: ActivityPub::Adapter, diff --git a/app/controllers/following_accounts_controller.rb b/app/controllers/following_accounts_controller.rb index 098b2a20cb0..181f852216b 100644 --- a/app/controllers/following_accounts_controller.rb +++ b/app/controllers/following_accounts_controller.rb @@ -3,10 +3,13 @@ class FollowingAccountsController < ApplicationController include AccountControllerConcern + before_action :set_cache_headers + def index respond_to do |format| format.html do use_pack 'public' + mark_cacheable! unless user_signed_in? next if @account.user_hides_network? @@ -17,6 +20,11 @@ class FollowingAccountsController < ApplicationController format.json do raise Mastodon::NotPermittedError if params[:page].present? && @account.user_hides_network? + if params[:page].blank? + skip_session! + expires_in 3.minutes, public: true + end + render json: collection_presenter, serializer: ActivityPub::CollectionSerializer, adapter: ActivityPub::Adapter, diff --git a/app/javascript/core/settings.js b/app/javascript/core/settings.js index af97fb25fb9..e0cb944e0f6 100644 --- a/app/javascript/core/settings.js +++ b/app/javascript/core/settings.js @@ -42,14 +42,20 @@ delegate(document, '#account_locked', 'change', ({ target }) => { }); delegate(document, '.input-copy input', 'click', ({ target }) => { + target.focus(); target.select(); + target.setSelectionRange(0, target.value.length); }); delegate(document, '.input-copy button', 'click', ({ target }) => { const input = target.parentNode.querySelector('.input-copy__wrapper input'); + const oldReadOnly = input.readonly; + + input.readonly = false; input.focus(); input.select(); + input.setSelectionRange(0, input.value.length); try { if (document.execCommand('copy')) { @@ -63,4 +69,6 @@ delegate(document, '.input-copy button', 'click', ({ target }) => { } catch (err) { console.error(err); } + + input.readonly = oldReadOnly; }); diff --git a/app/javascript/flavours/glitch/components/poll.js b/app/javascript/flavours/glitch/components/poll.js index 56331cb2903..690f9ae5a07 100644 --- a/app/javascript/flavours/glitch/components/poll.js +++ b/app/javascript/flavours/glitch/components/poll.js @@ -9,41 +9,12 @@ import Motion from 'mastodon/features/ui/util/optional_motion'; import spring from 'react-motion/lib/spring'; import escapeTextContentForBrowser from 'escape-html'; import emojify from 'mastodon/features/emoji/emoji'; +import RelativeTimestamp from './relative_timestamp'; const messages = defineMessages({ - moments: { id: 'time_remaining.moments', defaultMessage: 'Moments remaining' }, - seconds: { id: 'time_remaining.seconds', defaultMessage: '{number, plural, one {# second} other {# seconds}} left' }, - minutes: { id: 'time_remaining.minutes', defaultMessage: '{number, plural, one {# minute} other {# minutes}} left' }, - hours: { id: 'time_remaining.hours', defaultMessage: '{number, plural, one {# hour} other {# hours}} left' }, - days: { id: 'time_remaining.days', defaultMessage: '{number, plural, one {# day} other {# days}} left' }, closed: { id: 'poll.closed', defaultMessage: 'Closed' }, }); -const SECOND = 1000; -const MINUTE = 1000 * 60; -const HOUR = 1000 * 60 * 60; -const DAY = 1000 * 60 * 60 * 24; - -const timeRemainingString = (intl, date, now) => { - const delta = date.getTime() - now; - - let relativeTime; - - if (delta < 10 * SECOND) { - relativeTime = intl.formatMessage(messages.moments); - } else if (delta < MINUTE) { - relativeTime = intl.formatMessage(messages.seconds, { number: Math.floor(delta / SECOND) }); - } else if (delta < HOUR) { - relativeTime = intl.formatMessage(messages.minutes, { number: Math.floor(delta / MINUTE) }); - } else if (delta < DAY) { - relativeTime = intl.formatMessage(messages.hours, { number: Math.floor(delta / HOUR) }); - } else { - relativeTime = intl.formatMessage(messages.days, { number: Math.floor(delta / DAY) }); - } - - return relativeTime; -}; - const makeEmojiMap = record => record.get('emojis').reduce((obj, emoji) => { obj[`:${emoji.get('shortcode')}:`] = emoji.toJS(); return obj; @@ -146,7 +117,7 @@ class Poll extends ImmutablePureComponent { return null; } - const timeRemaining = poll.get('expired') ? intl.formatMessage(messages.closed) : timeRemainingString(intl, new Date(poll.get('expires_at')), intl.now()); + const timeRemaining = poll.get('expired') ? intl.formatMessage(messages.closed) : ; const showResults = poll.get('voted') || poll.get('expired'); const disabled = this.props.disabled || Object.entries(this.state.selected).every(item => !item); diff --git a/app/javascript/flavours/glitch/components/relative_timestamp.js b/app/javascript/flavours/glitch/components/relative_timestamp.js index 9609714a1c0..aa4b73cfe6a 100644 --- a/app/javascript/flavours/glitch/components/relative_timestamp.js +++ b/app/javascript/flavours/glitch/components/relative_timestamp.js @@ -8,6 +8,11 @@ const messages = defineMessages({ minutes: { id: 'relative_time.minutes', defaultMessage: '{number}m' }, hours: { id: 'relative_time.hours', defaultMessage: '{number}h' }, days: { id: 'relative_time.days', defaultMessage: '{number}d' }, + moments_remaining: { id: 'time_remaining.moments', defaultMessage: 'Moments remaining' }, + seconds_remaining: { id: 'time_remaining.seconds', defaultMessage: '{number, plural, one {# second} other {# seconds}} left' }, + minutes_remaining: { id: 'time_remaining.minutes', defaultMessage: '{number, plural, one {# minute} other {# minutes}} left' }, + hours_remaining: { id: 'time_remaining.hours', defaultMessage: '{number, plural, one {# hour} other {# hours}} left' }, + days_remaining: { id: 'time_remaining.days', defaultMessage: '{number, plural, one {# day} other {# days}} left' }, }); const dateFormatOptions = { @@ -86,13 +91,34 @@ export const timeAgoString = (intl, date, now, year) => { return relativeTime; }; -@injectIntl -export default class RelativeTimestamp extends React.Component { +const timeRemainingString = (intl, date, now) => { + const delta = date.getTime() - now; + + let relativeTime; + + 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) }); + } else if (delta < HOUR) { + relativeTime = intl.formatMessage(messages.minutes_remaining, { number: Math.floor(delta / MINUTE) }); + } else if (delta < DAY) { + relativeTime = intl.formatMessage(messages.hours_remaining, { number: Math.floor(delta / HOUR) }); + } else { + relativeTime = intl.formatMessage(messages.days_remaining, { number: Math.floor(delta / DAY) }); + } + + return relativeTime; +}; + +export default @injectIntl +class RelativeTimestamp extends React.Component { static propTypes = { intl: PropTypes.object.isRequired, timestamp: PropTypes.string.isRequired, year: PropTypes.number.isRequired, + futureDate: PropTypes.bool, }; state = { @@ -145,10 +171,10 @@ export default class RelativeTimestamp extends React.Component { } render () { - const { timestamp, intl, year } = this.props; + const { timestamp, intl, year, futureDate } = this.props; const date = new Date(timestamp); - const relativeTime = timeAgoString(intl, date, this.state.now, year); + const relativeTime = futureDate ? timeRemainingString(intl, date, this.state.now) : timeAgoString(intl, date, this.state.now, year); return (