Added bookmarks

• Added:
- bookmarks for GabPRO members only
- migration for creation of StatusBookmarks
- all necessary routes, controllers
- redux for adding, removing, fetching and displaying bookmarks
- bookmark icon
- doorkeeper scopes
- backend and frontend support

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

dfea7368c9
This commit is contained in:
mgabdev
2020-07-24 18:48:31 -05:00
parent 763466ab86
commit 13af58da7a
22 changed files with 528 additions and 5 deletions

View File

@@ -19,6 +19,10 @@ module AccountAssociations
has_many :conversations, class_name: 'AccountConversation', dependent: :destroy, inverse_of: :account
has_many :scheduled_statuses, inverse_of: :account, dependent: :destroy
# Pinned statuses
has_many :status_bookmarks, inverse_of: :account, dependent: :destroy
has_many :bookmarked_statuses, -> { reorder('status_bookmarks.created_at DESC') }, through: :status_bookmarks, class_name: 'Status', source: :status
# Pinned statuses
has_many :status_pins, inverse_of: :account, dependent: :destroy
has_many :pinned_statuses, -> { reorder('status_pins.created_at DESC') }, through: :status_pins, class_name: 'Status', source: :status

View File

@@ -189,6 +189,10 @@ module AccountInteractions
status.proper.favourites.where(account: self).exists?
end
def bookmarked?(status)
status_bookmarks.where(account: self).exists?
end
def reblogged?(status)
status.proper.reblogs.where(account: self).exists?
end

View File

@@ -26,6 +26,7 @@
# quote_of_id :bigint(8)
# revised_at :datetime
# markdown :text
# expires_at :datetime
#
class Status < ApplicationRecord
@@ -57,6 +58,7 @@ class Status < ApplicationRecord
belongs_to :quote, foreign_key: 'quote_of_id', class_name: 'Status', inverse_of: :quotes, optional: true
has_many :favourites, inverse_of: :status, dependent: :destroy
has_many :status_bookmarks, inverse_of: :status, dependent: :destroy
has_many :reblogs, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblog, dependent: :destroy
has_many :quotes, foreign_key: 'quote_of_id', class_name: 'Status', inverse_of: :quote, dependent: :nullify
has_many :replies, foreign_key: 'in_reply_to_id', class_name: 'Status', inverse_of: :thread
@@ -365,6 +367,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)
StatusBookmark.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).each_with_object({}) { |s, h| h[s.reblog_of_id] = true }
end

View File

@@ -0,0 +1,24 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: status_bookmarks
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# account_id :integer not null
# status_id :integer not null
#
class StatusBookmark < ApplicationRecord
include Paginable
belongs_to :account, inverse_of: :status_bookmarks
belongs_to :status, inverse_of: :status_bookmarks
validates :status_id, uniqueness: { scope: :account_id }
before_validation do
self.status = status.reblog if status&.reblog?
end
end