Add abilityto add oneself to lists (#12271)

* Add ability to add oneself to lists

* Change search results to include oneself when searching through followers

* Mark follow relation as optional in ListAccount
This commit is contained in:
ThibG 2019-11-04 13:02:01 +01:00 committed by Eugen Rochko
parent 1a12943924
commit 65e13cfacf
5 changed files with 14 additions and 7 deletions

View file

@ -429,6 +429,8 @@ class Account < ApplicationRecord
SELECT target_account_id
FROM follows
WHERE account_id = ?
UNION ALL
SELECT ?
)
SELECT
accounts.*,
@ -444,7 +446,7 @@ class Account < ApplicationRecord
LIMIT ? OFFSET ?
SQL
records = find_by_sql([sql, account.id, account.id, account.id, limit, offset])
records = find_by_sql([sql, account.id, account.id, account.id, account.id, limit, offset])
else
sql = <<-SQL.squish
SELECT

View file

@ -6,13 +6,13 @@
# id :bigint(8) not null, primary key
# list_id :bigint(8) not null
# account_id :bigint(8) not null
# follow_id :bigint(8) not null
# follow_id :bigint(8)
#
class ListAccount < ApplicationRecord
belongs_to :list
belongs_to :account
belongs_to :follow
belongs_to :follow, optional: true
validates :account_id, uniqueness: { scope: :list_id }
@ -21,6 +21,6 @@ class ListAccount < ApplicationRecord
private
def set_follow
self.follow = Follow.find_by(account_id: list.account_id, target_account_id: account.id)
self.follow = Follow.find_by!(account_id: list.account_id, target_account_id: account.id) unless list.account_id == account.id
end
end