diff --git a/app/javascript/mastodon/actions/interactions.js b/app/javascript/mastodon/actions/interactions.js index 9963e150a..920094d5e 100644 --- a/app/javascript/mastodon/actions/interactions.js +++ b/app/javascript/mastodon/actions/interactions.js @@ -552,14 +552,16 @@ export function emojiReactionFail(status, name, domain, url, static_url, error) }; 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) { 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)); api(getState).post(`/api/v1/statuses/${status.get('id')}/emoji_unreaction`).then(function (response) { diff --git a/app/models/announcement.rb b/app/models/announcement.rb index f8183aabc..1481282f2 100644 --- a/app/models/announcement.rb +++ b/app/models/announcement.rb @@ -75,7 +75,7 @@ class Announcement < ApplicationRecord if account.nil? scope.select('name, custom_emoji_id, count(*) as count, false as me') 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 diff --git a/app/models/status.rb b/app/models/status.rb index a800793f2..8e52474ac 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -326,7 +326,7 @@ class Status < ApplicationRecord if account.nil? scope.select('name, custom_emoji_id, count(*) as count, false as me') 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 ActiveRecord::Associations::Preloader.new.preload(records, :custom_emoji)