mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-26 10:11:37 +01:00
Port three new emoji reaction PR commits to Catstodon:
"Update reaction emails
Reaction icon made by @t3rminus@calamity.world"
"Simplify reactions API controller"
"Refactor status reactions query
This was done to announcement reactions in 1b0cb3b54d
. Might as well do it here too."
This commit is contained in:
parent
93ae46fa14
commit
ae854b8027
7 changed files with 50 additions and 72 deletions
|
@ -1,11 +1,8 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Api::V1::Statuses::ReactionsController < Api::BaseController
|
class Api::V1::Statuses::ReactionsController < Api::V1::Statuses::BaseController
|
||||||
include Authorization
|
|
||||||
|
|
||||||
before_action -> { doorkeeper_authorize! :write, :'write:favourites' }
|
before_action -> { doorkeeper_authorize! :write, :'write:favourites' }
|
||||||
before_action :require_user!
|
before_action :require_user!
|
||||||
before_action :set_status
|
|
||||||
|
|
||||||
def create
|
def create
|
||||||
ReactService.new.call(current_account, @status, params[:id])
|
ReactService.new.call(current_account, @status, params[:id])
|
||||||
|
@ -19,13 +16,4 @@ class Api::V1::Statuses::ReactionsController < Api::BaseController
|
||||||
rescue Mastodon::NotPermittedError
|
rescue Mastodon::NotPermittedError
|
||||||
not_found
|
not_found
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def set_status
|
|
||||||
@status = Status.find(params[:status_id])
|
|
||||||
authorize @status, :show?
|
|
||||||
rescue Mastodon::NotPermittedError
|
|
||||||
not_found
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
BIN
app/javascript/images/mailer-new/heading/reaction.png
Normal file
BIN
app/javascript/images/mailer-new/heading/reaction.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
|
@ -1 +1 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M460-80q-92 0-156-64t-64-156v-420q0-66 47-113t113-47q66 0 113 47t47 113v380q0 42-29 71t-71 29q-42 0-71-29t-29-71v-380h60v380q0 17 11.5 28.5T460-300q17 0 28.5-11.5T500-340v-380q0-42-29-71t-71-29q-42 0-71 29t-29 71v420q0 66 47 113t113 47q66 0 113-47t47-113v-420h60v420q0 92-64 156T460-80Z"/></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M720-330q0 104-73 177T470-80q-104 0-177-73t-73-177v-370q0-75 52.5-127.5T400-880q75 0 127.5 52.5T580-700v350q0 46-32 78t-78 32q-46 0-78-32t-32-78v-370h80v370q0 13 8.5 21.5T470-320q13 0 21.5-8.5T500-350v-350q-1-42-29.5-71T400-800q-42 0-71 29t-29 71v370q-1 71 49 120.5T470-160q70 0 119-49.5T640-330v-390h80v390Z"/></svg>
|
Before Width: | Height: | Size: 392 B After Width: | Height: | Size: 414 B |
|
@ -1 +1 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M460-80q-92 0-156-64t-64-156v-420q0-66 47-113t113-47q66 0 113 47t47 113v380q0 42-29 71t-71 29q-42 0-71-29t-29-71v-380h60v380q0 17 11.5 28.5T460-300q17 0 28.5-11.5T500-340v-380q0-42-29-71t-71-29q-42 0-71 29t-29 71v420q0 66 47 113t113 47q66 0 113-47t47-113v-420h60v420q0 92-64 156T460-80Z"/></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M720-330q0 104-73 177T470-80q-104 0-177-73t-73-177v-370q0-75 52.5-127.5T400-880q75 0 127.5 52.5T580-700v350q0 46-32 78t-78 32q-46 0-78-32t-32-78v-370h80v370q0 13 8.5 21.5T470-320q13 0 21.5-8.5T500-350v-350q-1-42-29.5-71T400-800q-42 0-71 29t-29 71v370q-1 71 49 120.5T470-160q70 0 119-49.5T640-330v-390h80v390Z"/></svg>
|
Before Width: | Height: | Size: 392 B After Width: | Height: | Size: 414 B |
|
@ -282,20 +282,13 @@ class Status < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def reactions(account = nil)
|
def reactions(account = nil)
|
||||||
records = begin
|
grouped_ordered_status_reactions.select(
|
||||||
scope = status_reactions.group(:status_id, :name, :custom_emoji_id).order(Arel.sql('MIN(created_at) ASC'))
|
[:name, :custom_emoji_id, 'COUNT(*) as count'].tap do |values|
|
||||||
|
values << value_for_reaction_me_column(account)
|
||||||
if account.nil?
|
|
||||||
scope.select('name, custom_emoji_id, count(*) as count, false as me')
|
|
||||||
else
|
|
||||||
# rubocop:disable Layout/LineLength
|
|
||||||
scope.select("name, custom_emoji_id, count(*) as count, exists(select 1 from status_reactions r where r.account_id = #{account.id} and r.status_id = status_reactions.status_id and r.name = status_reactions.name and (r.custom_emoji_id = status_reactions.custom_emoji_id or r.custom_emoji_id is null and status_reactions.custom_emoji_id is null)) as me")
|
|
||||||
# rubocop:enable Layout/LineLength
|
|
||||||
end
|
end
|
||||||
|
).to_a.tap do |records|
|
||||||
|
ActiveRecord::Associations::Preloader.new(records: records, associations: :custom_emoji).call
|
||||||
end
|
end
|
||||||
|
|
||||||
ActiveRecord::Associations::Preloader.new(records: records, associations: :custom_emoji)
|
|
||||||
records
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def ordered_media_attachments
|
def ordered_media_attachments
|
||||||
|
@ -485,6 +478,35 @@ class Status < ApplicationRecord
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def grouped_ordered_status_reactions
|
||||||
|
status_reactions
|
||||||
|
.group(:status_id, :name, :custom_emoji_id)
|
||||||
|
.order(
|
||||||
|
Arel.sql('MIN(created_at)').asc
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def value_for_reaction_me_column(account)
|
||||||
|
if account.nil?
|
||||||
|
'FALSE AS me'
|
||||||
|
else
|
||||||
|
<<~SQL.squish
|
||||||
|
EXISTS(
|
||||||
|
SELECT 1
|
||||||
|
FROM status_reactions inner_reactions
|
||||||
|
WHERE inner_reactions.account_id = #{account.id}
|
||||||
|
AND inner_reactions.status_id = status_reactions.status_id
|
||||||
|
AND inner_reactions.name = status_reactions.name
|
||||||
|
AND (
|
||||||
|
inner_reactions.custom_emoji_id = status_reactions.custom_emoji_id
|
||||||
|
OR inner_reactions.custom_emoji_id IS NULL
|
||||||
|
AND status_reactions.custom_emoji_id IS NULL
|
||||||
|
)
|
||||||
|
) AS me
|
||||||
|
SQL
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def update_status_stat!(attrs)
|
def update_status_stat!(attrs)
|
||||||
return if marked_for_destruction? || destroyed?
|
return if marked_for_destruction? || destroyed?
|
||||||
|
|
||||||
|
|
|
@ -1,45 +1,13 @@
|
||||||
%table.email-table{ cellspacing: 0, cellpadding: 0 }
|
= content_for :heading do
|
||||||
%tbody
|
= render 'application/mailer/heading', heading_title: t('notification_mailer.reaction.title'), heading_subtitle: t('notification_mailer.reaction.body', name: @account.pretty_acct), heading_image_url: frontend_asset_url('images/mailer-new/heading/reaction.png')
|
||||||
%tr
|
%table.email-w-full{ cellspacing: 0, cellpadding: 0, border: 0, role: 'presentation' }
|
||||||
%td.email-body
|
%tr
|
||||||
.email-container
|
%td.email-body-padding-td
|
||||||
%table.content-section{ cellspacing: 0, cellpadding: 0 }
|
%table.email-inner-card-table{ cellspacing: 0, cellpadding: 0, border: 0, role: 'presentation' }
|
||||||
%tbody
|
%tr
|
||||||
|
%td.email-inner-card-td
|
||||||
|
= render 'status', status: @status, time_zone: @me.user_time_zone
|
||||||
|
%table.email-w-full{ cellspacing: 0, cellpadding: 0, border: 0, role: 'presentation' }
|
||||||
%tr
|
%tr
|
||||||
%td.content-cell.hero
|
%td.email-padding-top-24
|
||||||
.email-row
|
= render 'application/mailer/button', text: t('application_mailer.view_status'), url: web_url("@#{@status.account.pretty_acct}/#{@status.id}")
|
||||||
.col-6
|
|
||||||
%table.column{ cellspacing: 0, cellpadding: 0 }
|
|
||||||
%tbody
|
|
||||||
%tr
|
|
||||||
%td.column-cell.text-center.padded
|
|
||||||
%table.hero-icon{ align: 'center', cellspacing: 0, cellpadding: 0 }
|
|
||||||
%tbody
|
|
||||||
%tr
|
|
||||||
%td
|
|
||||||
= image_tag full_pack_url('media/images/mailer/icon_add.png'), alt: ''
|
|
||||||
|
|
||||||
%h1= t 'notification_mailer.reaction.title'
|
|
||||||
%p.lead= t('notification_mailer.reaction.body', name: @account.pretty_acct)
|
|
||||||
|
|
||||||
= render 'status', status: @status, time_zone: @me.user_time_zone
|
|
||||||
|
|
||||||
%table.email-table{ cellspacing: 0, cellpadding: 0 }
|
|
||||||
%tbody
|
|
||||||
%tr
|
|
||||||
%td.email-body
|
|
||||||
.email-container
|
|
||||||
%table.content-section{ cellspacing: 0, cellpadding: 0 }
|
|
||||||
%tbody
|
|
||||||
%tr
|
|
||||||
%td.content-cell.content-start.border-top
|
|
||||||
%table.column{ cellspacing: 0, cellpadding: 0 }
|
|
||||||
%tbody
|
|
||||||
%tr
|
|
||||||
%td.column-cell.button-cell
|
|
||||||
%table.button{ align: 'center', cellspacing: 0, cellpadding: 0 }
|
|
||||||
%tbody
|
|
||||||
%tr
|
|
||||||
%td.button-primary
|
|
||||||
= link_to web_url("@#{@status.account.pretty_acct}/#{@status.id}") do
|
|
||||||
%span= t 'application_mailer.view_status'
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ module Mastodon
|
||||||
end
|
end
|
||||||
|
|
||||||
def catstodon_revision
|
def catstodon_revision
|
||||||
'1.0.12'
|
'1.0.13'
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_metadata
|
def build_metadata
|
||||||
|
|
Loading…
Reference in a new issue