Skip to content

Commit

Permalink
#29 Add personal limited_scope
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Sep 25, 2023
1 parent b70576d commit 002c4bf
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/javascript/mastodon/components/status.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const messages = defineMessages({
limited_short: { id: 'privacy.limited.short', defaultMessage: 'Limited menbers only' },
mutual_short: { id: 'privacy.mutual.short', defaultMessage: 'Mutual followers only' },
circle_short: { id: 'privacy.circle.short', defaultMessage: 'Circle members only' },
personal_short: { id: 'privacy.personal.short', defaultMessage: 'Yourself only' },
direct_short: { id: 'privacy.direct.short', defaultMessage: 'Mentioned people only' },
edited: { id: 'status.edited', defaultMessage: 'Edited {date}' },
});
Expand Down Expand Up @@ -405,6 +406,7 @@ class Status extends ImmutablePureComponent {
'limited': { icon: 'get-pocket', text: intl.formatMessage(messages.limited_short) },
'mutual': { icon: 'exchange', text: intl.formatMessage(messages.mutual_short) },
'circle': { icon: 'user-circle', text: intl.formatMessage(messages.circle_short) },
'personal': { icon: 'sticky-note-o', text: intl.formatMessage(messages.personal_short) },
'direct': { icon: 'at', text: intl.formatMessage(messages.direct_short) },
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const messages = defineMessages({
limited_short: { id: 'privacy.limited.short', defaultMessage: 'Limited menbers only' },
mutual_short: { id: 'privacy.mutual.short', defaultMessage: 'Mutual followers only' },
circle_short: { id: 'privacy.circle.short', defaultMessage: 'Circle members only' },
personal_short: { id: 'privacy.personal.short', defaultMessage: 'Yourself only' },
direct_short: { id: 'privacy.direct.short', defaultMessage: 'Mentioned people only' },
});

Expand Down Expand Up @@ -57,6 +58,7 @@ class StatusCheckBox extends PureComponent {
'limited': { icon: 'get-pocket', text: intl.formatMessage(messages.limited_short) },
'mutual': { icon: 'exchange', text: intl.formatMessage(messages.mutual_short) },
'circle': { icon: 'user-circle', text: intl.formatMessage(messages.circle_short) },
'personal': { icon: 'sticky-note-o', text: intl.formatMessage(messages.personal_short) },
'direct': { icon: 'at', text: intl.formatMessage(messages.direct_short) },
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const messages = defineMessages({
limited_short: { id: 'privacy.limited.short', defaultMessage: 'Limited menbers only' },
mutual_short: { id: 'privacy.mutual.short', defaultMessage: 'Mutual followers only' },
circle_short: { id: 'privacy.circle.short', defaultMessage: 'Circle members only' },
personal_short: { id: 'privacy.personal.short', defaultMessage: 'Yourself only' },
direct_short: { id: 'privacy.direct.short', defaultMessage: 'Mentioned people only' },
searchability_public_short: { id: 'searchability.public.short', defaultMessage: 'Public' },
searchability_private_short: { id: 'searchability.unlisted.short', defaultMessage: 'Followers' },
Expand Down Expand Up @@ -260,6 +261,7 @@ class DetailedStatus extends ImmutablePureComponent {
'limited': { icon: 'get-pocket', text: intl.formatMessage(messages.limited_short) },
'mutual': { icon: 'exchange', text: intl.formatMessage(messages.mutual_short) },
'circle': { icon: 'user-circle', text: intl.formatMessage(messages.circle_short) },
'personal': { icon: 'sticky-note-o', text: intl.formatMessage(messages.personal_short) },
'direct': { icon: 'at', text: intl.formatMessage(messages.direct_short) },
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const messages = defineMessages({
limited_short: { id: 'privacy.limited.short', defaultMessage: 'Limited menbers only' },
mutual_short: { id: 'privacy.mutual.short', defaultMessage: 'Mutual followers only' },
circle_short: { id: 'privacy.circle.short', defaultMessage: 'Circle members only' },
personal_short: { id: 'privacy.personal.short', defaultMessage: 'Yourself only' },
direct_short: { id: 'privacy.direct.short', defaultMessage: 'Mentioned people only' },
});

Expand Down Expand Up @@ -100,6 +101,7 @@ class BoostModal extends ImmutablePureComponent {
'limited': { icon: 'get-pocket', text: intl.formatMessage(messages.limited_short) },
'mutual': { icon: 'exchange', text: intl.formatMessage(messages.mutual_short) },
'circle': { icon: 'user-circle', text: intl.formatMessage(messages.circle_short) },
'personal': { icon: 'sticky-note-o', text: intl.formatMessage(messages.personal_short) },
'direct': { icon: 'at', text: intl.formatMessage(messages.direct_short) },
};

Expand Down
2 changes: 1 addition & 1 deletion app/models/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Status < ApplicationRecord

enum visibility: { public: 0, unlisted: 1, private: 2, direct: 3, limited: 4, public_unlisted: 10, login: 11 }, _suffix: :visibility
enum searchability: { public: 0, private: 1, direct: 2, limited: 3, unsupported: 4, public_unlisted: 10 }, _suffix: :searchability
enum limited_scope: { none: 0, mutual: 1, circle: 2 }, _suffix: :limited
enum limited_scope: { none: 0, mutual: 1, circle: 2, personal: 3 }, _suffix: :limited

belongs_to :application, class_name: 'Doorkeeper::Application', optional: true

Expand Down
4 changes: 3 additions & 1 deletion app/services/post_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ def process_status!
process_mentions_service.call(@status, limited_type: @status.limited_visibility? ? @limited_scope : '', circle: @circle, save_records: false)
safeguard_mentions!(@status)

@status.limited_scope = :personal if @status.limited_visibility? && !process_mentions_service.mentions?

UpdateStatusExpirationService.new.call(@status)

# The following transaction block is needed to wrap the UPDATEs to
Expand Down Expand Up @@ -221,7 +223,7 @@ def validate_media!
end

def process_mentions_service
ProcessMentionsService.new
@process_mentions_service ||= ProcessMentionsService.new
end

def process_hashtags_service
Expand Down
4 changes: 4 additions & 0 deletions app/services/process_mentions_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def call(status, limited_type: '', circle: nil, save_records: true)
end
end

def mentions?
@current_mentions.present?
end

private

def scan_text!
Expand Down
23 changes: 23 additions & 0 deletions spec/services/post_status_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@
expect(status.mentioned_accounts.first.id).to eq mutual_account.id
end

it 'personal visibility with mutual' do
account = Fabricate(:account)
text = 'This is an English text.'

status = subject.call(account, text: text, visibility: 'mutual')

expect(status.visibility).to eq 'limited'
expect(status.limited_scope).to eq 'personal'
expect(status.mentioned_accounts.count).to eq 0
end

it 'circle visibility' do
account = Fabricate(:account)
circle_account = Fabricate(:account)
Expand Down Expand Up @@ -227,6 +238,18 @@
expect { subject.call(account, text: text, visibility: 'limited') }.to raise_exception ActiveRecord::RecordInvalid
end

it 'personal visibility with circle' do
account = Fabricate(:account)
circle = Fabricate(:circle, account: account)
text = 'This is an English text.'

status = subject.call(account, text: text, visibility: 'circle', circle_id: circle.id)

expect(status.visibility).to eq 'limited'
expect(status.limited_scope).to eq 'personal'
expect(status.mentioned_accounts.count).to eq 0
end

it 'safeguards mentions' do
account = Fabricate(:account)
mentioned_account = Fabricate(:account, username: 'alice')
Expand Down

0 comments on commit 002c4bf

Please sign in to comment.