From 0c611e311543ac9ba11903bf3f87dfdf4c207974 Mon Sep 17 00:00:00 2001 From: Sasha Sorokin Date: Tue, 28 Jan 2020 14:28:38 -0500 Subject: [PATCH 01/13] Add missing translations (#12996) This commit adds missing translations for #12966 and #12954. --- app/javascript/mastodon/locales/defaultMessages.json | 12 ++++++++++++ app/javascript/mastodon/locales/en.json | 3 +++ 2 files changed, 15 insertions(+) diff --git a/app/javascript/mastodon/locales/defaultMessages.json b/app/javascript/mastodon/locales/defaultMessages.json index 3fc726dfdd..0eb054acdb 100644 --- a/app/javascript/mastodon/locales/defaultMessages.json +++ b/app/javascript/mastodon/locales/defaultMessages.json @@ -293,6 +293,10 @@ }, { "descriptors": [ + { + "defaultMessage": "today", + "id": "relative_time.today" + }, { "defaultMessage": "now", "id": "relative_time.just_now" @@ -1742,6 +1746,14 @@ "defaultMessage": "Home", "id": "column.home" }, + { + "defaultMessage": "Show announcements", + "id": "home.show_announcements" + }, + { + "defaultMessage": "Hide announcements", + "id": "home.hide_announcements" + }, { "defaultMessage": "Your home timeline is empty! Visit {public} or use search to get started and meet other users.", "id": "empty_column.home" diff --git a/app/javascript/mastodon/locales/en.json b/app/javascript/mastodon/locales/en.json index 25aa6bff5c..5927aeb6ca 100644 --- a/app/javascript/mastodon/locales/en.json +++ b/app/javascript/mastodon/locales/en.json @@ -184,6 +184,8 @@ "home.column_settings.basic": "Basic", "home.column_settings.show_reblogs": "Show boosts", "home.column_settings.show_replies": "Show replies", + "home.hide_announcements": "Hide announcements", + "home.show_announcements": "Show announcements", "intervals.full.days": "{number, plural, one {# day} other {# days}}", "intervals.full.hours": "{number, plural, one {# hour} other {# hours}}", "intervals.full.minutes": "{number, plural, one {# minute} other {# minutes}}", @@ -333,6 +335,7 @@ "relative_time.just_now": "now", "relative_time.minutes": "{number}m", "relative_time.seconds": "{number}s", + "relative_time.today": "today", "reply_indicator.cancel": "Cancel", "report.forward": "Forward to {target}", "report.forward_hint": "The account is from another server. Send an anonymized copy of the report there as well?", From 71baacb49ac63aa12af79649f657ab1e1d5787aa Mon Sep 17 00:00:00 2001 From: Shlee Date: Wed, 29 Jan 2020 03:33:09 +0800 Subject: [PATCH 02/13] Update Dockerfile (#12997) --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index cc75bd6bee..16618a2765 100644 --- a/Dockerfile +++ b/Dockerfile @@ -58,7 +58,9 @@ RUN npm install -g yarn && \ COPY Gemfile* package.json yarn.lock /opt/mastodon/ RUN cd /opt/mastodon && \ - bundle install -j$(nproc) --deployment --without development test && \ + bundle config set deployment 'true' && \ + bundle config set without 'development test' && \ + bundle install -j$(nproc) && \ yarn install --pure-lockfile FROM ubuntu:18.04 From 60e160a02d47c4b3825dc1fd249ee5b4847022c5 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 28 Jan 2020 20:56:32 +0100 Subject: [PATCH 03/13] Bump version to 3.1.0rc2 (#12999) --- lib/mastodon/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mastodon/version.rb b/lib/mastodon/version.rb index 5900c49c9c..7a0a9c41a8 100644 --- a/lib/mastodon/version.rb +++ b/lib/mastodon/version.rb @@ -17,7 +17,7 @@ module Mastodon end def flags - 'rc1' + 'rc2' end def suffix From bba0269d9741c8c4daaa9048c265a1321d93fbba Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 29 Jan 2020 16:18:33 +0100 Subject: [PATCH 04/13] Fix mascot being too large, and a code style issue (#13002) --- app/javascript/mastodon/reducers/statuses.js | 3 +-- app/javascript/styles/mastodon/components.scss | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/javascript/mastodon/reducers/statuses.js b/app/javascript/mastodon/reducers/statuses.js index 398a48cff8..2554c008d1 100644 --- a/app/javascript/mastodon/reducers/statuses.js +++ b/app/javascript/mastodon/reducers/statuses.js @@ -42,8 +42,7 @@ export default function statuses(state = initialState, action) { case FAVOURITE_REQUEST: return state.setIn([action.status.get('id'), 'favourited'], true); case UNFAVOURITE_SUCCESS: - const favouritesCount = action.status.get('favourites_count'); - return state.setIn([action.status.get('id'), 'favourites_count'], favouritesCount - 1); + return state.updateIn([action.status.get('id'), 'favourites_count'], x => Math.max(0, x - 1)); case FAVOURITE_FAIL: return state.get(action.status.get('id')) === undefined ? state : state.setIn([action.status.get('id'), 'favourited'], false); case BOOKMARK_REQUEST: diff --git a/app/javascript/styles/mastodon/components.scss b/app/javascript/styles/mastodon/components.scss index 28b2fa86f0..d72f2e0594 100644 --- a/app/javascript/styles/mastodon/components.scss +++ b/app/javascript/styles/mastodon/components.scss @@ -2522,7 +2522,7 @@ a.account__display-name { display: block; object-fit: contain; object-position: bottom left; - width: 100%; + width: 85%; height: 100%; pointer-events: none; user-drag: none; From 50cd73e5d7e39600203c9c3f591f04289f41e297 Mon Sep 17 00:00:00 2001 From: Sasha Sorokin Date: Wed, 29 Jan 2020 11:35:54 -0500 Subject: [PATCH 05/13] Add "Show thread" button to public profiles (#13000) This adds "Show thread" button to the status view which is used in profiles. The logic to display the button is mimicking logic in web app available at app/javascript/mastodon/components/status.js#L439. * The little change in components CSS required to remove enforced underline for all links on public pages on our button. --- app/javascript/styles/mastodon/components.scss | 1 + app/views/statuses/_simple_status.html.haml | 4 ++++ config/locales/en.yml | 1 + 3 files changed, 6 insertions(+) diff --git a/app/javascript/styles/mastodon/components.scss b/app/javascript/styles/mastodon/components.scss index d72f2e0594..7c09780b4f 100644 --- a/app/javascript/styles/mastodon/components.scss +++ b/app/javascript/styles/mastodon/components.scss @@ -923,6 +923,7 @@ background: transparent; padding: 0; padding-top: 8px; + text-decoration: none; &:hover, &:active { diff --git a/app/views/statuses/_simple_status.html.haml b/app/views/statuses/_simple_status.html.haml index 66c9412afc..5d16b1fc2a 100644 --- a/app/views/statuses/_simple_status.html.haml +++ b/app/views/statuses/_simple_status.html.haml @@ -45,6 +45,10 @@ - elsif status.preview_card = react_component :card, 'maxDescription': 160, card: ActiveModelSerializers::SerializableResource.new(status.preview_card, serializer: REST::PreviewCardSerializer).as_json + - if !status.in_reply_to_id.nil? && status.in_reply_to_account_id == status.account.id + = link_to ActivityPub::TagManager.instance.url_for(status), class: 'status__content__read-more-button', target: stream_link_target, rel: 'noopener noreferrer' do + = t 'statuses.show_thread' + .status__action-bar .status__action-bar__counter = link_to remote_interaction_path(status, type: :reply), class: 'status__action-bar-button icon-button modal-button', style: 'font-size: 18px; width: 23.1429px; height: 23.1429px; line-height: 23.15px;' do diff --git a/config/locales/en.yml b/config/locales/en.yml index 44900d4261..b1586ade52 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1088,6 +1088,7 @@ en: other: "%{count} votes" vote: Vote show_more: Show more + show_thread: Show thread sign_in_to_participate: Sign in to participate in the conversation title: '%{name}: "%{quote}"' visibilities: From 0fd2d2eee2bf2271c7dc4bc322287bd4cbba4a39 Mon Sep 17 00:00:00 2001 From: ThibG Date: Wed, 29 Jan 2020 18:39:44 +0100 Subject: [PATCH 06/13] Fix english wording (#13003) --- config/locales/simple_form.en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index f050ec8a36..37d5a82f5b 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -93,7 +93,7 @@ en: all_day: All-day event ends_at: End of event scheduled_at: Schedule publication - starts_at: Begin of event + starts_at: Start of event text: Announcement defaults: autofollow: Invite to follow your account From 2f978abd8790ba2e1ef994a00627397c8ca8cb57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D0=B8=D0=BB=20=D0=9F=D1=80=D0=BE?= =?UTF-8?q?=D0=BD=D0=B8=D0=BD?= Date: Thu, 30 Jan 2020 21:05:56 +1000 Subject: [PATCH 07/13] Fix Node version in Vagrant (#13008) --- Vagrantfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vagrantfile b/Vagrantfile index c4941f6731..79af1dc5d7 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -12,7 +12,7 @@ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - sudo apt-add-repository 'deb https://dl.yarnpkg.com/debian/ stable main' # Add repo for NodeJS -curl -sL https://deb.nodesource.com/setup_8.x | sudo bash - +curl -sL https://deb.nodesource.com/setup_10.x | sudo bash - # Add firewall rule to redirect 80 to PORT and save sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port #{ENV["PORT"]} From 37dc12dd5387935defcf625125a441dd161cc571 Mon Sep 17 00:00:00 2001 From: "Renato \"Lond\" Cerqueira" Date: Sat, 1 Feb 2020 15:42:12 +0100 Subject: [PATCH 08/13] Fix error when sending moderation notification (#13014) Since the statuses helper is not loaded, the rtl helper cannot be found and the email cannot be sent. --- app/mailers/user_mailer.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index c30bec80b9..88a11f7617 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -6,6 +6,7 @@ class UserMailer < Devise::Mailer helper :accounts helper :application helper :instance + helper :statuses add_template_helper RoutingHelper From 61a7390b666dc40beda291da426436a9d36f4288 Mon Sep 17 00:00:00 2001 From: abcang Date: Sat, 1 Feb 2020 23:42:24 +0900 Subject: [PATCH 09/13] Search account domain in lowercase (#13016) * Search account domain in lowercase * fix rubocop error * fix spec/models/account_spec.rb --- app/models/account.rb | 3 +- app/models/concerns/account_finder_concern.rb | 8 +-- app/validators/unique_username_validator.rb | 3 +- spec/models/account_spec.rb | 6 +-- .../unique_username_validator_spec.rb | 51 +++++++++++++++++-- 5 files changed, 55 insertions(+), 16 deletions(-) diff --git a/app/models/account.rb b/app/models/account.rb index da6f51a9cb..0eb719d652 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -70,14 +70,13 @@ class Account < ApplicationRecord enum protocol: [:ostatus, :activitypub] validates :username, presence: true + validates_with UniqueUsernameValidator, if: -> { will_save_change_to_username? } # Remote user validations - validates :username, uniqueness: { scope: :domain, case_sensitive: true }, if: -> { !local? && will_save_change_to_username? } validates :username, format: { with: /\A#{USERNAME_RE}\z/i }, if: -> { !local? && will_save_change_to_username? } # Local user validations validates :username, format: { with: /\A[a-z0-9_]+\z/i }, length: { maximum: 30 }, if: -> { local? && will_save_change_to_username? && actor_type != 'Application' } - validates_with UniqueUsernameValidator, if: -> { local? && will_save_change_to_username? } validates_with UnreservedUsernameValidator, if: -> { local? && will_save_change_to_username? } validates :display_name, length: { maximum: 30 }, if: -> { local? && will_save_change_to_display_name? } validates :note, note_length: { maximum: 500 }, if: -> { local? && will_save_change_to_note? } diff --git a/app/models/concerns/account_finder_concern.rb b/app/models/concerns/account_finder_concern.rb index a54c2174d4..04b2c981b1 100644 --- a/app/models/concerns/account_finder_concern.rb +++ b/app/models/concerns/account_finder_concern.rb @@ -48,7 +48,7 @@ module AccountFinderConcern end def with_usernames - Account.where.not(username: '') + Account.where.not(Account.arel_table[:username].lower.eq '') end def matching_username @@ -56,11 +56,7 @@ module AccountFinderConcern end def matching_domain - if domain.nil? - Account.where(domain: nil) - else - Account.where(Account.arel_table[:domain].lower.eq domain.to_s.downcase) - end + Account.where(Account.arel_table[:domain].lower.eq(domain.nil? ? nil : domain.to_s.downcase)) end end end diff --git a/app/validators/unique_username_validator.rb b/app/validators/unique_username_validator.rb index 4e24e3f5fe..f87eb06baf 100644 --- a/app/validators/unique_username_validator.rb +++ b/app/validators/unique_username_validator.rb @@ -7,8 +7,9 @@ class UniqueUsernameValidator < ActiveModel::Validator return if account.username.nil? normalized_username = account.username.downcase + normalized_domain = account.domain&.downcase - scope = Account.where(domain: nil).where('lower(username) = ?', normalized_username) + scope = Account.where(Account.arel_table[:username].lower.eq normalized_username).where(Account.arel_table[:domain].lower.eq normalized_domain) scope = scope.where.not(id: account.id) if account.persisted? account.errors.add(:username, :taken) if scope.exists? diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 4266122b24..98d29e6f3d 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -619,18 +619,18 @@ RSpec.describe Account, type: :model do end context 'when is remote' do - it 'is invalid if the username is not unique in case-sensitive comparison among accounts in the same normalized domain' do + it 'is invalid if the username is same among accounts in the same normalized domain' do Fabricate(:account, domain: 'にゃん', username: 'username') account = Fabricate.build(:account, domain: 'xn--r9j5b5b', username: 'username') account.valid? expect(account).to model_have_error_on_field(:username) end - it 'is valid even if the username is unique only in case-sensitive comparison among accounts in the same normalized domain' do + it 'is invalid if the username is not unique in case-insensitive comparison among accounts in the same normalized domain' do Fabricate(:account, domain: 'にゃん', username: 'username') account = Fabricate.build(:account, domain: 'xn--r9j5b5b', username: 'Username') account.valid? - expect(account).not_to model_have_error_on_field(:username) + expect(account).to model_have_error_on_field(:username) end it 'is valid even if the username contains hyphens' do diff --git a/spec/validators/unique_username_validator_spec.rb b/spec/validators/unique_username_validator_spec.rb index c2e2eedf41..6867cbc6ce 100644 --- a/spec/validators/unique_username_validator_spec.rb +++ b/spec/validators/unique_username_validator_spec.rb @@ -4,22 +4,65 @@ require 'rails_helper' describe UniqueUsernameValidator do describe '#validate' do + context 'when local account' do + it 'does not add errors if username is nil' do + account = double(username: nil, domain: nil, persisted?: false, errors: double(add: nil)) + subject.validate(account) + expect(account.errors).to_not have_received(:add) + end + + it 'does not add errors when existing one is subject itself' do + account = Fabricate(:account, username: 'abcdef') + expect(account).to be_valid + end + + it 'adds an error when the username is already used with ignoring cases' do + Fabricate(:account, username: 'ABCdef') + account = double(username: 'abcDEF', domain: nil, persisted?: false, errors: double(add: nil)) + subject.validate(account) + expect(account.errors).to have_received(:add) + end + + it 'does not add errors when same username remote account exists' do + Fabricate(:account, username: 'abcdef', domain: 'example.com') + account = double(username: 'abcdef', domain: nil, persisted?: false, errors: double(add: nil)) + subject.validate(account) + expect(account.errors).to_not have_received(:add) + end + end + end + + context 'when remote account' do it 'does not add errors if username is nil' do - account = double(username: nil, persisted?: false, errors: double(add: nil)) + account = double(username: nil, domain: 'example.com', persisted?: false, errors: double(add: nil)) subject.validate(account) expect(account.errors).to_not have_received(:add) end it 'does not add errors when existing one is subject itself' do - account = Fabricate(:account, username: 'abcdef') + account = Fabricate(:account, username: 'abcdef', domain: 'example.com') expect(account).to be_valid end it 'adds an error when the username is already used with ignoring cases' do - Fabricate(:account, username: 'ABCdef') - account = double(username: 'abcDEF', persisted?: false, errors: double(add: nil)) + Fabricate(:account, username: 'ABCdef', domain: 'example.com') + account = double(username: 'abcDEF', domain: 'example.com', persisted?: false, errors: double(add: nil)) subject.validate(account) expect(account.errors).to have_received(:add) end + + it 'adds an error when the domain is already used with ignoring cases' do + Fabricate(:account, username: 'ABCdef', domain: 'example.com') + account = double(username: 'ABCdef', domain: 'EXAMPLE.COM', persisted?: false, errors: double(add: nil)) + subject.validate(account) + expect(account.errors).to have_received(:add) + end + + it 'does not add errors when account with the same username and another domain exists' do + Fabricate(:account, username: 'abcdef', domain: 'example.com') + account = double(username: 'abcdef', domain: 'example2.com', persisted?: false, errors: double(add: nil)) + subject.validate(account) + expect(account.errors).to_not have_received(:add) + end end end From 3adc722d1cdd28d87d2724b8952d7ec52d241b52 Mon Sep 17 00:00:00 2001 From: ThibG Date: Mon, 3 Feb 2020 01:53:09 +0100 Subject: [PATCH 10/13] Change how unread announcements are handled (#13020) * Change meaning of /api/v1/announcements/:id/dismiss to mark an announcement as read * Change how unread announcements are counted in UI * Add unread marker to announcements and mark announcements as unread as they are displayed * Fixups --- .../api/v1/announcements_controller.rb | 6 +--- .../mastodon/actions/announcements.js | 30 ++++++++++++++++ .../components/announcements.js | 34 ++++++++++++++++++- .../containers/announcements_container.js | 3 +- .../mastodon/features/home_timeline/index.js | 2 +- .../mastodon/reducers/announcements.js | 26 +++----------- .../styles/mastodon/components.scss | 12 +++++++ .../rest/announcement_serializer.rb | 10 ++++++ 8 files changed, 94 insertions(+), 29 deletions(-) diff --git a/app/controllers/api/v1/announcements_controller.rb b/app/controllers/api/v1/announcements_controller.rb index 6724fac2ec..1e692ff751 100644 --- a/app/controllers/api/v1/announcements_controller.rb +++ b/app/controllers/api/v1/announcements_controller.rb @@ -19,11 +19,7 @@ class Api::V1::AnnouncementsController < Api::BaseController def set_announcements @announcements = begin - scope = Announcement.published - - scope.merge!(Announcement.without_muted(current_account)) unless truthy_param?(:with_dismissed) - - scope.chronological + Announcement.published.chronological end end diff --git a/app/javascript/mastodon/actions/announcements.js b/app/javascript/mastodon/actions/announcements.js index f072a407f9..1bdea909f7 100644 --- a/app/javascript/mastodon/actions/announcements.js +++ b/app/javascript/mastodon/actions/announcements.js @@ -7,6 +7,10 @@ export const ANNOUNCEMENTS_FETCH_FAIL = 'ANNOUNCEMENTS_FETCH_FAIL'; export const ANNOUNCEMENTS_UPDATE = 'ANNOUNCEMENTS_UPDATE'; export const ANNOUNCEMENTS_DELETE = 'ANNOUNCEMENTS_DELETE'; +export const ANNOUNCEMENTS_DISMISS_REQUEST = 'ANNOUNCEMENTS_DISMISS_REQUEST'; +export const ANNOUNCEMENTS_DISMISS_SUCCESS = 'ANNOUNCEMENTS_DISMISS_SUCCESS'; +export const ANNOUNCEMENTS_DISMISS_FAIL = 'ANNOUNCEMENTS_DISMISS_FAIL'; + export const ANNOUNCEMENTS_REACTION_ADD_REQUEST = 'ANNOUNCEMENTS_REACTION_ADD_REQUEST'; export const ANNOUNCEMENTS_REACTION_ADD_SUCCESS = 'ANNOUNCEMENTS_REACTION_ADD_SUCCESS'; export const ANNOUNCEMENTS_REACTION_ADD_FAIL = 'ANNOUNCEMENTS_REACTION_ADD_FAIL'; @@ -56,6 +60,32 @@ export const updateAnnouncements = announcement => ({ announcement: normalizeAnnouncement(announcement), }); +export const dismissAnnouncement = announcementId => (dispatch, getState) => { + dispatch(dismissAnnouncementRequest(announcementId)); + + api(getState).post(`/api/v1/announcements/${announcementId}/dismiss`).then(() => { + dispatch(dismissAnnouncementSuccess(announcementId)); + }).catch(error => { + dispatch(dismissAnnouncementFail(announcementId, error)); + }); +}; + +export const dismissAnnouncementRequest = announcementId => ({ + type: ANNOUNCEMENTS_DISMISS_REQUEST, + id: announcementId, +}); + +export const dismissAnnouncementSuccess = announcementId => ({ + type: ANNOUNCEMENTS_DISMISS_SUCCESS, + id: announcementId, +}); + +export const dismissAnnouncementFail = (announcementId, error) => ({ + type: ANNOUNCEMENTS_DISMISS_FAIL, + id: announcementId, + error, +}); + export const addReaction = (announcementId, name) => (dispatch, getState) => { const announcement = getState().getIn(['announcements', 'items']).find(x => x.get('id') === announcementId); diff --git a/app/javascript/mastodon/features/getting_started/components/announcements.js b/app/javascript/mastodon/features/getting_started/components/announcements.js index cf2abdd768..91cf6215e6 100644 --- a/app/javascript/mastodon/features/getting_started/components/announcements.js +++ b/app/javascript/mastodon/features/getting_started/components/announcements.js @@ -302,10 +302,23 @@ class Announcement extends ImmutablePureComponent { addReaction: PropTypes.func.isRequired, removeReaction: PropTypes.func.isRequired, intl: PropTypes.object.isRequired, + selected: PropTypes.bool, }; + state = { + unread: !this.props.announcement.get('read'), + }; + + componentDidUpdate () { + const { selected, announcement } = this.props; + if (!selected && this.state.unread !== !announcement.get('read')) { + this.setState({ unread: !announcement.get('read') }); + } + } + render () { const { announcement } = this.props; + const { unread } = this.state; const startsAt = announcement.get('starts_at') && new Date(announcement.get('starts_at')); const endsAt = announcement.get('ends_at') && new Date(announcement.get('ends_at')); const now = new Date(); @@ -330,6 +343,8 @@ class Announcement extends ImmutablePureComponent { removeReaction={this.props.removeReaction} emojiMap={this.props.emojiMap} /> + + {unread && } ); } @@ -342,6 +357,7 @@ class Announcements extends ImmutablePureComponent { static propTypes = { announcements: ImmutablePropTypes.list, emojiMap: ImmutablePropTypes.map.isRequired, + dismissAnnouncement: PropTypes.func.isRequired, addReaction: PropTypes.func.isRequired, removeReaction: PropTypes.func.isRequired, intl: PropTypes.object.isRequired, @@ -351,6 +367,21 @@ class Announcements extends ImmutablePureComponent { index: 0, }; + componentDidMount () { + this._markAnnouncementAsRead(); + } + + componentDidUpdate () { + this._markAnnouncementAsRead(); + } + + _markAnnouncementAsRead () { + const { dismissAnnouncement, announcements } = this.props; + const { index } = this.state; + const announcement = announcements.get(index); + if (!announcement.get('read')) dismissAnnouncement(announcement.get('id')); + } + handleChangeIndex = index => { this.setState({ index: index % this.props.announcements.size }); } @@ -377,7 +408,7 @@ class Announcements extends ImmutablePureComponent {
- {announcements.map(announcement => ( + {announcements.map((announcement, idx) => ( ))} diff --git a/app/javascript/mastodon/features/getting_started/containers/announcements_container.js b/app/javascript/mastodon/features/getting_started/containers/announcements_container.js index 8c3fc2e6b5..9d03ad6f78 100644 --- a/app/javascript/mastodon/features/getting_started/containers/announcements_container.js +++ b/app/javascript/mastodon/features/getting_started/containers/announcements_container.js @@ -1,5 +1,5 @@ import { connect } from 'react-redux'; -import { addReaction, removeReaction } from 'mastodon/actions/announcements'; +import { addReaction, removeReaction, dismissAnnouncement } from 'mastodon/actions/announcements'; import Announcements from '../components/announcements'; import { createSelector } from 'reselect'; import { Map as ImmutableMap } from 'immutable'; @@ -12,6 +12,7 @@ const mapStateToProps = state => ({ }); const mapDispatchToProps = dispatch => ({ + dismissAnnouncement: id => dispatch(dismissAnnouncement(id)), addReaction: (id, name) => dispatch(addReaction(id, name)), removeReaction: (id, name) => dispatch(removeReaction(id, name)), }); diff --git a/app/javascript/mastodon/features/home_timeline/index.js b/app/javascript/mastodon/features/home_timeline/index.js index 2bad22bc1d..577ff33bb0 100644 --- a/app/javascript/mastodon/features/home_timeline/index.js +++ b/app/javascript/mastodon/features/home_timeline/index.js @@ -24,7 +24,7 @@ const mapStateToProps = state => ({ hasUnread: state.getIn(['timelines', 'home', 'unread']) > 0, isPartial: state.getIn(['timelines', 'home', 'isPartial']), hasAnnouncements: !state.getIn(['announcements', 'items']).isEmpty(), - unreadAnnouncements: state.getIn(['announcements', 'unread']).size, + unreadAnnouncements: state.getIn(['announcements', 'items']).count(item => !item.get('read')), showAnnouncements: state.getIn(['announcements', 'show']), }); diff --git a/app/javascript/mastodon/reducers/announcements.js b/app/javascript/mastodon/reducers/announcements.js index 1653318ce2..34e08eac88 100644 --- a/app/javascript/mastodon/reducers/announcements.js +++ b/app/javascript/mastodon/reducers/announcements.js @@ -10,14 +10,14 @@ import { ANNOUNCEMENTS_REACTION_REMOVE_FAIL, ANNOUNCEMENTS_TOGGLE_SHOW, ANNOUNCEMENTS_DELETE, + ANNOUNCEMENTS_DISMISS_SUCCESS, } from '../actions/announcements'; -import { Map as ImmutableMap, List as ImmutableList, Set as ImmutableSet, fromJS } from 'immutable'; +import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable'; const initialState = ImmutableMap({ items: ImmutableList(), isLoading: false, show: false, - unread: ImmutableSet(), }); const updateReaction = (state, id, name, updater) => state.update('items', list => list.map(announcement => { @@ -42,24 +42,11 @@ const addReaction = (state, id, name) => updateReaction(state, id, name, x => x. const removeReaction = (state, id, name) => updateReaction(state, id, name, x => x.set('me', false).update('count', y => y - 1)); -const addUnread = (state, items) => { - if (state.get('show')) { - return state; - } - - const newIds = ImmutableSet(items.map(x => x.get('id'))); - const oldIds = ImmutableSet(state.get('items').map(x => x.get('id'))); - - return state.update('unread', unread => unread.union(newIds.subtract(oldIds))); -}; - const sortAnnouncements = list => list.sortBy(x => x.get('starts_at') || x.get('published_at')); const updateAnnouncement = (state, announcement) => { const idx = state.get('items').findIndex(x => x.get('id') === announcement.get('id')); - state = addUnread(state, [announcement]); - if (idx > -1) { // Deep merge is used because announcements from the streaming API do not contain // personalized data about which reactions have been selected by the given user, @@ -74,7 +61,6 @@ export default function announcementsReducer(state = initialState, action) { switch(action.type) { case ANNOUNCEMENTS_TOGGLE_SHOW: return state.withMutations(map => { - if (!map.get('show')) map.set('unread', ImmutableSet()); map.set('show', !map.get('show')); }); case ANNOUNCEMENTS_FETCH_REQUEST: @@ -83,10 +69,6 @@ export default function announcementsReducer(state = initialState, action) { return state.withMutations(map => { const items = fromJS(action.announcements); - map.set('unread', ImmutableSet()); - - addUnread(map, items); - map.set('items', items); map.set('isLoading', false); }); @@ -102,8 +84,10 @@ export default function announcementsReducer(state = initialState, action) { case ANNOUNCEMENTS_REACTION_REMOVE_REQUEST: case ANNOUNCEMENTS_REACTION_ADD_FAIL: return removeReaction(state, action.id, action.name); + case ANNOUNCEMENTS_DISMISS_SUCCESS: + return updateAnnouncement(state, fromJS({ 'id': action.id, 'read': true })); case ANNOUNCEMENTS_DELETE: - return state.update('unread', set => set.delete(action.id)).update('items', list => { + return state.update('items', list => { const idx = list.findIndex(x => x.get('id') === action.id); if (idx > -1) { diff --git a/app/javascript/styles/mastodon/components.scss b/app/javascript/styles/mastodon/components.scss index 7c09780b4f..d90d9734dc 100644 --- a/app/javascript/styles/mastodon/components.scss +++ b/app/javascript/styles/mastodon/components.scss @@ -6694,6 +6694,18 @@ noscript { font-weight: 500; margin-bottom: 10px; } + + &__unread { + position: absolute; + top: 15px; + right: 15px; + display: inline-block; + background: $highlight-text-color; + border-radius: 50%; + width: 0.625rem; + height: 0.625rem; + margin: 0 .15em; + } } &__pagination { diff --git a/app/serializers/rest/announcement_serializer.rb b/app/serializers/rest/announcement_serializer.rb index ae962aa1de..ae72f9aceb 100644 --- a/app/serializers/rest/announcement_serializer.rb +++ b/app/serializers/rest/announcement_serializer.rb @@ -4,15 +4,25 @@ class REST::AnnouncementSerializer < ActiveModel::Serializer attributes :id, :content, :starts_at, :ends_at, :all_day, :published_at, :updated_at + attribute :read, if: :current_user? + has_many :mentions has_many :tags, serializer: REST::StatusSerializer::TagSerializer has_many :emojis, serializer: REST::CustomEmojiSerializer has_many :reactions, serializer: REST::ReactionSerializer + def current_user? + !current_user.nil? + end + def id object.id.to_s end + def read + object.announcement_mutes.where(account: current_user.account).exists? + end + def content Formatter.instance.linkify(object.text) end From 9dc1f7d29941865f27734d11b0f52c49c095dbcf Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 29 Jan 2020 16:18:33 +0100 Subject: [PATCH 11/13] [Glitch] Fix mascot being too large, and a code style issue Port bba0269d9741c8c4daaa9048c265a1321d93fbba to glitch-soc Signed-off-by: Thibaut Girka --- app/javascript/flavours/glitch/reducers/statuses.js | 3 +-- app/javascript/flavours/glitch/styles/components/drawer.scss | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/javascript/flavours/glitch/reducers/statuses.js b/app/javascript/flavours/glitch/reducers/statuses.js index ee8ac929d7..8926e49f1c 100644 --- a/app/javascript/flavours/glitch/reducers/statuses.js +++ b/app/javascript/flavours/glitch/reducers/statuses.js @@ -41,8 +41,7 @@ export default function statuses(state = initialState, action) { case FAVOURITE_REQUEST: return state.setIn([action.status.get('id'), 'favourited'], true); case UNFAVOURITE_SUCCESS: - const favouritesCount = action.status.get('favourites_count'); - return state.setIn([action.status.get('id'), 'favourites_count'], favouritesCount - 1); + return state.updateIn([action.status.get('id'), 'favourites_count'], x => Math.max(0, x - 1)); case FAVOURITE_FAIL: return state.get(action.status.get('id')) === undefined ? state : state.setIn([action.status.get('id'), 'favourited'], false); case BOOKMARK_REQUEST: diff --git a/app/javascript/flavours/glitch/styles/components/drawer.scss b/app/javascript/flavours/glitch/styles/components/drawer.scss index 93a3f62ed3..d5463e4068 100644 --- a/app/javascript/flavours/glitch/styles/components/drawer.scss +++ b/app/javascript/flavours/glitch/styles/components/drawer.scss @@ -210,7 +210,7 @@ display: block; object-fit: contain; object-position: bottom left; - width: 100%; + width: 85%; height: 100%; pointer-events: none; user-drag: none; From dd6149ca0b05b05bd9103e2127adc387edb7fd22 Mon Sep 17 00:00:00 2001 From: Sasha Sorokin Date: Wed, 29 Jan 2020 11:35:54 -0500 Subject: [PATCH 12/13] [Glitch] Add "Show thread" button to public profiles Port 50cd73e5d7e39600203c9c3f591f04289f41e297 to glitch-soc Signed-off-by: Thibaut Girka --- .../flavours/glitch/styles/statuses.scss | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/javascript/flavours/glitch/styles/statuses.scss b/app/javascript/flavours/glitch/styles/statuses.scss index 611d5185bb..22fa7b3fd2 100644 --- a/app/javascript/flavours/glitch/styles/statuses.scss +++ b/app/javascript/flavours/glitch/styles/statuses.scss @@ -222,3 +222,20 @@ } } } + +.status__content__read-more-button { + display: block; + font-size: 15px; + line-height: 20px; + color: lighten($ui-highlight-color, 8%); + border: 0; + background: transparent; + padding: 0; + padding-top: 8px; + text-decoration: none; + + &:hover, + &:active { + text-decoration: underline; + } +} From 3dcb279da31bc7810b7f58991dad4f886aaade34 Mon Sep 17 00:00:00 2001 From: ThibG Date: Mon, 3 Feb 2020 01:53:09 +0100 Subject: [PATCH 13/13] [Glitch] Change how unread announcements are handled Port 3adc722d1cdd28d87d2724b8952d7ec52d241b52 to glitch-soc Signed-off-by: Thibaut Girka --- .../flavours/glitch/actions/announcements.js | 30 ++++++++++++++++ .../components/announcements.js | 34 ++++++++++++++++++- .../containers/announcements_container.js | 3 +- .../glitch/features/home_timeline/index.js | 2 +- .../flavours/glitch/reducers/announcements.js | 26 +++----------- .../styles/components/announcements.scss | 12 +++++++ 6 files changed, 83 insertions(+), 24 deletions(-) diff --git a/app/javascript/flavours/glitch/actions/announcements.js b/app/javascript/flavours/glitch/actions/announcements.js index a19a4c7082..871409d437 100644 --- a/app/javascript/flavours/glitch/actions/announcements.js +++ b/app/javascript/flavours/glitch/actions/announcements.js @@ -7,6 +7,10 @@ export const ANNOUNCEMENTS_FETCH_FAIL = 'ANNOUNCEMENTS_FETCH_FAIL'; export const ANNOUNCEMENTS_UPDATE = 'ANNOUNCEMENTS_UPDATE'; export const ANNOUNCEMENTS_DELETE = 'ANNOUNCEMENTS_DELETE'; +export const ANNOUNCEMENTS_DISMISS_REQUEST = 'ANNOUNCEMENTS_DISMISS_REQUEST'; +export const ANNOUNCEMENTS_DISMISS_SUCCESS = 'ANNOUNCEMENTS_DISMISS_SUCCESS'; +export const ANNOUNCEMENTS_DISMISS_FAIL = 'ANNOUNCEMENTS_DISMISS_FAIL'; + export const ANNOUNCEMENTS_REACTION_ADD_REQUEST = 'ANNOUNCEMENTS_REACTION_ADD_REQUEST'; export const ANNOUNCEMENTS_REACTION_ADD_SUCCESS = 'ANNOUNCEMENTS_REACTION_ADD_SUCCESS'; export const ANNOUNCEMENTS_REACTION_ADD_FAIL = 'ANNOUNCEMENTS_REACTION_ADD_FAIL'; @@ -56,6 +60,32 @@ export const updateAnnouncements = announcement => ({ announcement: normalizeAnnouncement(announcement), }); +export const dismissAnnouncement = announcementId => (dispatch, getState) => { + dispatch(dismissAnnouncementRequest(announcementId)); + + api(getState).post(`/api/v1/announcements/${announcementId}/dismiss`).then(() => { + dispatch(dismissAnnouncementSuccess(announcementId)); + }).catch(error => { + dispatch(dismissAnnouncementFail(announcementId, error)); + }); +}; + +export const dismissAnnouncementRequest = announcementId => ({ + type: ANNOUNCEMENTS_DISMISS_REQUEST, + id: announcementId, +}); + +export const dismissAnnouncementSuccess = announcementId => ({ + type: ANNOUNCEMENTS_DISMISS_SUCCESS, + id: announcementId, +}); + +export const dismissAnnouncementFail = (announcementId, error) => ({ + type: ANNOUNCEMENTS_DISMISS_FAIL, + id: announcementId, + error, +}); + export const addReaction = (announcementId, name) => (dispatch, getState) => { const announcement = getState().getIn(['announcements', 'items']).find(x => x.get('id') === announcementId); diff --git a/app/javascript/flavours/glitch/features/getting_started/components/announcements.js b/app/javascript/flavours/glitch/features/getting_started/components/announcements.js index 4eeac8560e..e34c9009b5 100644 --- a/app/javascript/flavours/glitch/features/getting_started/components/announcements.js +++ b/app/javascript/flavours/glitch/features/getting_started/components/announcements.js @@ -302,10 +302,23 @@ class Announcement extends ImmutablePureComponent { addReaction: PropTypes.func.isRequired, removeReaction: PropTypes.func.isRequired, intl: PropTypes.object.isRequired, + selected: PropTypes.bool, }; + state = { + unread: !this.props.announcement.get('read'), + }; + + componentDidUpdate () { + const { selected, announcement } = this.props; + if (!selected && this.state.unread !== !announcement.get('read')) { + this.setState({ unread: !announcement.get('read') }); + } + } + render () { const { announcement } = this.props; + const { unread } = this.state; const startsAt = announcement.get('starts_at') && new Date(announcement.get('starts_at')); const endsAt = announcement.get('ends_at') && new Date(announcement.get('ends_at')); const now = new Date(); @@ -330,6 +343,8 @@ class Announcement extends ImmutablePureComponent { removeReaction={this.props.removeReaction} emojiMap={this.props.emojiMap} /> + + {unread && }
); } @@ -342,6 +357,7 @@ class Announcements extends ImmutablePureComponent { static propTypes = { announcements: ImmutablePropTypes.list, emojiMap: ImmutablePropTypes.map.isRequired, + dismissAnnouncement: PropTypes.func.isRequired, addReaction: PropTypes.func.isRequired, removeReaction: PropTypes.func.isRequired, intl: PropTypes.object.isRequired, @@ -351,6 +367,21 @@ class Announcements extends ImmutablePureComponent { index: 0, }; + componentDidMount () { + this._markAnnouncementAsRead(); + } + + componentDidUpdate () { + this._markAnnouncementAsRead(); + } + + _markAnnouncementAsRead () { + const { dismissAnnouncement, announcements } = this.props; + const { index } = this.state; + const announcement = announcements.get(index); + if (!announcement.get('read')) dismissAnnouncement(announcement.get('id')); + } + handleChangeIndex = index => { this.setState({ index: index % this.props.announcements.size }); } @@ -377,7 +408,7 @@ class Announcements extends ImmutablePureComponent {
- {announcements.map(announcement => ( + {announcements.map((announcement, idx) => ( ))} diff --git a/app/javascript/flavours/glitch/features/getting_started/containers/announcements_container.js b/app/javascript/flavours/glitch/features/getting_started/containers/announcements_container.js index 8fa695e344..d472323f8f 100644 --- a/app/javascript/flavours/glitch/features/getting_started/containers/announcements_container.js +++ b/app/javascript/flavours/glitch/features/getting_started/containers/announcements_container.js @@ -1,5 +1,5 @@ import { connect } from 'react-redux'; -import { addReaction, removeReaction } from 'flavours/glitch/actions/announcements'; +import { addReaction, removeReaction, dismissAnnouncement } from 'flavours/glitch/actions/announcements'; import Announcements from '../components/announcements'; import { createSelector } from 'reselect'; import { Map as ImmutableMap } from 'immutable'; @@ -12,6 +12,7 @@ const mapStateToProps = state => ({ }); const mapDispatchToProps = dispatch => ({ + dismissAnnouncement: id => dispatch(dismissAnnouncement(id)), addReaction: (id, name) => dispatch(addReaction(id, name)), removeReaction: (id, name) => dispatch(removeReaction(id, name)), }); diff --git a/app/javascript/flavours/glitch/features/home_timeline/index.js b/app/javascript/flavours/glitch/features/home_timeline/index.js index 5e36e5f768..cc8e4664c7 100644 --- a/app/javascript/flavours/glitch/features/home_timeline/index.js +++ b/app/javascript/flavours/glitch/features/home_timeline/index.js @@ -24,7 +24,7 @@ const mapStateToProps = state => ({ hasUnread: state.getIn(['timelines', 'home', 'unread']) > 0, isPartial: state.getIn(['timelines', 'home', 'isPartial']), hasAnnouncements: !state.getIn(['announcements', 'items']).isEmpty(), - unreadAnnouncements: state.getIn(['announcements', 'unread']).size, + unreadAnnouncements: state.getIn(['announcements', 'items']).count(item => !item.get('read')), showAnnouncements: state.getIn(['announcements', 'show']), }); diff --git a/app/javascript/flavours/glitch/reducers/announcements.js b/app/javascript/flavours/glitch/reducers/announcements.js index 1653318ce2..34e08eac88 100644 --- a/app/javascript/flavours/glitch/reducers/announcements.js +++ b/app/javascript/flavours/glitch/reducers/announcements.js @@ -10,14 +10,14 @@ import { ANNOUNCEMENTS_REACTION_REMOVE_FAIL, ANNOUNCEMENTS_TOGGLE_SHOW, ANNOUNCEMENTS_DELETE, + ANNOUNCEMENTS_DISMISS_SUCCESS, } from '../actions/announcements'; -import { Map as ImmutableMap, List as ImmutableList, Set as ImmutableSet, fromJS } from 'immutable'; +import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable'; const initialState = ImmutableMap({ items: ImmutableList(), isLoading: false, show: false, - unread: ImmutableSet(), }); const updateReaction = (state, id, name, updater) => state.update('items', list => list.map(announcement => { @@ -42,24 +42,11 @@ const addReaction = (state, id, name) => updateReaction(state, id, name, x => x. const removeReaction = (state, id, name) => updateReaction(state, id, name, x => x.set('me', false).update('count', y => y - 1)); -const addUnread = (state, items) => { - if (state.get('show')) { - return state; - } - - const newIds = ImmutableSet(items.map(x => x.get('id'))); - const oldIds = ImmutableSet(state.get('items').map(x => x.get('id'))); - - return state.update('unread', unread => unread.union(newIds.subtract(oldIds))); -}; - const sortAnnouncements = list => list.sortBy(x => x.get('starts_at') || x.get('published_at')); const updateAnnouncement = (state, announcement) => { const idx = state.get('items').findIndex(x => x.get('id') === announcement.get('id')); - state = addUnread(state, [announcement]); - if (idx > -1) { // Deep merge is used because announcements from the streaming API do not contain // personalized data about which reactions have been selected by the given user, @@ -74,7 +61,6 @@ export default function announcementsReducer(state = initialState, action) { switch(action.type) { case ANNOUNCEMENTS_TOGGLE_SHOW: return state.withMutations(map => { - if (!map.get('show')) map.set('unread', ImmutableSet()); map.set('show', !map.get('show')); }); case ANNOUNCEMENTS_FETCH_REQUEST: @@ -83,10 +69,6 @@ export default function announcementsReducer(state = initialState, action) { return state.withMutations(map => { const items = fromJS(action.announcements); - map.set('unread', ImmutableSet()); - - addUnread(map, items); - map.set('items', items); map.set('isLoading', false); }); @@ -102,8 +84,10 @@ export default function announcementsReducer(state = initialState, action) { case ANNOUNCEMENTS_REACTION_REMOVE_REQUEST: case ANNOUNCEMENTS_REACTION_ADD_FAIL: return removeReaction(state, action.id, action.name); + case ANNOUNCEMENTS_DISMISS_SUCCESS: + return updateAnnouncement(state, fromJS({ 'id': action.id, 'read': true })); case ANNOUNCEMENTS_DELETE: - return state.update('unread', set => set.delete(action.id)).update('items', list => { + return state.update('items', list => { const idx = list.findIndex(x => x.get('id') === action.id); if (idx > -1) { diff --git a/app/javascript/flavours/glitch/styles/components/announcements.scss b/app/javascript/flavours/glitch/styles/components/announcements.scss index 909957bf18..ac4c199cd0 100644 --- a/app/javascript/flavours/glitch/styles/components/announcements.scss +++ b/app/javascript/flavours/glitch/styles/components/announcements.scss @@ -81,6 +81,18 @@ font-weight: 500; margin-bottom: 10px; } + + &__unread { + position: absolute; + top: 15px; + right: 15px; + display: inline-block; + background: $highlight-text-color; + border-radius: 50%; + width: 0.625rem; + height: 0.625rem; + margin: 0 .15em; + } } &__pagination {