Fix unlike counter, fixes #107
This commit is contained in:
parent
817063fd14
commit
d78dd971c0
|
@ -19,7 +19,7 @@ class Api::V1::Statuses::FavouritesController < Api::BaseController
|
|||
|
||||
UnfavouriteWorker.perform_async(current_user.account_id, @status.id)
|
||||
|
||||
render json: @status, serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new([@status], current_user&.account_id, favourites_map: @favourites_map)
|
||||
render json: @status, serializer: REST::StatusSerializer, unfavourite: true, relationships: StatusRelationshipsPresenter.new([@status], current_user&.account_id, favourites_map: @favourites_map)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -3,6 +3,7 @@ import {
|
|||
REBLOG_FAIL,
|
||||
FAVORITE_REQUEST,
|
||||
FAVORITE_FAIL,
|
||||
UNFAVORITE_REQUEST,
|
||||
} from '../actions/interactions';
|
||||
import {
|
||||
STATUS_MUTE_SUCCESS,
|
||||
|
@ -39,6 +40,8 @@ export default function statuses(state = initialState, action) {
|
|||
return state.setIn([action.status.get('id'), 'favourited'], true);
|
||||
case FAVORITE_FAIL:
|
||||
return state.get(action.status.get('id')) === undefined ? state : state.setIn([action.status.get('id'), 'favourited'], false);
|
||||
case UNFAVORITE_REQUEST:
|
||||
return state.setIn([action.status.get('id'), 'favourited'], false);
|
||||
case REBLOG_REQUEST:
|
||||
return state.setIn([action.status.get('id'), 'reblogged'], true);
|
||||
case REBLOG_FAIL:
|
||||
|
|
|
@ -83,6 +83,16 @@ class REST::StatusSerializer < ActiveModel::Serializer
|
|||
end
|
||||
end
|
||||
|
||||
def favourites_count
|
||||
if instance_options && instance_options[:unfavourite]
|
||||
# Decrement counter
|
||||
# https://github.com/tootsuite/mastodon/issues/3166
|
||||
object.favourites_count - 1
|
||||
else
|
||||
object.favourites_count
|
||||
end
|
||||
end
|
||||
|
||||
def reblogged
|
||||
if instance_options && instance_options[:relationships]
|
||||
instance_options[:relationships].reblogs_map[object.id] || false
|
||||
|
|
Loading…
Reference in New Issue