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

@ -0,0 +1,69 @@
# frozen_string_literal: true
class Api::V1::BookmarksController < Api::BaseController
before_action -> { doorkeeper_authorize! :read, :'read:bookmarks' }
before_action :require_user!
after_action :insert_pagination_headers
respond_to :json
def index
@statuses = []
if current_account.is_pro
@statuses = load_statuses
end
render json: @statuses, each_serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new(@statuses, current_user&.account_id)
end
private
def load_statuses
cached_bookmarks
end
def cached_bookmarks
cache_collection(
Status.reorder(nil).joins(:status_bookmarks).merge(results),
Status
)
end
def results
@_results ||= account_bookmarks.paginate_by_id(
limit_param(DEFAULT_STATUSES_LIMIT),
params_slice(:max_id, :since_id, :min_id)
)
end
def account_bookmarks
current_account.status_bookmarks
end
def insert_pagination_headers
set_pagination_headers(next_path, prev_path)
end
def next_path
api_v1_bookmarks_url pagination_params(max_id: pagination_max_id) if records_continue?
end
def prev_path
api_v1_bookmarks_url pagination_params(since_id: pagination_since_id) unless results.empty?
end
def pagination_max_id
results.last.id
end
def pagination_since_id
results.first.id
end
def records_continue?
results.size == limit_param(DEFAULT_STATUSES_LIMIT)
end
def pagination_params(core_params)
params.slice(:limit).permit(:limit).merge(core_params)
end
end

View File

@ -0,0 +1,47 @@
# frozen_string_literal: true
class Api::V1::Statuses::BookmarksController < Api::BaseController
include Authorization
before_action -> { doorkeeper_authorize! :write, :'write:bookmarks' }
before_action :require_user!
respond_to :json
def create
if current_user.account.is_pro
@status = bookmarked_status
render json: @status, serializer: REST::StatusSerializer
else
render json: { error: 'You need to be a GabPRO member to access this' }, status: 422
end
end
def destroy
if current_user.account.is_pro
@status = requested_status
@bookmarks_map = { @status.id => false }
bookmark = StatusBookmark.find_by!(account: current_user.account, status: @status)
bookmark.destroy!
render json: @status, serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new([@status], current_user&.account_id, bookmarks_map: @bookmarks_map)
else
render json: { error: 'You need to be a GabPRO member to access this' }, status: 422
end
end
private
def bookmarked_status
authorize_with current_user.account, requested_status, :show?
bookmark = StatusBookmark.find_or_create_by!(account: current_user.account, status: requested_status)
bookmark.status.reload
end
def requested_status
Status.find(params[:status_id])
end
end

View File

@ -0,0 +1,98 @@
import api, { getLinks } from '../api'
import { importFetchedStatuses } from './importer'
import { me } from '../initial_state'
export const BOOKMARKED_STATUSES_FETCH_REQUEST = 'BOOKMARKED_STATUSES_FETCH_REQUEST'
export const BOOKMARKED_STATUSES_FETCH_SUCCESS = 'BOOKMARKED_STATUSES_FETCH_SUCCESS'
export const BOOKMARKED_STATUSES_FETCH_FAIL = 'BOOKMARKED_STATUSES_FETCH_FAIL'
export const BOOKMARKED_STATUSES_EXPAND_REQUEST = 'BOOKMARKED_STATUSES_EXPAND_REQUEST'
export const BOOKMARKED_STATUSES_EXPAND_SUCCESS = 'BOOKMARKED_STATUSES_EXPAND_SUCCESS'
export const BOOKMARKED_STATUSES_EXPAND_FAIL = 'BOOKMARKED_STATUSES_EXPAND_FAIL'
export function fetchBookmarkedStatuses() {
return (dispatch, getState) => {
if (!me) return
if (getState().getIn(['status_lists', 'bookmarks', 'isLoading'])) {
return
}
dispatch(fetchBookmarkedStatusesRequest())
api(getState).get('/api/v1/bookmarks').then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next')
dispatch(importFetchedStatuses(response.data))
dispatch(fetchBookmarkedStatusesSuccess(response.data, next ? next.uri : null))
}).catch(error => {
dispatch(fetchBookmarkedStatusesFail(error))
})
}
}
export function fetchBookmarkedStatusesRequest() {
return {
type: BOOKMARKED_STATUSES_FETCH_REQUEST,
skipLoading: true,
}
}
export function fetchBookmarkedStatusesSuccess(statuses, next) {
return {
type: BOOKMARKED_STATUSES_FETCH_SUCCESS,
statuses,
next,
skipLoading: true,
}
}
export function fetchBookmarkedStatusesFail(error) {
return {
type: BOOKMARKED_STATUSES_FETCH_FAIL,
error,
skipLoading: true,
}
}
export function expandBookmarkedStatuses() {
return (dispatch, getState) => {
if (!me) return
const url = getState().getIn(['status_lists', 'bookmarks', 'next'], null)
if (url === null || getState().getIn(['status_lists', 'bookmarks', 'isLoading'])) {
return
}
dispatch(expandBookmarkedStatusesRequest())
api(getState).get(url).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next')
dispatch(importFetchedStatuses(response.data))
dispatch(expandBookmarkedStatusesSuccess(response.data, next ? next.uri : null))
}).catch(error => {
dispatch(expandBookmarkedStatusesFail(error))
})
}
}
export function expandBookmarkedStatusesRequest() {
return {
type: BOOKMARKED_STATUSES_EXPAND_REQUEST,
}
}
export function expandBookmarkedStatusesSuccess(statuses, next) {
return {
type: BOOKMARKED_STATUSES_EXPAND_SUCCESS,
statuses,
next,
}
}
export function expandBookmarkedStatusesFail(error) {
return {
type: BOOKMARKED_STATUSES_EXPAND_FAIL,
error,
}
}

View File

@ -30,6 +30,14 @@ export const UNPIN_REQUEST = 'UNPIN_REQUEST';
export const UNPIN_SUCCESS = 'UNPIN_SUCCESS';
export const UNPIN_FAIL = 'UNPIN_FAIL';
export const BOOKMARK_REQUEST = 'BOOKMARK_REQUEST'
export const BOOKMARK_SUCCESS = 'BOOKMARK_SUCCESS'
export const BOOKMARK_FAIL = 'BOOKMARK_FAIL'
export const UNBOOKMARK_REQUEST = 'UNBOOKMARK_REQUEST'
export const UNBOOKMARK_SUCCESS = 'UNBOOKMARK_SUCCESS'
export const UNBOOKMARK_FAIL = 'UNBOOKMARK_FAIL'
export const LIKES_FETCH_REQUEST = 'LIKES_FETCH_REQUEST';
export const LIKES_FETCH_SUCCESS = 'LIKES_FETCH_SUCCESS';
export const LIKES_FETCH_FAIL = 'LIKES_FETCH_FAIL';
@ -346,4 +354,76 @@ export function fetchLikesFail(id, error) {
type: LIKES_FETCH_FAIL,
error,
};
};
};
export function bookmark(status) {
return function (dispatch, getState) {
dispatch(bookmarkRequest(status));
api(getState).post(`/api/v1/statuses/${status.get('id')}/bookmark`).then(function (response) {
dispatch(importFetchedStatus(response.data));
dispatch(bookmarkSuccess(status, response.data));
}).catch(function (error) {
dispatch(bookmarkFail(status, error))
})
}
}
export function unbookmark(status) {
return (dispatch, getState) => {
dispatch(unbookmarkRequest(status))
api(getState).post(`/api/v1/statuses/${status.get('id')}/unbookmark`).then(response => {
dispatch(importFetchedStatus(response.data))
dispatch(unbookmarkSuccess(status, response.data))
}).catch(error => {
dispatch(unbookmarkFail(status, error))
})
}
}
export function bookmarkRequest(status) {
return {
type: BOOKMARK_REQUEST,
status: status,
}
}
export function bookmarkSuccess(status, response) {
return {
type: BOOKMARK_SUCCESS,
status: status,
response: response,
}
}
export function bookmarkFail(status, error) {
return {
type: BOOKMARK_FAIL,
status: status,
error: error,
}
}
export function unbookmarkRequest(status) {
return {
type: UNBOOKMARK_REQUEST,
status: status,
}
}
export function unbookmarkSuccess(status, response) {
return {
type: UNBOOKMARK_SUCCESS,
status: status,
response: response,
}
}
export function unbookmarkFail(status, error) {
return {
type: UNBOOKMARK_FAIL,
status: status,
error: error,
}
}

View File

@ -0,0 +1,24 @@
const BookmarkIcon = ({
className = '',
size = '16px',
title = 'Bookmark',
}) => (
<svg
className={className}
version='1.1'
xmlns='http://www.w3.org/2000/svg'
x='0px'
y='0px'
width={size}
height={size}
viewBox='0 0 48 48'
xmlSpace='preserve'
aria-label={title}
>
<g>
<path d='M 39.06 0 L 8.94 0 C 8.16 0 7.53 0.63 7.53 1.41 L 7.53 46.59 C 7.53 47.16 7.88 47.68 8.4 47.89 C 8.57 47.96 8.76 48 8.94 48 C 9.3 48 9.66 47.86 9.93 47.59 L 24 33.52 L 38.07 47.59 C 38.47 47.99 39.07 48.11 39.6 47.89 C 40.13 47.68 40.47 47.16 40.47 46.59 L 40.47 1.41 C 40.47 0.63 39.84 0 39.06 0 Z M 39.06 0' />
</g>
</svg>
)
export default BookmarkIcon

View File

@ -11,6 +11,7 @@ import BackIcon from '../assets/back_icon'
import BlockIcon from '../assets/block_icon'
import BlockquoteIcon from '../assets/blockquote_icon'
import BoldIcon from '../assets/bold_icon'
import BookmarkIcon from '../assets/bookmark_icon'
import CalendarIcon from '../assets/calendar_icon'
import ChatIcon from '../assets/chat_icon'
import CheckIcon from '../assets/check_icon'
@ -93,6 +94,7 @@ const ICONS = {
'block': BlockIcon,
'blockquote': BlockquoteIcon,
'bold': BoldIcon,
'bookmark': BookmarkIcon,
'calendar': CalendarIcon,
'chat': ChatIcon,
'check': CheckIcon,

View File

@ -7,6 +7,8 @@ import {
unrepost,
pin,
unpin,
bookmark,
unbookmark,
} from '../../actions/interactions';
import {
muteStatus,
@ -24,7 +26,10 @@ import { initMuteModal } from '../../actions/mutes'
import { initReport } from '../../actions/reports'
import { openModal } from '../../actions/modal'
import { closePopover } from '../../actions/popover'
import { MODAL_EMBED } from '../../constants'
import {
MODAL_EMBED,
MODAL_PRO_UPGRADE,
} from '../../constants'
import PopoverLayout from './popover_layout'
import List from '../list'
@ -49,6 +54,8 @@ const messages = defineMessages({
unmuteConversation: { id: 'status.unmute_conversation', defaultMessage: 'Unmute conversation' },
pin: { id: 'status.pin', defaultMessage: 'Pin on profile' },
unpin: { id: 'status.unpin', defaultMessage: 'Unpin from profile' },
bookmark: { id: 'status.bookmark', defaultMessage: 'Bookmark status' },
unbookmark: { id: 'status.unbookmark', defaultMessage: 'Remove bookmark' },
admin_account: { id: 'status.admin_account', defaultMessage: 'Open moderation interface for @{name}' },
admin_status: { id: 'status.admin_status', defaultMessage: 'Open this status in the moderation interface' },
group_remove_account: { id: 'status.remove_account_from_group', defaultMessage: 'Remove account from group' },
@ -68,6 +75,7 @@ const mapStateToProps = (state, { status }) => {
return {
groupId,
groupRelationships,
isPro: state.getIn(['accounts', me, 'is_pro']),
}
}
@ -93,6 +101,16 @@ const mapDispatchToProps = (dispatch) => ({
}
},
onBookmark(status) {
dispatch(closePopover())
if (status.get('bookmarked')) {
dispatch(unbookmark(status))
} else {
dispatch(bookmark(status))
}
},
onQuote(status, router) {
dispatch(closePopover())
@ -186,6 +204,11 @@ const mapDispatchToProps = (dispatch) => ({
}))
},
onOpenProUpgradeModal() {
dispatch(closePopover())
dispatch(openModal(MODAL_PRO_UPGRADE))
},
onClosePopover: () => dispatch(closePopover()),
})
@ -213,8 +236,10 @@ class StatusOptionsPopover extends ImmutablePureComponent {
intl: PropTypes.object.isRequired,
onFetchGroupRelationships: PropTypes.func.isRequired,
onOpenEmbedModal: PropTypes.func.isRequired,
onOpenProUpgradeModal: PropTypes.func.isRequired,
onClosePopover: PropTypes.func.isRequired,
isXS: PropTypes.bool,
isPro: PropTypes.bool,
}
updateOnProps = [
@ -261,6 +286,14 @@ class StatusOptionsPopover extends ImmutablePureComponent {
this.props.onPin(this.props.status)
}
handleBookmarkClick = () => {
if (this.props.isPro) {
this.props.onBookmark(this.props.status)
} else {
this.props.onOpenProUpgradeModal()
}
}
handleDeleteClick = () => {
this.props.onDelete(this.props.status)
}
@ -346,6 +379,13 @@ class StatusOptionsPopover extends ImmutablePureComponent {
})
}
menu.push({
icon: 'bookmark',
hideArrow: true,
title: intl.formatMessage(status.get('bookmarked') ? messages.unbookmark : messages.bookmark),
onClick: this.handleBookmarkClick,
})
if (status.getIn(['account', 'id']) === me) {
if (publicStatus) {
menu.push({
@ -355,7 +395,7 @@ class StatusOptionsPopover extends ImmutablePureComponent {
onClick: this.handlePinClick,
})
}
menu.push({
icon: 'trash',
hideArrow: true,

View File

@ -0,0 +1,59 @@
import ImmutablePropTypes from 'react-immutable-proptypes'
import { FormattedMessage } from 'react-intl'
import ImmutablePureComponent from 'react-immutable-pure-component'
import debounce from 'lodash.debounce'
import { fetchBookmarkedStatuses, expandBookmarkedStatuses } from '../actions/bookmarks'
import { meUsername } from '../initial_state'
import StatusList from '../components/status_list'
import ColumnIndicator from '../components/column_indicator'
const mapStateToProps = (state, { params: { username } }) => {
return {
isMyAccount: (username.toLowerCase() === meUsername.toLowerCase()),
statusIds: state.getIn(['status_lists', 'bookmarks', 'items']),
isLoading: state.getIn(['status_lists', 'bookmarks', 'isLoading'], true),
hasMore: !!state.getIn(['status_lists', 'bookmarks', 'next']),
}
}
export default
@connect(mapStateToProps)
class BookmarkedStatuses extends ImmutablePureComponent {
static propTypes = {
dispatch: PropTypes.func.isRequired,
statusIds: ImmutablePropTypes.list.isRequired,
hasMore: PropTypes.bool,
isLoading: PropTypes.bool,
isMyAccount: PropTypes.bool.isRequired,
}
componentWillMount() {
this.props.dispatch(fetchBookmarkedStatuses())
}
handleLoadMore = debounce(() => {
this.props.dispatch(expandBookmarkedStatuses())
}, 300, { leading: true })
render() {
const { statusIds, hasMore, isLoading, isMyAccount } = this.props
if (!isMyAccount) {
return <ColumnIndicator type='missing' />
}
return (
<StatusList
statusIds={statusIds}
scrollKey='bookmarked_statuses'
hasMore={hasMore}
isLoading={isLoading}
onLoadMore={this.handleLoadMore}
emptyMessage={<FormattedMessage id='empty_column.bookmarked_statuses' defaultMessage="You don't have any bookmarked gabs yet. If you are GabPRO, when you bookmark one, it will show up here." />}
/>
)
}
}

View File

@ -48,6 +48,7 @@ import {
AccountTimeline,
BlockedAccounts,
BlockedDomains,
BookmarkedStatuses,
CommunityTimeline,
Compose,
DMCA,
@ -228,6 +229,9 @@ class SwitchingArea extends PureComponent {
<Redirect from='/@:username/likes' to='/:username/likes' />
<WrappedRoute path='/:username/likes' page={ProfilePage} component={LikedStatuses} content={children} />
<Redirect from='/@:username/bookmarks' to='/:username/bookmarks' />
<WrappedRoute path='/:username/bookmarks' page={ProfilePage} component={BookmarkedStatuses} content={children} />
<Redirect from='/@:username/posts/:statusId' to='/:username/posts/:statusId' exact />
<WrappedRoute path='/:username/posts/:statusId' publicRoute exact page={BasicPage} component={StatusFeature} content={children} componentParams={{ title: 'Status', page: 'status' }} />

View File

@ -3,6 +3,7 @@ export function AccountTimeline() { return import(/* webpackChunkName: "features
export function AccountGallery() { return import(/* webpackChunkName: "features/account_gallery" */'../../account_gallery') }
export function BlockAccountModal() { return import(/* webpackChunkName: "components/block_account_modal" */'../../../components/modal/block_account_modal') }
export function BlockedAccounts() { return import(/* webpackChunkName: "features/blocked_accounts" */'../../blocked_accounts') }
export function BookmarkedStatuses() { return import(/* webpackChunkName: "features/bookmarked_statuses" */'../../bookmarked_statuses') }
export function BoostModal() { return import(/* webpackChunkName: "components/boost_modal" */'../../../components/modal/boost_modal') }
export function CommentSortingOptionsPopover() { return import(/* webpackChunkName: "components/comment_sorting_options_popover" */'../../../components/popover/comment_sorting_options_popover') }
export function CommunityTimeline() { return import(/* webpackChunkName: "features/community_timeline" */'../../community_timeline') }

View File

@ -6,15 +6,30 @@ import {
FAVORITED_STATUSES_EXPAND_SUCCESS,
FAVORITED_STATUSES_EXPAND_FAIL,
} from '../actions/favorites';
import {
BOOKMARKED_STATUSES_FETCH_REQUEST,
BOOKMARKED_STATUSES_FETCH_SUCCESS,
BOOKMARKED_STATUSES_FETCH_FAIL,
BOOKMARKED_STATUSES_EXPAND_REQUEST,
BOOKMARKED_STATUSES_EXPAND_SUCCESS,
BOOKMARKED_STATUSES_EXPAND_FAIL,
} from '../actions/bookmarks'
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
import {
FAVORITE_SUCCESS,
UNFAVORITE_SUCCESS,
PIN_SUCCESS,
UNPIN_SUCCESS,
BOOKMARK_SUCCESS,
UNBOOKMARK_SUCCESS,
} from '../actions/interactions';
const initialState = ImmutableMap({
bookmarks: ImmutableMap({
next: null,
loaded: false,
items: ImmutableList(),
}),
favorites: ImmutableMap({
next: null,
loaded: false,
@ -57,7 +72,17 @@ const removeOneFromList = (state, listType, status) => {
};
export default function statusLists(state = initialState, action) {
switch(action.type) {
switch (action.type) {
case BOOKMARKED_STATUSES_FETCH_REQUEST:
case BOOKMARKED_STATUSES_EXPAND_REQUEST:
return state.setIn(['bookmarks', 'isLoading'], true);
case BOOKMARKED_STATUSES_FETCH_FAIL:
case BOOKMARKED_STATUSES_EXPAND_FAIL:
return state.setIn(['bookmarks', 'isLoading'], false);
case BOOKMARKED_STATUSES_FETCH_SUCCESS:
return normalizeList(state, 'bookmarks', action.statuses, action.next);
case BOOKMARKED_STATUSES_EXPAND_SUCCESS:
return appendToList(state, 'bookmarks', action.statuses, action.next);
case FAVORITED_STATUSES_FETCH_REQUEST:
case FAVORITED_STATUSES_EXPAND_REQUEST:
return state.setIn(['favorites', 'isLoading'], true);
@ -76,6 +101,10 @@ export default function statusLists(state = initialState, action) {
return prependOneToList(state, 'pins', action.status);
case UNPIN_SUCCESS:
return removeOneFromList(state, 'pins', action.status);
case BOOKMARK_SUCCESS:
return prependOneToList(state, 'bookmarks', action.status);
case UNBOOKMARK_SUCCESS:
return removeOneFromList(state, 'bookmarks', action.status);
default:
return state;
}

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

View File

@ -1,13 +1,15 @@
# frozen_string_literal: true
class StatusRelationshipsPresenter
attr_reader :reblogs_map, :favourites_map, :mutes_map, :pins_map
attr_reader :reblogs_map, :favourites_map, :mutes_map, :pins_map, :bookmarks_map
def initialize(statuses, current_account_id = nil, **options)
if current_account_id.nil?
@reblogs_map = {}
@favourites_map = {}
@mutes_map = {}
@bookmarks_map = {}
@pins_map = {}
else
statuses = statuses.compact
@ -18,6 +20,7 @@ class StatusRelationshipsPresenter
@reblogs_map = Status.reblogs_map(status_ids, current_account_id).merge(options[:reblogs_map] || {})
@favourites_map = Status.favourites_map(status_ids, current_account_id).merge(options[:favourites_map] || {})
@mutes_map = Status.mutes_map(conversation_ids, current_account_id).merge(options[:mutes_map] || {})
@bookmarks_map = Status.bookmarks_map(status_ids, current_account_id).merge(options[:bookmarks_map] || {})
@pins_map = Status.pins_map(pinnable_status_ids, current_account_id).merge(options[:pins_map] || {})
end
end

View File

@ -9,6 +9,7 @@ class REST::StatusSerializer < ActiveModel::Serializer
attribute :favourited, if: :current_user?
attribute :reblogged, if: :current_user?
attribute :muted, if: :current_user?
attribute :bookmarked, if: :current_user?
attribute :pinned, if: :pinnable?
attribute :content, unless: :source_requested?
@ -117,6 +118,14 @@ class REST::StatusSerializer < ActiveModel::Serializer
end
end
def bookmarked
if instance_options && instance_options[:relationships]
instance_options[:relationships].bookmarks_map[object.id] || false
else
current_user.account.bookmarked?(object)
end
end
def pinned
if instance_options && instance_options[:relationships]
instance_options[:relationships].pins_map[object.id] || false

View File

@ -21,6 +21,7 @@ class SuspendAccountService < BaseService
passive_relationships
report_notes
scheduled_statuses
status_bookmarks
status_pins
stream_entries
subscriptions

View File

@ -58,6 +58,7 @@ Doorkeeper.configure do
optional_scopes :write,
:'write:accounts',
:'write:blocks',
:'write:bookmarks',
:'write:conversations',
:'write:favourites',
:'write:filters',
@ -71,6 +72,7 @@ Doorkeeper.configure do
:read,
:'read:accounts',
:'read:blocks',
:'read:bookmarks',
:'read:favourites',
:'read:filters',
:'read:follows',

View File

@ -119,6 +119,7 @@ en:
read: read all your account's data
read:accounts: see accounts information
read:blocks: see your blocks
read:bookmarks: see your bookmarks
read:favourites: see your favorites
read:filters: see your filters
read:follows: see your follows
@ -131,6 +132,7 @@ en:
write: modify all your account's data
write:accounts: modify your profile
write:blocks: block accounts and domains
write:bookmarks: bookmark statuses
write:favourites: favorite statuses
write:filters: create filters
write:follows: follow people

View File

@ -302,6 +302,9 @@ Rails.application.routes.draw do
resource :favourite, only: :create
post :unfavourite, to: 'favourites#destroy'
resource :bookmark, only: :create
post :unbookmark, to: 'bookmarks#destroy'
resource :mute, only: :create
post :unmute, to: 'mutes#destroy'
@ -360,6 +363,7 @@ Rails.application.routes.draw do
resources :filters, only: [:index, :create, :show, :update, :destroy]
resources :endorsements, only: [:index]
resources :shortcuts, only: [:index, :create, :show, :destroy]
resources :bookmarks, only: [:index]
namespace :apps do
get :verify_credentials, to: 'credentials#show'

View File

@ -0,0 +1,11 @@
class CreateStatusBookmark < ActiveRecord::Migration[5.2]
def change
create_table :status_bookmarks do |t|
t.timestamps
t.belongs_to :account, foreign_key: { on_delete: :cascade }, null: false
t.belongs_to :status, foreign_key: { on_delete: :cascade }, null: false
end
add_index :status_bookmarks, [:account_id, :status_id], unique: true
end
end