diff options
Diffstat (limited to 'app/lib')
-rw-r--r-- | app/lib/activitypub/activity/create.rb | 13 | ||||
-rw-r--r-- | app/lib/command_tag/commands/status_tools.rb | 28 |
2 files changed, 41 insertions, 0 deletions
diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index 10a0a9498..12c3b0d19 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -122,6 +122,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity text: text_from_content || '', language: detected_language, spoiler_text: converted_object_type? ? '' : (text_from_summary || ''), + title: text_from_title, created_at: @object['published'], override_timestamps: @options[:override_timestamps], reply: @object['inReplyTo'].present?, @@ -451,6 +452,14 @@ class ActivityPub::Activity::Create < ActivityPub::Activity end end + def text_from_title + if @object['title'].present? + @object['title'] + elsif title_language_map? + @object['titleMap'].values.first + end + end + def text_from_name if @object['name'].present? @object['name'] @@ -487,6 +496,10 @@ class ActivityPub::Activity::Create < ActivityPub::Activity @object['summaryMap'].is_a?(Hash) && !@object['summaryMap'].empty? end + def title_language_map? + @object['titleMap'].is_a?(Hash) && !@object['titleMap'].empty? + end + def content_language_map? @object['contentMap'].is_a?(Hash) && !@object['contentMap'].empty? end diff --git a/app/lib/command_tag/commands/status_tools.rb b/app/lib/command_tag/commands/status_tools.rb new file mode 100644 index 000000000..f8b8f8ae0 --- /dev/null +++ b/app/lib/command_tag/commands/status_tools.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +# rubocop:disable Layout/ExtraSpacing +module CommandTag::Commands::StatusTools + def handle_title_before_save(args) + return unless author_of_status? && !@status.published? + + @status.title = args[0] + end + + def handle_visibility_before_save(args) + return unless author_of_status? && !@status.published? && args[0].present? + + args[0] = 'public' if %w(p pu all world).include?(args[0]) + args[0] = 'unlisted' if %w(u ul).include?(args[0]) + args[0] = 'private' if %w(f followers followers-only packmates packmates-only).include?(args[0]) + args[0] = 'limited' if %w(l limit).include?(args[0]) + args[0] = 'direct' if %w(d dm pm directmessage).include?(args[0]) + + return unless %w(public unlisted private limited direct).include?(args[0]) + + @status.visibility = args[0].to_sym + end + + alias handle_v_before_save handle_visibility_before_save + alias handle_privacy_before_save handle_visibility_before_save +end +# rubocop:enable Layout/ExtraSpacing |