Add ability to filter followed accounts' posts by language (#19095)
This commit is contained in:
parent
882e54c786
commit
50948b46aa
30 changed files with 298 additions and 39 deletions
|
@ -9,6 +9,7 @@ module AccountInteractions
|
|||
mapping[follow.target_account_id] = {
|
||||
reblogs: follow.show_reblogs?,
|
||||
notify: follow.notify?,
|
||||
languages: follow.languages,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@ -38,6 +39,7 @@ module AccountInteractions
|
|||
mapping[follow_request.target_account_id] = {
|
||||
reblogs: follow_request.show_reblogs?,
|
||||
notify: follow_request.notify?,
|
||||
languages: follow_request.languages,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@ -100,12 +102,13 @@ module AccountInteractions
|
|||
has_many :announcement_mutes, dependent: :destroy
|
||||
end
|
||||
|
||||
def follow!(other_account, reblogs: nil, notify: nil, uri: nil, rate_limit: false, bypass_limit: false)
|
||||
rel = active_relationships.create_with(show_reblogs: reblogs.nil? ? true : reblogs, notify: notify.nil? ? false : notify, uri: uri, rate_limit: rate_limit, bypass_follow_limit: bypass_limit)
|
||||
def follow!(other_account, reblogs: nil, notify: nil, languages: nil, uri: nil, rate_limit: false, bypass_limit: false)
|
||||
rel = active_relationships.create_with(show_reblogs: reblogs.nil? ? true : reblogs, notify: notify.nil? ? false : notify, languages: languages, uri: uri, rate_limit: rate_limit, bypass_follow_limit: bypass_limit)
|
||||
.find_or_create_by!(target_account: other_account)
|
||||
|
||||
rel.show_reblogs = reblogs unless reblogs.nil?
|
||||
rel.notify = notify unless notify.nil?
|
||||
rel.show_reblogs = reblogs unless reblogs.nil?
|
||||
rel.notify = notify unless notify.nil?
|
||||
rel.languages = languages unless languages.nil?
|
||||
|
||||
rel.save! if rel.changed?
|
||||
|
||||
|
@ -114,12 +117,13 @@ module AccountInteractions
|
|||
rel
|
||||
end
|
||||
|
||||
def request_follow!(other_account, reblogs: nil, notify: nil, uri: nil, rate_limit: false, bypass_limit: false)
|
||||
rel = follow_requests.create_with(show_reblogs: reblogs.nil? ? true : reblogs, notify: notify.nil? ? false : notify, uri: uri, rate_limit: rate_limit, bypass_follow_limit: bypass_limit)
|
||||
def request_follow!(other_account, reblogs: nil, notify: nil, languages: nil, uri: nil, rate_limit: false, bypass_limit: false)
|
||||
rel = follow_requests.create_with(show_reblogs: reblogs.nil? ? true : reblogs, notify: notify.nil? ? false : notify, uri: uri, languages: languages, rate_limit: rate_limit, bypass_follow_limit: bypass_limit)
|
||||
.find_or_create_by!(target_account: other_account)
|
||||
|
||||
rel.show_reblogs = reblogs unless reblogs.nil?
|
||||
rel.notify = notify unless notify.nil?
|
||||
rel.show_reblogs = reblogs unless reblogs.nil?
|
||||
rel.notify = notify unless notify.nil?
|
||||
rel.languages = languages unless languages.nil?
|
||||
|
||||
rel.save! if rel.changed?
|
||||
|
||||
|
@ -288,8 +292,7 @@ module AccountInteractions
|
|||
|
||||
private
|
||||
|
||||
def remove_potential_friendship(other_account, mutual = false)
|
||||
def remove_potential_friendship(other_account)
|
||||
PotentialFriendshipTracker.remove(id, other_account.id)
|
||||
PotentialFriendshipTracker.remove(other_account.id, id) if mutual
|
||||
end
|
||||
end
|
||||
|
|
|
@ -30,9 +30,9 @@ class Export
|
|||
end
|
||||
|
||||
def to_following_accounts_csv
|
||||
CSV.generate(headers: ['Account address', 'Show boosts'], write_headers: true) do |csv|
|
||||
CSV.generate(headers: ['Account address', 'Show boosts', 'Notify on new posts', 'Languages'], write_headers: true) do |csv|
|
||||
account.active_relationships.includes(:target_account).reorder(id: :desc).each do |follow|
|
||||
csv << [acct(follow.target_account), follow.show_reblogs]
|
||||
csv << [acct(follow.target_account), follow.show_reblogs, follow.notify, follow.languages&.join(', ')]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
# show_reblogs :boolean default(TRUE), not null
|
||||
# uri :string
|
||||
# notify :boolean default(FALSE), not null
|
||||
# languages :string is an Array
|
||||
#
|
||||
|
||||
class Follow < ApplicationRecord
|
||||
|
@ -27,6 +28,7 @@ class Follow < ApplicationRecord
|
|||
has_one :notification, as: :activity, dependent: :destroy
|
||||
|
||||
validates :account_id, uniqueness: { scope: :target_account_id }
|
||||
validates :languages, language: true
|
||||
|
||||
scope :recent, -> { reorder(id: :desc) }
|
||||
|
||||
|
@ -35,7 +37,7 @@ class Follow < ApplicationRecord
|
|||
end
|
||||
|
||||
def revoke_request!
|
||||
FollowRequest.create!(account: account, target_account: target_account, show_reblogs: show_reblogs, notify: notify, uri: uri)
|
||||
FollowRequest.create!(account: account, target_account: target_account, show_reblogs: show_reblogs, notify: notify, languages: languages, uri: uri)
|
||||
destroy!
|
||||
end
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
# show_reblogs :boolean default(TRUE), not null
|
||||
# uri :string
|
||||
# notify :boolean default(FALSE), not null
|
||||
# languages :string is an Array
|
||||
#
|
||||
|
||||
class FollowRequest < ApplicationRecord
|
||||
|
@ -27,9 +28,10 @@ class FollowRequest < ApplicationRecord
|
|||
has_one :notification, as: :activity, dependent: :destroy
|
||||
|
||||
validates :account_id, uniqueness: { scope: :target_account_id }
|
||||
validates :languages, language: true
|
||||
|
||||
def authorize!
|
||||
account.follow!(target_account, reblogs: show_reblogs, notify: notify, uri: uri, bypass_limit: true)
|
||||
account.follow!(target_account, reblogs: show_reblogs, notify: notify, languages: languages, uri: uri, bypass_limit: true)
|
||||
MergeWorker.perform_async(target_account.id, account.id) if account.local?
|
||||
destroy!
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue