return if target_account.nil? || !target_account.local? || delete_arrived_first?(@json['id']) || @account.blocking?(target_account)
UnfollowService.new.call(target_account, @account) if target_account.following?(@account)
- @account.block!(target_account)
+ @account.block!(target_account, uri: @json['id'])
end
end
return
end
- follow_request = FollowRequest.create!(account: @account, target_account: target_account)
+ follow_request = FollowRequest.create!(account: @account, target_account: target_account, uri: @json['id'])
if target_account.locked?
NotifyService.new.call(target_account, follow_request)
end
end
+ def generate_uri_for(_target)
+ URI.join(root_url, 'payloads', SecureRandom.uuid)
+ end
+
def activity_uri_for(target)
raise ArgumentError, 'target must be a local activity' unless %i(note comment activity).include?(target.object_type) && target.local?
# updated_at :datetime not null
# account_id :bigint(8) not null
# target_account_id :bigint(8) not null
+# uri :string
#
class Block < ApplicationRecord
validates :account_id, uniqueness: { scope: :target_account_id }
+ def local?
+ false # Force uri_for to use uri attribute
+ end
+
after_commit :remove_blocking_cache
+ before_validation :set_uri, only: :create
private
Rails.cache.delete("exclude_account_ids_for:#{account_id}")
Rails.cache.delete("exclude_account_ids_for:#{target_account_id}")
end
+
+ def set_uri
+ self.uri = ActivityPub::TagManager.instance.generate_uri_for(self) if uri.nil?
+ end
end
has_many :domain_blocks, class_name: 'AccountDomainBlock', dependent: :destroy
end
- def follow!(other_account, reblogs: nil)
+ def follow!(other_account, reblogs: nil, uri: nil)
reblogs = true if reblogs.nil?
- rel = active_relationships.create_with(show_reblogs: reblogs).find_or_create_by!(target_account: other_account)
- rel.update!(show_reblogs: reblogs)
+ rel = active_relationships.create_with(show_reblogs: reblogs, uri: uri)
+ .find_or_create_by!(target_account: other_account)
+
+ rel.update!(show_reblogs: reblogs)
rel
end
- def block!(other_account)
- block_relationships.find_or_create_by!(target_account: other_account)
+ def block!(other_account, uri: nil)
+ block_relationships.create_with(uri: uri)
+ .find_or_create_by!(target_account: other_account)
end
def mute!(other_account, notifications: nil)
# account_id :bigint(8) not null
# target_account_id :bigint(8) not null
# show_reblogs :boolean default(TRUE), not null
+# uri :string
#
class Follow < ApplicationRecord
validates :account_id, uniqueness: { scope: :target_account_id }
scope :recent, -> { reorder(id: :desc) }
+
+ def local?
+ false # Force uri_for to use uri attribute
+ end
+
+ before_validation :set_uri, only: :create
+
+ private
+
+ def set_uri
+ self.uri = ActivityPub::TagManager.instance.generate_uri_for(self) if uri.nil?
+ end
end
# account_id :bigint(8) not null
# target_account_id :bigint(8) not null
# show_reblogs :boolean default(TRUE), not null
+# uri :string
#
class FollowRequest < ApplicationRecord
validates :account_id, uniqueness: { scope: :target_account_id }
def authorize!
- account.follow!(target_account, reblogs: show_reblogs)
+ account.follow!(target_account, reblogs: show_reblogs, uri: uri)
MergeWorker.perform_async(target_account.id, account.id)
-
destroy!
end
alias reject! destroy!
+
+ def local?
+ false # Force uri_for to use uri attribute
+ end
+
+ before_validation :set_uri, only: :create
+
+ private
+
+ def set_uri
+ self.uri = ActivityPub::TagManager.instance.generate_uri_for(self) if uri.nil?
+ end
end
attribute :virtual_object, key: :object
def id
- [ActivityPub::TagManager.instance.uri_for(object.account), '#follows/', object.id].join
+ ActivityPub::TagManager.instance.uri_for(object)
end
def type
--- /dev/null
+class AddUriToRelationships < ActiveRecord::Migration[5.2]
+ def change
+ add_column :follows, :uri, :string
+ add_column :follow_requests, :uri, :string
+ add_column :blocks, :uri, :string
+ end
+end
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2018_04_10_204633) do
+ActiveRecord::Schema.define(version: 2018_04_16_210259) do
# These are extensions that must be enabled in order to support this database
- enable_extension "pg_stat_statements"
enable_extension "plpgsql"
create_table "account_domain_blocks", force: :cascade do |t|
t.datetime "updated_at", null: false
t.bigint "account_id", null: false
t.bigint "target_account_id", null: false
+ t.string "uri"
t.index ["account_id", "target_account_id"], name: "index_blocks_on_account_id_and_target_account_id", unique: true
end
t.bigint "account_id", null: false
t.bigint "target_account_id", null: false
t.boolean "show_reblogs", default: true, null: false
+ t.string "uri"
t.index ["account_id", "target_account_id"], name: "index_follow_requests_on_account_id_and_target_account_id", unique: true
end
t.bigint "account_id", null: false
t.bigint "target_account_id", null: false
t.boolean "show_reblogs", default: true, null: false
+ t.string "uri"
t.index ["account_id", "target_account_id"], name: "index_follows_on_account_id_and_target_account_id", unique: true
end
let(:target_account) { Fabricate(:account) }
it 'calls Account#follow!, MergeWorker.perform_async, and #destroy!' do
- expect(account).to receive(:follow!).with(target_account, reblogs: true)
+ expect(account).to receive(:follow!).with(target_account, reblogs: true, uri: follow_request.uri)
expect(MergeWorker).to receive(:perform_async).with(target_account.id, account.id)
expect(follow_request).to receive(:destroy!)
follow_request.authorize!