Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Mastodon
Commits
f9c41ae4
Commit
f9c41ae4
authored
9 months ago
by
Claire
Browse files
Options
Downloads
Patches
Plain Diff
Normalize language code of incoming posts (#30403)
parent
b8edc95e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/lib/activitypub/parser/status_parser.rb
+9
-2
9 additions, 2 deletions
app/lib/activitypub/parser/status_parser.rb
spec/lib/activitypub/parser/status_parser_spec.rb
+50
-0
50 additions, 0 deletions
spec/lib/activitypub/parser/status_parser_spec.rb
with
59 additions
and
2 deletions
app/lib/activitypub/parser/status_parser.rb
+
9
−
2
View file @
f9c41ae4
...
...
@@ -3,6 +3,8 @@
class
ActivityPub::Parser::StatusParser
include
JsonLdHelper
NORMALIZED_LOCALE_NAMES
=
LanguagesHelper
::
SUPPORTED_LOCALES
.
keys
.
index_by
(
&
:downcase
).
freeze
# @param [Hash] json
# @param [Hash] magic_values
# @option magic_values [String] :followers_collection
...
...
@@ -86,6 +88,13 @@ class ActivityPub::Parser::StatusParser
end
def
language
lang
=
raw_language_code
lang
.
presence
&&
NORMALIZED_LOCALE_NAMES
.
fetch
(
lang
.
downcase
.
to_sym
,
lang
)
end
private
def
raw_language_code
if
content_language_map?
@object
[
'contentMap'
].
keys
.
first
elsif
name_language_map?
...
...
@@ -95,8 +104,6 @@ class ActivityPub::Parser::StatusParser
end
end
private
def
audience_to
as_array
(
@object
[
'to'
]
||
@json
[
'to'
]).
map
{
|
x
|
value_or_id
(
x
)
}
end
...
...
This diff is collapsed.
Click to expand it.
spec/lib/activitypub/parser/status_parser_spec.rb
0 → 100644
+
50
−
0
View file @
f9c41ae4
# frozen_string_literal: true
require
'rails_helper'
RSpec
.
describe
ActivityPub
::
Parser
::
StatusParser
do
subject
{
described_class
.
new
(
json
)
}
let
(
:sender
)
{
Fabricate
(
:account
,
followers_url:
'http://example.com/followers'
,
domain:
'example.com'
,
uri:
'https://example.com/actor'
)
}
let
(
:follower
)
{
Fabricate
(
:account
,
username:
'bob'
)
}
let
(
:json
)
do
{
'@context'
:
'https://www.w3.org/ns/activitystreams'
,
id:
[
ActivityPub
::
TagManager
.
instance
.
uri_for
(
sender
),
'#foo'
].
join
,
type:
'Create'
,
actor:
ActivityPub
::
TagManager
.
instance
.
uri_for
(
sender
),
object:
object_json
,
}.
with_indifferent_access
end
let
(
:object_json
)
do
{
id:
[
ActivityPub
::
TagManager
.
instance
.
uri_for
(
sender
),
'post1'
].
join
(
'/'
),
type:
'Note'
,
to:
[
'https://www.w3.org/ns/activitystreams#Public'
,
ActivityPub
::
TagManager
.
instance
.
uri_for
(
follower
),
],
content:
'@bob lorem ipsum'
,
contentMap:
{
EN
:
'@bob lorem ipsum'
,
},
published:
1
.
hour
.
ago
.
utc
.
iso8601
,
updated:
1
.
hour
.
ago
.
utc
.
iso8601
,
tag:
{
type:
'Mention'
,
href:
ActivityPub
::
TagManager
.
instance
.
uri_for
(
follower
),
},
}
end
it
'correctly parses status'
do
expect
(
subject
).
to
have_attributes
(
text:
'@bob lorem ipsum'
,
uri:
[
ActivityPub
::
TagManager
.
instance
.
uri_for
(
sender
),
'post1'
].
join
(
'/'
),
reply:
false
,
language: :en
)
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment