summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2021-11-05 21:14:35 +0100
committerEugen Rochko <eugen@zeonfederated.com>2021-11-06 00:07:17 +0100
commitf60bb0784fdf2ac67582ba4e96779acc078d9902 (patch)
tree850c49d585a59d3c4ae0568986664a31e6066bcd
parentc3a6f7b9411a86a8fce71ef99d8801d8930bb8f0 (diff)
Fix handling announcements with links (#16941)
Broken since #15827
-rw-r--r--app/models/status.rb2
-rw-r--r--spec/workers/publish_scheduled_announcement_worker_spec.rb26
2 files changed, 27 insertions, 1 deletions
diff --git a/app/models/status.rb b/app/models/status.rb
index 3acf759f9de..c7f761bc6ba 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -338,7 +338,7 @@ class Status < ApplicationRecord
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)
diff --git a/spec/workers/publish_scheduled_announcement_worker_spec.rb b/spec/workers/publish_scheduled_announcement_worker_spec.rb
new file mode 100644
index 00000000000..0977bba1ee1
--- /dev/null
+++ b/spec/workers/publish_scheduled_announcement_worker_spec.rb
@@ -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