From d4e0ef254d00e3ca22b8559786210ca087c5c732 Mon Sep 17 00:00:00 2001 From: KMY Date: Tue, 11 Apr 2023 12:47:01 +0900 Subject: [PATCH 1/7] Fix trends error --- app/models/status.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/status.rb b/app/models/status.rb index da4bbc1e9f..8ac22b9558 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -313,6 +313,10 @@ class Status < ApplicationRecord status_stat&.favourites_count || 0 end + def emoji_reactions_count + status_stat&.emoji_reactions_count || 0 + end + def increment_count!(key) update_status_stat!(key => public_send(key) + 1) end From 25c3915728ee53b6c6aefda921310c418b38ae99 Mon Sep 17 00:00:00 2001 From: KMY Date: Wed, 12 Apr 2023 10:16:46 +0900 Subject: [PATCH 2/7] Add markdown selection support --- app/controllers/api/v1/statuses_controller.rb | 3 +++ app/helpers/formatting_helper.rb | 8 +++--- app/javascript/mastodon/actions/compose.js | 8 ++++++ .../compose/components/compose_form.jsx | 2 ++ .../containers/compose_form_container.js | 1 + .../containers/markdown_button_container.js | 26 +++++++++++++++++++ app/javascript/mastodon/reducers/compose.js | 10 +++++++ app/lib/text_formatter.rb | 7 ++++- app/models/status.rb | 1 + app/models/status_stat.rb | 1 + app/serializers/rest/status_serializer.rb | 2 +- app/services/post_status_service.rb | 3 +++ app/services/update_status_service.rb | 2 ++ ...20230412005311_add_markdown_to_statuses.rb | 5 ++++ db/schema.rb | 4 ++- 15 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 app/javascript/mastodon/features/compose/containers/markdown_button_container.js create mode 100644 db/migrate/20230412005311_add_markdown_to_statuses.rb diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb index 51fdd92e09..2f2d51f8cc 100644 --- a/app/controllers/api/v1/statuses_controller.rb +++ b/app/controllers/api/v1/statuses_controller.rb @@ -58,6 +58,7 @@ class Api::V1::StatusesController < Api::BaseController media_ids: status_params[:media_ids], sensitive: status_params[:sensitive], spoiler_text: status_params[:spoiler_text], + markdown: status_params[:markdown], visibility: status_params[:visibility], searchability: status_params[:searchability], language: status_params[:language], @@ -91,6 +92,7 @@ class Api::V1::StatusesController < Api::BaseController sensitive: status_params[:sensitive], language: status_params[:language], spoiler_text: status_params[:spoiler_text], + markdown: status_params[:markdown], poll: status_params[:poll] ) @@ -136,6 +138,7 @@ class Api::V1::StatusesController < Api::BaseController :visibility, :searchability, :language, + :markdown, :scheduled_at, allowed_mentions: [], media_ids: [], diff --git a/app/helpers/formatting_helper.rb b/app/helpers/formatting_helper.rb index b99c82969c..975a4d3522 100644 --- a/app/helpers/formatting_helper.rb +++ b/app/helpers/formatting_helper.rb @@ -15,11 +15,11 @@ module FormattingHelper module_function :extract_status_plain_text def status_content_format(status) - html_aware_format(status.text, status.local?, preloaded_accounts: [status.account] + (status.respond_to?(:active_mentions) ? status.active_mentions.map(&:account) : [])) + html_aware_format(status.text, status.local?, markdown: status.markdown, preloaded_accounts: [status.account] + (status.respond_to?(:active_mentions) ? status.active_mentions.map(&:account) : [])) end def emoji_name_format(emoji_reaction, status) - html_aware_format(emoji_reaction['url'].present? ? ":#{emoji_reaction['name']}:" : emoji_reaction['name'], status.local?) + html_aware_format(emoji_reaction['url'].present? ? ":#{emoji_reaction['name']}:" : emoji_reaction['name'], status.local?, markdown: status.markdown) end def rss_status_content_format(status) @@ -54,10 +54,10 @@ module FormattingHelper end def account_bio_format(account) - html_aware_format(account.note, account.local?) + html_aware_format(account.note, account.local?, markdown: true) end def account_field_value_format(field, with_rel_me: true) - html_aware_format(field.value, field.account.local?, with_rel_me: with_rel_me, with_domains: true, multiline: false) + html_aware_format(field.value, field.account.local?, markdown: true, with_rel_me: with_rel_me, with_domains: true, multiline: false) end end diff --git a/app/javascript/mastodon/actions/compose.js b/app/javascript/mastodon/actions/compose.js index 4a799a08f1..74080abafe 100644 --- a/app/javascript/mastodon/actions/compose.js +++ b/app/javascript/mastodon/actions/compose.js @@ -52,6 +52,7 @@ export const COMPOSE_UNMOUNT = 'COMPOSE_UNMOUNT'; export const COMPOSE_SENSITIVITY_CHANGE = 'COMPOSE_SENSITIVITY_CHANGE'; export const COMPOSE_SPOILERNESS_CHANGE = 'COMPOSE_SPOILERNESS_CHANGE'; export const COMPOSE_SPOILER_TEXT_CHANGE = 'COMPOSE_SPOILER_TEXT_CHANGE'; +export const COMPOSE_MARKDOWN_CHANGE = 'COMPOSE_MARKDOWN_CHANGE'; export const COMPOSE_VISIBILITY_CHANGE = 'COMPOSE_VISIBILITY_CHANGE'; export const COMPOSE_SEARCHABILITY_CHANGE= 'COMPOSE_SEARCHABILITY_CHANGE'; export const COMPOSE_COMPOSING_CHANGE = 'COMPOSE_COMPOSING_CHANGE'; @@ -192,6 +193,7 @@ export function submitCompose(routerHistory) { media_attributes, sensitive: getState().getIn(['compose', 'sensitive']), spoiler_text: getState().getIn(['compose', 'spoiler']) ? getState().getIn(['compose', 'spoiler_text'], '') : '', + markdown: getState().getIn(['compose', 'markdown']), visibility: getState().getIn(['compose', 'privacy']), searchability: getState().getIn(['compose', 'searchability']), poll: getState().getIn(['compose', 'poll'], null), @@ -729,6 +731,12 @@ export function changeComposeSpoilerText(text) { }; } +export function changeComposeMarkdown() { + return { + type: COMPOSE_MARKDOWN_CHANGE, + }; +} + export function changeComposeVisibility(value) { return { type: COMPOSE_VISIBILITY_CHANGE, diff --git a/app/javascript/mastodon/features/compose/components/compose_form.jsx b/app/javascript/mastodon/features/compose/components/compose_form.jsx index 97aa443f88..e6663ca44e 100644 --- a/app/javascript/mastodon/features/compose/components/compose_form.jsx +++ b/app/javascript/mastodon/features/compose/components/compose_form.jsx @@ -18,6 +18,7 @@ import PollFormContainer from '../containers/poll_form_container'; import UploadFormContainer from '../containers/upload_form_container'; import WarningContainer from '../containers/warning_container'; import LanguageDropdown from '../containers/language_dropdown_container'; +import MarkdownButtonContainer from '../containers/markdown_button_container'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { length } from 'stringz'; import { countableText } from '../util/counter'; @@ -290,6 +291,7 @@ class ComposeForm extends ImmutablePureComponent { +
diff --git a/app/javascript/mastodon/features/compose/containers/compose_form_container.js b/app/javascript/mastodon/features/compose/containers/compose_form_container.js index 132546dbc7..8ae8923402 100644 --- a/app/javascript/mastodon/features/compose/containers/compose_form_container.js +++ b/app/javascript/mastodon/features/compose/containers/compose_form_container.js @@ -17,6 +17,7 @@ const mapStateToProps = state => ({ suggestions: state.getIn(['compose', 'suggestions']), spoiler: state.getIn(['compose', 'spoiler']), spoilerText: state.getIn(['compose', 'spoiler_text']), + markdown: state.getIn(['compose', 'markdown']), privacy: state.getIn(['compose', 'privacy']), focusDate: state.getIn(['compose', 'focusDate']), caretPosition: state.getIn(['compose', 'caretPosition']), diff --git a/app/javascript/mastodon/features/compose/containers/markdown_button_container.js b/app/javascript/mastodon/features/compose/containers/markdown_button_container.js new file mode 100644 index 0000000000..1f5604f97b --- /dev/null +++ b/app/javascript/mastodon/features/compose/containers/markdown_button_container.js @@ -0,0 +1,26 @@ +import { connect } from 'react-redux'; +import TextIconButton from '../components/text_icon_button'; +import { changeComposeMarkdown } from '../../../actions/compose'; +import { injectIntl, defineMessages } from 'react-intl'; + +const messages = defineMessages({ + marked: { id: 'compose_form.markdown.marked', defaultMessage: 'Markdown is enabled' }, + unmarked: { id: 'compose_form.markdown.unmarked', defaultMessage: 'Markdown is disabled' }, +}); + +const mapStateToProps = (state, { intl }) => ({ + label: 'MD', + title: intl.formatMessage(state.getIn(['compose', 'markdown']) ? messages.marked : messages.unmarked), + active: state.getIn(['compose', 'markdown']), + ariaControls: 'cw-markdown-input', +}); + +const mapDispatchToProps = dispatch => ({ + + onClick () { + dispatch(changeComposeMarkdown()); + }, + +}); + +export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(TextIconButton)); diff --git a/app/javascript/mastodon/reducers/compose.js b/app/javascript/mastodon/reducers/compose.js index ff5b5038fe..17db54f6f8 100644 --- a/app/javascript/mastodon/reducers/compose.js +++ b/app/javascript/mastodon/reducers/compose.js @@ -28,6 +28,7 @@ import { COMPOSE_SENSITIVITY_CHANGE, COMPOSE_SPOILERNESS_CHANGE, COMPOSE_SPOILER_TEXT_CHANGE, + COMPOSE_MARKDOWN_CHANGE, COMPOSE_VISIBILITY_CHANGE, COMPOSE_LANGUAGE_CHANGE, COMPOSE_COMPOSING_CHANGE, @@ -62,6 +63,7 @@ const initialState = ImmutableMap({ sensitive: false, spoiler: false, spoiler_text: '', + markdown: false, privacy: null, searchability: null, id: null, @@ -120,6 +122,7 @@ function clearAll(state) { map.set('text', ''); map.set('spoiler', false); map.set('spoiler_text', ''); + map.set('markdown', false); map.set('is_submitting', false); map.set('is_changing_upload', false); map.set('in_reply_to', null); @@ -328,6 +331,11 @@ export default function compose(state = initialState, action) { return state .set('spoiler_text', action.text) .set('idempotencyKey', uuid()); + case COMPOSE_MARKDOWN_CHANGE: + return state.withMutations(map => { + map.set('markdown', !state.get('markdown')); + map.set('idempotencyKey', uuid()); + }); case COMPOSE_VISIBILITY_CHANGE: return state .set('privacy', action.value) @@ -488,6 +496,7 @@ export default function compose(state = initialState, action) { map.set('idempotencyKey', uuid()); map.set('sensitive', action.status.get('sensitive')); map.set('language', action.status.get('language')); + map.set('markdown', action.status.get('markdown')); map.set('id', null); if (action.status.get('spoiler_text').length > 0) { @@ -518,6 +527,7 @@ export default function compose(state = initialState, action) { map.set('idempotencyKey', uuid()); map.set('sensitive', action.status.get('sensitive')); map.set('language', action.status.get('language')); + map.set('markdown', action.status.get('markdown')); if (action.spoiler_text.length > 0) { map.set('spoiler', true); diff --git a/app/lib/text_formatter.rb b/app/lib/text_formatter.rb index f59a5e25aa..ec4a37fc9c 100644 --- a/app/lib/text_formatter.rb +++ b/app/lib/text_formatter.rb @@ -11,6 +11,7 @@ class TextFormatter DEFAULT_OPTIONS = { multiline: true, + markdown: false, }.freeze attr_reader :text, :options @@ -44,7 +45,7 @@ class TextFormatter end # line first letter for blockquote - html = markdownify(html.gsub(/^>/, '>')) + html = markdownify(html.gsub(/^>/, '>')) if markdown? # html = simple_format(html, {}, sanitize: false).delete("\n") if multiline? html = html.delete("\n") @@ -152,6 +153,10 @@ class TextFormatter options[:with_rel_me] end + def markdown? + options[:markdown] + end + def preloaded_accounts options[:preloaded_accounts] end diff --git a/app/models/status.rb b/app/models/status.rb index 8ac22b9558..fb5805a32f 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -28,6 +28,7 @@ # trendable :boolean # ordered_media_attachment_ids :bigint(8) is an Array # searchability :integer +# markdown :boolean default(FALSE) # require 'ostruct' diff --git a/app/models/status_stat.rb b/app/models/status_stat.rb index 80e7270318..0f651959f1 100644 --- a/app/models/status_stat.rb +++ b/app/models/status_stat.rb @@ -13,6 +13,7 @@ # updated_at :datetime not null # emoji_reactions :string # emoji_reactions_count :integer default(0), not null +# test :integer default(0), not null # class StatusStat < ApplicationRecord diff --git a/app/serializers/rest/status_serializer.rb b/app/serializers/rest/status_serializer.rb index bd7b279d68..38c4b541de 100644 --- a/app/serializers/rest/status_serializer.rb +++ b/app/serializers/rest/status_serializer.rb @@ -5,7 +5,7 @@ class REST::StatusSerializer < ActiveModel::Serializer attributes :id, :created_at, :in_reply_to_id, :in_reply_to_account_id, :sensitive, :spoiler_text, :visibility, :visibility_ex, :language, :translatable, - :uri, :url, :replies_count, :reblogs_count, :searchability, + :uri, :url, :replies_count, :reblogs_count, :searchability, :markdown, :favourites_count, :emoji_reactions, :edited_at attribute :favourited, if: :current_user? diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index c0f15525bf..e7c9574a4f 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -24,6 +24,7 @@ class PostStatusService < BaseService # @option [String] :visibility # @option [String] :searchability # @option [String] :spoiler_text + # @option [Boolean] :markdown # @option [String] :language # @option [String] :scheduled_at # @option [Hash] :poll Optional poll to attach @@ -69,6 +70,7 @@ class PostStatusService < BaseService @visibility = :unlisted if (@visibility&.to_sym == :public || @visibility&.to_sym == :public_unlisted) && @account.silenced? @visibility = :public_unlisted if @visibility&.to_sym == :public && !@options[:application]&.superapp && @account.user&.setting_public_post_to_unlisted @searchability= searchability + @markdown = !!@options[:markdown] @scheduled_at = @options[:scheduled_at]&.to_datetime @scheduled_at = nil if scheduled_in_the_past? rescue ArgumentError @@ -214,6 +216,7 @@ class PostStatusService < BaseService poll_attributes: poll_attributes, sensitive: @sensitive, spoiler_text: @options[:spoiler_text] || '', + markdown: @markdown, visibility: @visibility, searchability: @searchability, language: valid_locale_cascade(@options[:language], @account.user&.preferred_posting_language, I18n.default_locale), diff --git a/app/services/update_status_service.rb b/app/services/update_status_service.rb index f29dba816f..c6bb40ee3a 100644 --- a/app/services/update_status_service.rb +++ b/app/services/update_status_service.rb @@ -15,6 +15,7 @@ class UpdateStatusService < BaseService # @option options [String] :text # @option options [String] :spoiler_text # @option options [Boolean] :sensitive + # @option options [Boolean] :markdown # @option options [String] :language def call(status, account_id, options = {}) @status = status @@ -112,6 +113,7 @@ class UpdateStatusService < BaseService def update_immediate_attributes! @status.text = @options[:text].presence || @options.delete(:spoiler_text) || '' if @options.key?(:text) @status.spoiler_text = @options[:spoiler_text] || '' if @options.key?(:spoiler_text) + @status.markdown = !!@options[:markdown] @status.sensitive = @options[:sensitive] || @options[:spoiler_text].present? if @options.key?(:sensitive) || @options.key?(:spoiler_text) @status.language = valid_locale_cascade(@options[:language], @status.language, @status.account.user&.preferred_posting_language, I18n.default_locale) diff --git a/db/migrate/20230412005311_add_markdown_to_statuses.rb b/db/migrate/20230412005311_add_markdown_to_statuses.rb new file mode 100644 index 0000000000..b8e0c0bd66 --- /dev/null +++ b/db/migrate/20230412005311_add_markdown_to_statuses.rb @@ -0,0 +1,5 @@ +class AddMarkdownToStatuses < ActiveRecord::Migration[6.1] + def change + add_column :statuses, :markdown, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 645b0d0a90..2754e12256 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_04_10_004651) do +ActiveRecord::Schema.define(version: 2023_04_12_005311) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -934,6 +934,7 @@ ActiveRecord::Schema.define(version: 2023_04_10_004651) do t.datetime "updated_at", null: false t.string "emoji_reactions" t.integer "emoji_reactions_count", default: 0, null: false + t.integer "test", default: 0, null: false t.index ["status_id"], name: "index_status_stats_on_status_id", unique: true end @@ -972,6 +973,7 @@ ActiveRecord::Schema.define(version: 2023_04_10_004651) do t.boolean "trendable" t.bigint "ordered_media_attachment_ids", array: true t.integer "searchability" + t.boolean "markdown", default: false t.index ["account_id", "id", "visibility", "updated_at"], name: "index_statuses_20190820", order: { id: :desc }, where: "(deleted_at IS NULL)" t.index ["account_id"], name: "index_statuses_on_account_id" t.index ["deleted_at"], name: "index_statuses_on_deleted_at", where: "(deleted_at IS NOT NULL)" From 8db2f96c361442ef0d0850f81615c575f27cf44f Mon Sep 17 00:00:00 2001 From: KMY Date: Wed, 12 Apr 2023 16:37:40 +0900 Subject: [PATCH 3/7] Fix markdown property on edit status --- app/models/concerns/status_snapshot_concern.rb | 1 + app/models/status_edit.rb | 1 + app/serializers/rest/status_edit_serializer.rb | 2 +- db/migrate/20230412073021_add_markdown_to_status_edits.rb | 5 +++++ db/schema.rb | 3 ++- 5 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20230412073021_add_markdown_to_status_edits.rb diff --git a/app/models/concerns/status_snapshot_concern.rb b/app/models/concerns/status_snapshot_concern.rb index 9741b9aeb2..43b3ecd44e 100644 --- a/app/models/concerns/status_snapshot_concern.rb +++ b/app/models/concerns/status_snapshot_concern.rb @@ -19,6 +19,7 @@ module StatusSnapshotConcern status_id: id, text: text, spoiler_text: spoiler_text, + markdown: markdown, sensitive: sensitive, ordered_media_attachment_ids: ordered_media_attachment_ids&.dup || media_attachments.pluck(:id), media_descriptions: ordered_media_attachments.map(&:description), diff --git a/app/models/status_edit.rb b/app/models/status_edit.rb index 683441bb56..0ba97f33cf 100644 --- a/app/models/status_edit.rb +++ b/app/models/status_edit.rb @@ -15,6 +15,7 @@ # media_descriptions :text is an Array # poll_options :string is an Array # sensitive :boolean +# markdown :boolean default(FALSE) # class StatusEdit < ApplicationRecord diff --git a/app/serializers/rest/status_edit_serializer.rb b/app/serializers/rest/status_edit_serializer.rb index f7a48797d1..58fb039a01 100644 --- a/app/serializers/rest/status_edit_serializer.rb +++ b/app/serializers/rest/status_edit_serializer.rb @@ -5,7 +5,7 @@ class REST::StatusEditSerializer < ActiveModel::Serializer has_one :account, serializer: REST::AccountSerializer - attributes :content, :spoiler_text, :sensitive, :created_at + attributes :content, :spoiler_text, :markdown, :sensitive, :created_at has_many :ordered_media_attachments, key: :media_attachments, serializer: REST::MediaAttachmentSerializer has_many :emojis, serializer: REST::CustomEmojiSerializer diff --git a/db/migrate/20230412073021_add_markdown_to_status_edits.rb b/db/migrate/20230412073021_add_markdown_to_status_edits.rb new file mode 100644 index 0000000000..f73f5fbff5 --- /dev/null +++ b/db/migrate/20230412073021_add_markdown_to_status_edits.rb @@ -0,0 +1,5 @@ +class AddMarkdownToStatusEdits < ActiveRecord::Migration[6.1] + def change + add_column :status_edits, :markdown, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 2754e12256..991cfaf140 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_04_12_005311) do +ActiveRecord::Schema.define(version: 2023_04_12_073021) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -912,6 +912,7 @@ ActiveRecord::Schema.define(version: 2023_04_12_005311) do t.text "media_descriptions", array: true t.string "poll_options", array: true t.boolean "sensitive" + t.boolean "markdown", default: false t.index ["account_id"], name: "index_status_edits_on_account_id" t.index ["status_id"], name: "index_status_edits_on_status_id" end From 71917cab04ddb636440f70714acd48263bb316bb Mon Sep 17 00:00:00 2001 From: KMY Date: Wed, 12 Apr 2023 17:06:27 +0900 Subject: [PATCH 4/7] Fix no-markdown post line break --- app/lib/text_formatter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/text_formatter.rb b/app/lib/text_formatter.rb index ec4a37fc9c..cbd8cad12b 100644 --- a/app/lib/text_formatter.rb +++ b/app/lib/text_formatter.rb @@ -47,7 +47,7 @@ class TextFormatter # line first letter for blockquote html = markdownify(html.gsub(/^>/, '>')) if markdown? - # html = simple_format(html, {}, sanitize: false).delete("\n") if multiline? + html = simple_format(html, {}, sanitize: false).delete("\n") if !markdown? && multiline? html = html.delete("\n") html.html_safe # rubocop:disable Rails/OutputSafety From a4e8dcc3c4f02bea9083c96715b38bb13b8959df Mon Sep 17 00:00:00 2001 From: KMY Date: Thu, 13 Apr 2023 09:53:24 +0900 Subject: [PATCH 5/7] Fix api responses and add force_visibility --- app/controllers/api/v1/statuses_controller.rb | 2 ++ app/serializers/rest/instance_serializer.rb | 6 ++++-- app/serializers/rest/v1/instance_serializer.rb | 5 ++++- app/services/post_status_service.rb | 3 ++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb index 2f2d51f8cc..d7500b663a 100644 --- a/app/controllers/api/v1/statuses_controller.rb +++ b/app/controllers/api/v1/statuses_controller.rb @@ -60,6 +60,7 @@ class Api::V1::StatusesController < Api::BaseController spoiler_text: status_params[:spoiler_text], markdown: status_params[:markdown], visibility: status_params[:visibility], + force_visibility: status_params[:force_visibility], searchability: status_params[:searchability], language: status_params[:language], scheduled_at: status_params[:scheduled_at], @@ -136,6 +137,7 @@ class Api::V1::StatusesController < Api::BaseController :sensitive, :spoiler_text, :visibility, + :force_visibility, :searchability, :language, :markdown, diff --git a/app/serializers/rest/instance_serializer.rb b/app/serializers/rest/instance_serializer.rb index 6fbb463572..3d4f88c5e9 100644 --- a/app/serializers/rest/instance_serializer.rb +++ b/app/serializers/rest/instance_serializer.rb @@ -97,10 +97,12 @@ class REST::InstanceSerializer < ActiveModel::Serializer def fedibird_capabilities capabilities = [ :emoji_reaction, - :visibility_public_unlisted, + :kmyblue_extra_media_attachments, + :kmyblue_visibility_public_unlisted, :enable_wide_emoji, :enable_wide_emoji_reaction, - :searchability, + :kmyblue_searchability, + :kmyblue_markdown, ] capabilities << :profile_search unless Chewy.enabled? diff --git a/app/serializers/rest/v1/instance_serializer.rb b/app/serializers/rest/v1/instance_serializer.rb index 7db03edf08..d2c49ba0e3 100644 --- a/app/serializers/rest/v1/instance_serializer.rb +++ b/app/serializers/rest/v1/instance_serializer.rb @@ -107,9 +107,12 @@ class REST::V1::InstanceSerializer < ActiveModel::Serializer def fedibird_capabilities capabilities = [ :emoji_reaction, - :visibility_public_unlisted, + :kmyblue_extra_media_attachments, + :kmyblue_visibility_public_unlisted, :enable_wide_emoji, :enable_wide_emoji_reaction, + :kmyblue_searchability, + :kmyblue_markdown, ] capabilities << :profile_search unless Chewy.enabled? diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index e7c9574a4f..29093b7a78 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -22,6 +22,7 @@ class PostStatusService < BaseService # @option [Status] :thread Optional status to reply to # @option [Boolean] :sensitive # @option [String] :visibility + # @option [Boolean] :force_visibility # @option [String] :searchability # @option [String] :spoiler_text # @option [Boolean] :markdown @@ -68,7 +69,7 @@ class PostStatusService < BaseService @text = @options.delete(:spoiler_text) if @text.blank? && @options[:spoiler_text].present? @visibility = @options[:visibility] || @account.user&.setting_default_privacy @visibility = :unlisted if (@visibility&.to_sym == :public || @visibility&.to_sym == :public_unlisted) && @account.silenced? - @visibility = :public_unlisted if @visibility&.to_sym == :public && !@options[:application]&.superapp && @account.user&.setting_public_post_to_unlisted + @visibility = :public_unlisted if @visibility&.to_sym == :public && !@options[:force_visibility] && !@options[:application]&.superapp && @account.user&.setting_public_post_to_unlisted @searchability= searchability @markdown = !!@options[:markdown] @scheduled_at = @options[:scheduled_at]&.to_datetime From 6751f0ded8c4af8c9f8cf9949520b0acb1a4a459 Mon Sep 17 00:00:00 2001 From: KMY Date: Thu, 13 Apr 2023 10:06:06 +0900 Subject: [PATCH 6/7] Add width and height in notify custom_emoji --- .../rest/notify_emoji_reaction_serializer.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/serializers/rest/notify_emoji_reaction_serializer.rb b/app/serializers/rest/notify_emoji_reaction_serializer.rb index a78740d56c..8b8c57c4d5 100644 --- a/app/serializers/rest/notify_emoji_reaction_serializer.rb +++ b/app/serializers/rest/notify_emoji_reaction_serializer.rb @@ -9,6 +9,8 @@ class REST::NotifyEmojiReactionSerializer < ActiveModel::Serializer attribute :url, if: :custom_emoji? attribute :static_url, if: :custom_emoji? attribute :domain, if: :custom_emoji? + attribute :width, if: :width? + attribute :height, if: :height? def count? object.respond_to?(:count) @@ -33,4 +35,20 @@ class REST::NotifyEmojiReactionSerializer < ActiveModel::Serializer def domain object.custom_emoji.domain end + + def width? + custom_emoji? && (object.custom_emoji.respond_to?(:image_width) || object.custom_emoji.respond_to?(:width)) + end + + def height? + custom_emoji? && (object.custom_emoji.respond_to?(:image_height) || object.custom_emoji.respond_to?(:height)) + end + + def width + object.custom_emoji.respond_to?(:image_width) ? object.custom_emoji.image_width : object.custom_emoji.width + end + + def height + object.custom_emoji.respond_to?(:image_height) ? object.custom_emoji.image_height : object.custom_emoji.height + end end From fac734b6a88a9079692b46c00ac32a39030a7141 Mon Sep 17 00:00:00 2001 From: KMY Date: Thu, 13 Apr 2023 18:55:36 +0900 Subject: [PATCH 7/7] Add emoji_reactions_count on status --- app/serializers/rest/status_serializer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/serializers/rest/status_serializer.rb b/app/serializers/rest/status_serializer.rb index 38c4b541de..7f72974a78 100644 --- a/app/serializers/rest/status_serializer.rb +++ b/app/serializers/rest/status_serializer.rb @@ -6,7 +6,7 @@ class REST::StatusSerializer < ActiveModel::Serializer attributes :id, :created_at, :in_reply_to_id, :in_reply_to_account_id, :sensitive, :spoiler_text, :visibility, :visibility_ex, :language, :translatable, :uri, :url, :replies_count, :reblogs_count, :searchability, :markdown, - :favourites_count, :emoji_reactions, :edited_at + :favourites_count, :emoji_reactions, :emoji_reactions_count, :edited_at attribute :favourited, if: :current_user? attribute :reblogged, if: :current_user?