Fix emoji_reactions in API response status so that my unicode emoji reaction is me

This commit is contained in:
noellabo 2021-06-08 11:17:49 +09:00
parent 933485dcec
commit 523b769258
3 changed files with 7 additions and 5 deletions

View file

@ -552,14 +552,16 @@ export function emojiReactionFail(status, name, domain, url, static_url, error)
}; };
const findMyEmojiReaction = (status) => { const findMyEmojiReaction = (status) => {
return status.get('emoji_reactions').find(emoji_reaction => emoji_reaction.get('me') === true) ?? {}; return status.get('emoji_reactions').find(emoji_reaction => emoji_reaction.get('me') === true);
}; };
export function removeEmojiReaction(status) { export function removeEmojiReaction(status) {
return function (dispatch, getState) { return function (dispatch, getState) {
const {name, domain, url, static_url} = findMyEmojiReaction(status).toObject(); const emoji_reaction = findMyEmojiReaction(status);
if (emoji_reaction) {
const {name, domain, url, static_url} = emoji_reaction.toObject();
if (name) {
dispatch(unEmojiReactionRequest(status, name, domain, url, static_url)); dispatch(unEmojiReactionRequest(status, name, domain, url, static_url));
api(getState).post(`/api/v1/statuses/${status.get('id')}/emoji_unreaction`).then(function (response) { api(getState).post(`/api/v1/statuses/${status.get('id')}/emoji_unreaction`).then(function (response) {

View file

@ -75,7 +75,7 @@ class Announcement < ApplicationRecord
if account.nil? if account.nil?
scope.select('name, custom_emoji_id, count(*) as count, false as me') scope.select('name, custom_emoji_id, count(*) as count, false as me')
else else
scope.select("name, custom_emoji_id, count(*) as count, exists(select 1 from announcement_reactions r where r.account_id = #{account.id} and r.announcement_id = announcement_reactions.announcement_id and r.name = announcement_reactions.name) as me") scope.select(ActiveRecord::Base.sanitize_sql_array(["name, custom_emoji_id, count(*) as count, exists(select 1 from announcement_reactions r where r.account_id = :account_id and r.announcement_id = announcement_reactions.announcement_id and r.name = announcement_reactions.name) as me", account_id: account.id]))
end end
end end

View file

@ -326,7 +326,7 @@ class Status < ApplicationRecord
if account.nil? if account.nil?
scope.select('name, custom_emoji_id, count(*) as count, false as me') scope.select('name, custom_emoji_id, count(*) as count, false as me')
else else
scope.select("name, custom_emoji_id, count(*) as count, exists(select 1 from emoji_reactions r where r.account_id = #{account.id} and r.status_id = emoji_reactions.status_id and r.name = emoji_reactions.name and r.custom_emoji_id = emoji_reactions.custom_emoji_id) as me") scope.select(ActiveRecord::Base.sanitize_sql_array(["name, custom_emoji_id, count(*) as count, exists(select 1 from emoji_reactions r where r.account_id = :account_id and r.status_id = emoji_reactions.status_id and r.name = emoji_reactions.name and (r.custom_emoji_id IS NULL and emoji_reactions.custom_emoji_id IS NULL or r.custom_emoji_id = emoji_reactions.custom_emoji_id)) as me", account_id: account.id]))
end end
end end
ActiveRecord::Associations::Preloader.new.preload(records, :custom_emoji) ActiveRecord::Associations::Preloader.new.preload(records, :custom_emoji)