From 5765accf0fe610ce359385f061ae90079e60b7e0 Mon Sep 17 00:00:00 2001 From: KMY Date: Sun, 24 Sep 2023 17:44:31 +0900 Subject: [PATCH] Add mentioned users menu to status --- .../statuses/mentioned_accounts_controller.rb | 18 +++++++++--------- .../mastodon/components/status_action_bar.jsx | 11 ++++++++++- .../features/status/components/action_bar.jsx | 6 ++++++ app/javascript/mastodon/reducers/circles.js | 1 + app/models/mention.rb | 2 ++ config/routes/api.rb | 1 + 6 files changed, 29 insertions(+), 10 deletions(-) diff --git a/app/controllers/api/v1/statuses/mentioned_accounts_controller.rb b/app/controllers/api/v1/statuses/mentioned_accounts_controller.rb index 960aa26fe67109..4d905ef1a6f95a 100644 --- a/app/controllers/api/v1/statuses/mentioned_accounts_controller.rb +++ b/app/controllers/api/v1/statuses/mentioned_accounts_controller.rb @@ -24,13 +24,13 @@ def load_accounts def default_accounts Account .without_suspended - .includes(:account_stat) - .references(:favourites) - .where(favourites: { status_id: @status.id }) + .includes(:mentions, :account_stat) + .references(:mentions) + .where(mentions: { status_id: @status.id }) end - def paginated_favourites - Favourite.paginate_by_max_id( + def paginated_mentioned_users + Mention.paginate_by_max_id( limit_param(DEFAULT_ACCOUNTS_LIMIT), params[:max_id], params[:since_id] @@ -42,19 +42,19 @@ def insert_pagination_headers end def next_path - api_v1_status_favourited_by_index_url pagination_params(max_id: pagination_max_id) if records_continue? + api_v1_status_mentioned_by_index_url pagination_params(max_id: pagination_max_id) if records_continue? end def prev_path - api_v1_status_favourited_by_index_url pagination_params(since_id: pagination_since_id) unless @accounts.empty? + api_v1_status_mentioned_by_index_url pagination_params(since_id: pagination_since_id) unless @accounts.empty? end def pagination_max_id - @accounts.last.favourites.last.id + @accounts.last.mentions.last.id end def pagination_since_id - @accounts.first.favourites.first.id + @accounts.first.mentions.first.id end def records_continue? diff --git a/app/javascript/mastodon/components/status_action_bar.jsx b/app/javascript/mastodon/components/status_action_bar.jsx index 02a42a92ddda49..a6f5e870376501 100644 --- a/app/javascript/mastodon/components/status_action_bar.jsx +++ b/app/javascript/mastodon/components/status_action_bar.jsx @@ -24,6 +24,7 @@ const messages = defineMessages({ edit: { id: 'status.edit', defaultMessage: 'Edit' }, direct: { id: 'status.direct', defaultMessage: 'Privately mention @{name}' }, mention: { id: 'status.mention', defaultMessage: 'Mention @{name}' }, + mentions: { id: 'status.mentions', defaultMessage: 'Mentioned users' }, mute: { id: 'account.mute', defaultMessage: 'Mute @{name}' }, block: { id: 'account.block', defaultMessage: 'Block @{name}' }, reply: { id: 'status.reply', defaultMessage: 'Reply' }, @@ -249,6 +250,10 @@ class StatusActionBar extends ImmutablePureComponent { this.context.router.history.push(`/@${this.props.status.getIn(['account', 'acct'])}/${this.props.status.get('id')}`); }; + handleOpenMentions = () => { + this.context.router.history.push(`/@${this.props.status.getIn(['account', 'acct'])}/${this.props.status.get('id')}/mentioned_users`); + }; + handleEmbed = () => { this.props.onEmbed(this.props.status); }; @@ -315,7 +320,11 @@ class StatusActionBar extends ImmutablePureComponent { } if (signedIn) { - if (!simpleTimelineMenu) { + if (writtenByMe) { + menu.push({ text: intl.formatMessage(messages.mentions), action: this.handleOpenMentions }); + } + + if (!simpleTimelineMenu || writtenByMe) { menu.push(null); } diff --git a/app/javascript/mastodon/features/status/components/action_bar.jsx b/app/javascript/mastodon/features/status/components/action_bar.jsx index 56086075fc8780..2e5df723dea114 100644 --- a/app/javascript/mastodon/features/status/components/action_bar.jsx +++ b/app/javascript/mastodon/features/status/components/action_bar.jsx @@ -22,6 +22,7 @@ const messages = defineMessages({ edit: { id: 'status.edit', defaultMessage: 'Edit' }, direct: { id: 'status.direct', defaultMessage: 'Privately mention @{name}' }, mention: { id: 'status.mention', defaultMessage: 'Mention @{name}' }, + mentions: { id: 'status.mentions', defaultMessage: 'Mentioned users' }, reply: { id: 'status.reply', defaultMessage: 'Reply' }, reblog: { id: 'status.reblog', defaultMessage: 'Boost' }, cancel_reblog: { id: 'status.cancel_reblog_private', defaultMessage: 'Unboost' }, @@ -95,6 +96,10 @@ class ActionBar extends PureComponent { intl: PropTypes.object.isRequired, }; + handleOpenMentions = () => { + this.context.router.history.push(`/@${this.props.status.getIn(['account', 'acct'])}/${this.props.status.get('id')}/mentioned_users`); + }; + handleReplyClick = () => { this.props.onReply(this.props.status); }; @@ -264,6 +269,7 @@ class ActionBar extends PureComponent { menu.push(null); } + menu.push({ text: intl.formatMessage(messages.mentions), action: this.handleOpenMentions }); menu.push({ text: intl.formatMessage(mutingConversation ? messages.unmuteConversation : messages.muteConversation), action: this.handleConversationMuteClick }); menu.push(null); menu.push({ text: intl.formatMessage(messages.edit), action: this.handleEditClick }); diff --git a/app/javascript/mastodon/reducers/circles.js b/app/javascript/mastodon/reducers/circles.js index 96237219d9065c..111cdcc6542336 100644 --- a/app/javascript/mastodon/reducers/circles.js +++ b/app/javascript/mastodon/reducers/circles.js @@ -23,6 +23,7 @@ const initialState = ImmutableList(); const initialStatusesState = ImmutableMap({ items: ImmutableList(), isLoading: false, + loaded: true, next: null, }); diff --git a/app/models/mention.rb b/app/models/mention.rb index 2348b2905c0e06..5addfcc583c472 100644 --- a/app/models/mention.rb +++ b/app/models/mention.rb @@ -13,6 +13,8 @@ # class Mention < ApplicationRecord + include Paginable + belongs_to :account, inverse_of: :mentions belongs_to :status diff --git a/config/routes/api.rb b/config/routes/api.rb index 961cd43ad35198..005d8f68390c4e 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -12,6 +12,7 @@ resources :favourited_by, controller: :favourited_by_accounts, only: :index resources :emoji_reactioned_by, controller: :emoji_reactioned_by_accounts, only: :index resources :referred_by, controller: :referred_by_statuses, only: :index + resources :mentioned_by, controller: :mentioned_accounts, only: :index resources :bookmark_categories, only: :index resource :reblog, only: :create post :unreblog, to: 'reblogs#destroy'