about summary refs log tree commit diff
path: root/app/models/status.rb
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-11-13 23:02:10 +0100
committerEugen Rochko <eugen@zeonfederated.com>2019-11-13 23:02:10 +0100
commitdfea7368c934f600bd0b6b93b4a6c008a4e265b0 (patch)
tree9db2db756c89b70ec5f01b782b787465d4b45b07 /app/models/status.rb
parentafb398b583b23c139c5a069c1281550bb69760e0 (diff)
Add bookmarks (#7107)
* Add backend support for bookmarks

Bookmarks behave like favourites, except they aren't shared with other
users and do not have an associated counter.

* Add spec for bookmark endpoints

* Add front-end support for bookmarks

* Introduce OAuth scopes for bookmarks

* Add bookmarks to archive takeout

* Fix migration

* Coding style fixes

* Fix rebase issue

* Update bookmarked_statuses to latest UI changes

* Update bookmark actions to properly reflect status changes in state

* Add bookmarks item to single-column layout

* Make active bookmarks red
Diffstat (limited to 'app/models/status.rb')
-rw-r--r--app/models/status.rb5
1 files changed, 5 insertions, 0 deletions
diff --git a/app/models/status.rb b/app/models/status.rb
index 0c01a5389..1cb381400 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -54,6 +54,7 @@ class Status < ApplicationRecord
   belongs_to :reblog, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblogs, 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, inverse_of: :status
@@ -302,6 +303,10 @@ class Status < ApplicationRecord
       Favourite.select('status_id').where(status_id: status_ids).where(account_id: account_id).each_with_object({}) { |f, h| h[f.status_id] = true }
     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)
       unscoped.select('reblog_of_id').where(reblog_of_id: status_ids).where(account_id: account_id).each_with_object({}) { |s, h| h[s.reblog_of_id] = true }
     end