From 50eb8f1f613df0a2379565f5f5eabd8acc110f15 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Tue, 10 Apr 2018 22:13:15 +0200 Subject: Add backend support for bookmarks Bookmarks behave like favourites, except they aren't shared with other users and do not have an associated counter. --- app/models/status.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'app/models/status.rb') diff --git a/app/models/status.rb b/app/models/status.rb index 7e5ca09e4..34b41d347 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -46,6 +46,7 @@ class Status < ApplicationRecord belongs_to :reblog, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblogs, counter_cache: :reblogs_count, optional: true has_many :favourites, inverse_of: :status, dependent: :destroy + has_many :bookmarks, inverse_of: :status, dependent: :destroy has_many :reblogs, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblog, dependent: :destroy has_many :replies, foreign_key: 'in_reply_to_id', class_name: 'Status', inverse_of: :thread has_many :mentions, dependent: :destroy @@ -216,6 +217,10 @@ class Status < ApplicationRecord Favourite.select('status_id').where(status_id: status_ids).where(account_id: account_id).map { |f| [f.status_id, true] }.to_h end + def bookmarks_map(status_ids, account_id) + Bookmark.select('status_id').where(status_id: status_ids).where(account_id: account_id).map { |f| [f.status_id, true] }.to_h + end + def reblogs_map(status_ids, account_id) select('reblog_of_id').where(reblog_of_id: status_ids).where(account_id: account_id).reorder(nil).map { |s| [s.reblog_of_id, true] }.to_h end -- cgit