Add emoji_reactioned_by_slim api (not work)
This commit is contained in:
parent
a1485f242d
commit
9ad51e001e
8 changed files with 98 additions and 3 deletions
|
@ -0,0 +1,28 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Api::V1::Statuses::EmojiReactionedByAccountsSlimController < Api::BaseController
|
||||
include Authorization
|
||||
|
||||
before_action -> { authorize_if_got_token! :read, :'read:accounts' }
|
||||
before_action :set_status
|
||||
|
||||
def index
|
||||
@accounts = load_emoji_reactions
|
||||
|
||||
# TODO for serialize hash object
|
||||
render json: @accounts, each_serializer: REST::EmojiReactedBySlimSerializer
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_emoji_reactions
|
||||
@status.generate_emoji_reactions_grouped_by_account
|
||||
end
|
||||
|
||||
def set_status
|
||||
@status = Status.find(params[:status_id])
|
||||
authorize @status, :show?
|
||||
rescue Mastodon::NotPermittedError
|
||||
not_found
|
||||
end
|
||||
end
|
|
@ -69,7 +69,6 @@ class EmojiReactions extends ImmutablePureComponent {
|
|||
if (!groups[key]) groups[key] = [value];
|
||||
else groups[key].push(value);
|
||||
}
|
||||
console.dir(groups)
|
||||
|
||||
const emptyMessage = <FormattedMessage id='empty_column.emoji_reactions' defaultMessage='No one has reacted with emoji this post yet. When someone does, they will show up here.' />;
|
||||
|
||||
|
|
|
@ -136,8 +136,6 @@ export default function userLists(state = initialState, action) {
|
|||
case FAVOURITES_FETCH_SUCCESS:
|
||||
return state.setIn(['favourited_by', action.id], ImmutableList(action.accounts.map(item => item.id)));
|
||||
case EMOJI_REACTIONS_FETCH_SUCCESS:
|
||||
console.log('===================')
|
||||
console.dir(state);
|
||||
return state.setIn(['emoji_reactioned_by', action.id], ImmutableList(action.accounts));
|
||||
case NOTIFICATIONS_UPDATE:
|
||||
return action.notification.type === 'follow_request' ? normalizeFollowRequest(state, action.notification) : state;
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
# ordered_media_attachment_ids :bigint(8) is an Array
|
||||
#
|
||||
|
||||
require 'ostruct'
|
||||
|
||||
class Status < ApplicationRecord
|
||||
before_destroy :unlink_from_conversations!
|
||||
|
||||
|
@ -312,6 +314,11 @@ class Status < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def generate_emoji_reactions_grouped_by_account
|
||||
# TODO for serializer
|
||||
EmojiReaction.where(status_id: id).group_by(&:account)
|
||||
end
|
||||
|
||||
def trendable?
|
||||
if attributes['trendable'].nil?
|
||||
account.trendable?
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
class StatusEmojiReactionsGroupedByAccountObject
|
||||
def initialize(account, emoji_reactions)
|
||||
@account = account
|
||||
@emoji_reactions = emoji_reactions
|
||||
end
|
||||
|
||||
def read_attribute_for_serialization(_)
|
||||
REST::EmojiReactedBySlimSerializer
|
||||
end
|
||||
|
||||
def model_name
|
||||
'EmojiReaction'
|
||||
end
|
||||
end
|
|
@ -0,0 +1,27 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class REST::EmojiReactedBySlimReactionSerializer < ActiveModel::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :name
|
||||
|
||||
attribute :url, if: :custom_emoji?
|
||||
attribute :static_url, if: :custom_emoji?
|
||||
attribute :domain, if: :custom_emoji?
|
||||
|
||||
def url
|
||||
full_asset_url(object.custom_emoji.image.url)
|
||||
end
|
||||
|
||||
def static_url
|
||||
full_asset_url(object.custom_emoji.image.url(:static))
|
||||
end
|
||||
|
||||
def domain
|
||||
object.custom_emoji.domain
|
||||
end
|
||||
|
||||
def custom_emoji?
|
||||
object.custom_emoji.present?
|
||||
end
|
||||
end
|
21
app/serializers/rest/emoji_reacted_by_slim_serializer.rb
Normal file
21
app/serializers/rest/emoji_reacted_by_slim_serializer.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class REST::EmojiReactedBySlimSerializer < ActiveModel::Serializer
|
||||
|
||||
belongs_to :account, serializer: REST::AccountSerializer
|
||||
has_many :emoji_reactions, serializer: REST::EmojiReactedBySlimReactionSerializer
|
||||
|
||||
def attributes
|
||||
{ account => emoji_reactions }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def account
|
||||
object.first
|
||||
end
|
||||
|
||||
def emoji_reactions
|
||||
object.last
|
||||
end
|
||||
end
|
|
@ -441,6 +441,7 @@ Rails.application.routes.draw do
|
|||
resources :reblogged_by, controller: :reblogged_by_accounts, only: :index
|
||||
resources :favourited_by, controller: :favourited_by_accounts, only: :index
|
||||
resources :emoji_reactioned_by, controller: :emoji_reactioned_by_accounts, only: :index
|
||||
resources :emoji_reactioned_by_slim, controller: :emoji_reactioned_by_accounts_slim, only: :index
|
||||
resource :reblog, only: :create
|
||||
post :unreblog, to: 'reblogs#destroy'
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue