From 8fada4fae25592e24f709faff41b0dedf6d5e36f Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 28 Feb 2016 14:33:13 +0100 Subject: [PATCH] When posting a status or reblogging one, ping hubs about the feed update --- app/models/account.rb | 5 +++++ app/services/post_status_service.rb | 1 + app/services/reblog_service.rb | 1 + spec/models/account_spec.rb | 4 ++++ 4 files changed, 11 insertions(+) diff --git a/app/models/account.rb b/app/models/account.rb index f1ac6fdd76d..e9fc03a1003 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -65,6 +65,11 @@ class Account < ActiveRecord::Base @subscription ||= OStatus2::Subscription.new(self.remote_url, secret: self.secret, token: self.verify_token, webhook: webhook_url, hub: self.hub_url) end + def ping!(atom_url, hubs) + return unless local? + OStatus2::Publication.new(atom_url, hubs).publish + end + def avatar_remote_url=(url) self.avatar = URI.parse(url) @avatar_remote_url = url diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index 17cc8e32313..64519a4003d 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -7,6 +7,7 @@ class PostStatusService < BaseService def call(account, text, in_reply_to = nil) status = account.statuses.create!(text: text, thread: in_reply_to) process_mentions_service.(status) + account.ping!(atom_user_stream_url(id: account.id), HUB_URL) status end diff --git a/app/services/reblog_service.rb b/app/services/reblog_service.rb index 000ed8ee673..66b7634fb08 100644 --- a/app/services/reblog_service.rb +++ b/app/services/reblog_service.rb @@ -5,6 +5,7 @@ class ReblogService < BaseService # @return [Status] def call(account, reblogged_status) reblog = account.statuses.create!(reblog: reblogged_status, text: '') + account.ping!(atom_user_stream_url(id: account.id), HUB_URL) return reblog if reblogged_status.local? send_interaction_service.(reblog.stream_entry, reblogged_status.account) reblog diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index a5f24a99053..562989335a2 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -107,4 +107,8 @@ RSpec.describe Account, type: :model do expect(subject.content).to eql subject.note end end + + describe '#ping!' do + pending + end end