Skip to content

Commit

Permalink
Add mentioned users menu to status
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Sep 24, 2023
1 parent e17bf57 commit 5765acc
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
18 changes: 9 additions & 9 deletions app/controllers/api/v1/statuses/mentioned_accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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?
Expand Down
11 changes: 10 additions & 1 deletion app/javascript/mastodon/components/status_action_bar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down Expand Up @@ -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);
};
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down Expand Up @@ -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);
};
Expand Down Expand Up @@ -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 });
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/reducers/circles.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const initialState = ImmutableList();
const initialStatusesState = ImmutableMap({
items: ImmutableList(),
isLoading: false,
loaded: true,
next: null,
});

Expand Down
2 changes: 2 additions & 0 deletions app/models/mention.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#

class Mention < ApplicationRecord
include Paginable

belongs_to :account, inverse_of: :mentions
belongs_to :status

Expand Down
1 change: 1 addition & 0 deletions config/routes/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 5765acc

Please sign in to comment.