diff --git a/app/services/update_status_service.rb b/app/services/update_status_service.rb index 6e63fa97421051..0a5de6b907b3bf 100644 --- a/app/services/update_status_service.rb +++ b/app/services/update_status_service.rb @@ -167,7 +167,13 @@ def update_references! def update_metadata! ProcessHashtagsService.new.call(@status) - ProcessMentionsService.new.call(@status) + process_mentions_service.call(@status) + + @status.update(limited_scope: :circle) if process_mentions_service.mentions? + end + + def process_mentions_service + @process_mentions_service ||= ProcessMentionsService.new end def broadcast_updates! diff --git a/spec/services/post_status_service_spec.rb b/spec/services/post_status_service_spec.rb index 2e513b9ca40ef9..5e2a54c264a30f 100644 --- a/spec/services/post_status_service_spec.rb +++ b/spec/services/post_status_service_spec.rb @@ -250,6 +250,19 @@ expect(status.mentioned_accounts.count).to eq 0 end + it 'using empty circle but with mention' do + account = Fabricate(:account) + Fabricate(:account, username: 'bob', domain: nil) + circle = Fabricate(:circle, account: account) + text = 'This is an English text. @bob' + + status = subject.call(account, text: text, visibility: 'circle', circle_id: circle.id) + + expect(status.visibility).to eq 'limited' + expect(status.limited_scope).to eq 'circle' + expect(status.mentioned_accounts.count).to eq 1 + end + it 'safeguards mentions' do account = Fabricate(:account) mentioned_account = Fabricate(:account, username: 'alice') diff --git a/spec/services/update_status_service_spec.rb b/spec/services/update_status_service_spec.rb index 9c53ebb2fd8271..288466bdeb784a 100644 --- a/spec/services/update_status_service_spec.rb +++ b/spec/services/update_status_service_spec.rb @@ -166,6 +166,39 @@ end end + context 'when personal_limited mentions in text change' do + let!(:account) { Fabricate(:account) } + let!(:bob) { Fabricate(:account, username: 'bob') } + let!(:status) { PostStatusService.new.call(account, text: 'Hello', visibility: 'circle', circle_id: Fabricate(:circle, account: account).id) } + + before do + subject.call(status, status.account_id, text: 'Hello @bob') + end + + it 'changes mentions' do + expect(status.active_mentions.pluck(:account_id)).to eq [bob.id] + end + + it 'changes visibilities' do + expect(status.visibility).to eq 'limited' + expect(status.limited_scope).to eq 'circle' + end + end + + context 'when personal_limited in text change' do + let!(:account) { Fabricate(:account) } + let!(:status) { PostStatusService.new.call(account, text: 'Hello', visibility: 'circle', circle_id: Fabricate(:circle, account: account).id) } + + before do + subject.call(status, status.account_id, text: 'AAA') + end + + it 'not changing visibilities' do + expect(status.visibility).to eq 'limited' + expect(status.limited_scope).to eq 'personal' + end + end + context 'when hashtags in text change' do let!(:account) { Fabricate(:account) } let!(:status) { PostStatusService.new.call(account, text: 'Hello #foo') }