From 297db76188b8aa50decccf9f7fa52ebcc637943f Mon Sep 17 00:00:00 2001 From: KMY Date: Wed, 27 Sep 2023 18:03:13 +0900 Subject: [PATCH] #41 Add Japanese language flag to posts from misskey --- app/lib/activitypub/parser/status_parser.rb | 4 + spec/lib/activitypub/activity/create_spec.rb | 80 ++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/app/lib/activitypub/parser/status_parser.rb b/app/lib/activitypub/parser/status_parser.rb index 4ffec58ae3..e0a234e110 100644 --- a/app/lib/activitypub/parser/status_parser.rb +++ b/app/lib/activitypub/parser/status_parser.rb @@ -107,6 +107,10 @@ class ActivityPub::Parser::StatusParser end def language + @language ||= original_language || (misskey_software? ? 'ja' : nil) + end + + def original_language if content_language_map? @object['contentMap'].keys.first elsif name_language_map? diff --git a/spec/lib/activitypub/activity/create_spec.rb b/spec/lib/activitypub/activity/create_spec.rb index 9c4bba3e62..c199fcd038 100644 --- a/spec/lib/activitypub/activity/create_spec.rb +++ b/spec/lib/activitypub/activity/create_spec.rb @@ -1088,6 +1088,86 @@ RSpec.describe ActivityPub::Activity::Create do expect(poll.votes.first).to be_nil end end + + context 'with language' do + let(:to) { 'https://www.w3.org/ns/activitystreams#Public' } + let(:object_json) do + { + id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, + type: 'Note', + content: 'Lorem ipsum', + to: to, + contentMap: { ja: 'Lorem ipsum' }, + } + end + + it 'create status' do + status = sender.statuses.first + + expect(status).to_not be_nil + expect(status.language).to eq 'ja' + end + end + + context 'without language' do + let(:to) { 'https://www.w3.org/ns/activitystreams#Public' } + let(:object_json) do + { + id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, + type: 'Note', + content: 'Lorem ipsum', + to: to, + } + end + + it 'create status' do + status = sender.statuses.first + + expect(status).to_not be_nil + expect(status.language).to be_nil + end + end + + context 'without language when misskey server' do + let(:sender_software) { 'misskey' } + let(:to) { 'https://www.w3.org/ns/activitystreams#Public' } + let(:object_json) do + { + id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, + type: 'Note', + content: 'Lorem ipsum', + to: to, + } + end + + it 'create status' do + status = sender.statuses.first + + expect(status).to_not be_nil + expect(status.language).to eq 'ja' + end + end + + context 'with language when misskey server' do + let(:sender_software) { 'misskey' } + let(:to) { 'https://www.w3.org/ns/activitystreams#Public' } + let(:object_json) do + { + id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, + type: 'Note', + content: 'Lorem ipsum', + to: to, + contentMap: { 'en-US': 'Lorem ipsum' }, + } + end + + it 'create status' do + status = sender.statuses.first + + expect(status).to_not be_nil + expect(status.language).to eq 'en-US' + end + end end context 'with an encrypted message' do