Introduce event language detection
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -10,6 +10,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Comments do
|
||||
alias Mobilizon.Federation.ActivityStream.Convertible
|
||||
alias Mobilizon.GraphQL.API.Utils, as: APIUtils
|
||||
alias Mobilizon.Service.Activity.Comment, as: CommentActivity
|
||||
alias Mobilizon.Service.LanguageDetection
|
||||
alias Mobilizon.Share
|
||||
alias Mobilizon.Tombstone
|
||||
alias Mobilizon.Web.Endpoint
|
||||
@@ -127,6 +128,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Comments do
|
||||
),
|
||||
tags <- ConverterUtils.fetch_tags(tags),
|
||||
mentions <- Map.get(args, :mentions, []) ++ ConverterUtils.fetch_mentions(mentions),
|
||||
lang <- Map.get(args, :language, "und"),
|
||||
args <-
|
||||
Map.merge(args, %{
|
||||
actor_id: Map.get(args, :actor_id),
|
||||
@@ -141,7 +143,8 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Comments do
|
||||
if(is_nil(in_reply_to_comment),
|
||||
do: nil,
|
||||
else: Comment.get_thread_id(in_reply_to_comment)
|
||||
)
|
||||
),
|
||||
language: if(lang == "und", do: LanguageDetection.detect(:comment, args), else: lang)
|
||||
}) do
|
||||
args
|
||||
end
|
||||
|
||||
@@ -12,6 +12,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Events do
|
||||
alias Mobilizon.GraphQL.API.Utils, as: APIUtils
|
||||
alias Mobilizon.Service.Activity.Event, as: EventActivity
|
||||
alias Mobilizon.Service.Formatter.HTML
|
||||
alias Mobilizon.Service.LanguageDetection
|
||||
alias Mobilizon.Service.Notifications.Scheduler
|
||||
alias Mobilizon.Share
|
||||
alias Mobilizon.Tombstone
|
||||
@@ -234,6 +235,10 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Events do
|
||||
|
||||
args
|
||||
|> Map.put(:options, options)
|
||||
|> Map.put_new(:language, "und")
|
||||
|> Map.update!(:language, fn lang ->
|
||||
if lang == "und", do: LanguageDetection.detect(:event, args), else: lang
|
||||
end)
|
||||
|> Map.update(:tags, [], &ConverterUtils.fetch_tags/1)
|
||||
|> Map.update(:contacts, [], &ConverterUtils.fetch_actors/1)
|
||||
end
|
||||
|
||||
@@ -8,6 +8,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Posts do
|
||||
alias Mobilizon.Federation.ActivityStream.Convertible
|
||||
alias Mobilizon.Posts.Post
|
||||
alias Mobilizon.Service.Activity.Post, as: PostsActivity
|
||||
alias Mobilizon.Service.LanguageDetection
|
||||
require Logger
|
||||
import Mobilizon.Federation.ActivityPub.Utils, only: [make_create_data: 2, make_update_data: 2]
|
||||
|
||||
@@ -17,7 +18,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Posts do
|
||||
|
||||
@impl Entity
|
||||
def create(args, additional) do
|
||||
with args <- Map.update(args, :tags, [], &ConverterUtils.fetch_tags/1),
|
||||
with args <- prepare_args(args),
|
||||
{:ok, %Post{attributed_to_id: group_id, author_id: creator_id} = post} <-
|
||||
Posts.create_post(args),
|
||||
{:ok, _} <- PostsActivity.insert_activity(post, subject: "post_created"),
|
||||
@@ -37,7 +38,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Posts do
|
||||
|
||||
@impl Entity
|
||||
def update(%Post{} = post, args, additional) do
|
||||
with args <- Map.update(args, :tags, [], &ConverterUtils.fetch_tags/1),
|
||||
with args <- prepare_args(args),
|
||||
{:ok, %Post{attributed_to_id: group_id, author_id: creator_id} = post} <-
|
||||
Posts.update_post(post, args),
|
||||
{:ok, _} <- PostsActivity.insert_activity(post, subject: "post_updated"),
|
||||
@@ -99,4 +100,13 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Posts do
|
||||
delete: :moderator
|
||||
}
|
||||
end
|
||||
|
||||
defp prepare_args(args) do
|
||||
args
|
||||
|> Map.update(:tags, [], &ConverterUtils.fetch_tags/1)
|
||||
|> Map.put_new(:language, "und")
|
||||
|> Map.update!(:language, fn lang ->
|
||||
if lang == "und", do: LanguageDetection.detect(:post, args), else: lang
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -36,6 +36,7 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://litepub.social/context.jsonld",
|
||||
%{
|
||||
"@language" => "und",
|
||||
"sc" => "http://schema.org#",
|
||||
"ical" => "http://www.w3.org/2002/12/cal/ical#",
|
||||
"pt" => "https://joinpeertube.org/ns#",
|
||||
@@ -91,7 +92,8 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do
|
||||
},
|
||||
"PropertyValue" => "sc:PropertyValue",
|
||||
"value" => "sc:value",
|
||||
"propertyID" => "sc:propertyID"
|
||||
"propertyID" => "sc:propertyID",
|
||||
"inLanguage" => "sc:inLanguage"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -83,7 +83,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
|
||||
mentions: mentions,
|
||||
physical_address_id: address_id,
|
||||
updated_at: object["updated"],
|
||||
publish_at: object["published"]
|
||||
publish_at: object["published"],
|
||||
language: object["inLanguage"]
|
||||
}
|
||||
else
|
||||
{:ok, %Actor{suspended: true}} ->
|
||||
@@ -128,7 +129,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
|
||||
"draft" => event.draft,
|
||||
"ical:status" => event.status |> to_string |> String.upcase(),
|
||||
"id" => event.url,
|
||||
"url" => event.url
|
||||
"url" => event.url,
|
||||
"inLanguage" => event.language
|
||||
}
|
||||
|> maybe_add_physical_address(event)
|
||||
|> maybe_add_event_picture(event)
|
||||
|
||||
Reference in New Issue
Block a user