Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Fix handling announcements with links (mastodon#16941)
Browse files Browse the repository at this point in the history
Broken since mastodon#15827
  • Loading branch information
ClearlyClaire authored Nov 5, 2021
1 parent 458830e commit 989c67d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def permitted_for(target_account, account)
def from_text(text)
return [] if text.blank?

text.scan(FetchLinkCardService::URL_PATTERN).map(&:first).uniq.filter_map do |url|
text.scan(FetchLinkCardService::URL_PATTERN).map(&:second).uniq.filter_map do |url|
status = begin
if TagManager.instance.local_url?(url)
ActivityPub::TagManager.instance.uri_to_resource(url, Status)
Expand Down
26 changes: 26 additions & 0 deletions spec/workers/publish_scheduled_announcement_worker_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require 'rails_helper'

describe PublishScheduledAnnouncementWorker do
subject { described_class.new }

let!(:remote_account) { Fabricate(:account, domain: 'domain.com', username: 'foo', uri: 'https://domain.com/users/foo') }
let!(:remote_status) { Fabricate(:status, uri: 'https://domain.com/users/foo/12345', account: remote_account) }
let!(:local_status) { Fabricate(:status) }
let(:scheduled_announcement) { Fabricate(:announcement, text: "rebooting very soon, see #{ActivityPub::TagManager.instance.uri_for(remote_status)} and #{ActivityPub::TagManager.instance.uri_for(local_status)}") }

describe 'perform' do
before do
service = double
allow(FetchRemoteStatusService).to receive(:new).and_return(service)
allow(service).to receive(:call).with('https://domain.com/users/foo/12345') { remote_status.reload }

subject.perform(scheduled_announcement.id)
end

it 'updates the linked statuses' do
expect(scheduled_announcement.reload.status_ids).to eq [remote_status.id, local_status.id]
end
end
end

0 comments on commit 989c67d

Please sign in to comment.