[WIP] Test transmogrifier
Introduce MobilizonWeb.API namespace Signed-off-by: Thomas Citharel <tcit@tcit.fr> Format Signed-off-by: Thomas Citharel <tcit@tcit.fr> WIP Signed-off-by: Thomas Citharel <tcit@tcit.fr> remove unneeded code Signed-off-by: Thomas Citharel <tcit@tcit.fr> Fix tests Signed-off-by: Thomas Citharel <tcit@tcit.fr> Fix warnings Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
58
lib/mobilizon_web/api/groups.ex
Normal file
58
lib/mobilizon_web/api/groups.ex
Normal file
@@ -0,0 +1,58 @@
|
||||
defmodule MobilizonWeb.API.Groups do
|
||||
@moduledoc """
|
||||
API for Events
|
||||
"""
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Service.Formatter
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Service.ActivityPub.Utils, as: ActivityPubUtils
|
||||
import MobilizonWeb.API.Utils
|
||||
|
||||
@spec create_group(map()) :: {:ok, Activity.t()} | any()
|
||||
def create_group(
|
||||
%{
|
||||
preferred_username: title,
|
||||
description: description,
|
||||
admin_actor_username: admin_actor_username
|
||||
} = args
|
||||
) do
|
||||
with {:bad_actor, %Actor{url: url} = actor} <-
|
||||
{:bad_actor, Actors.get_local_actor_by_name(admin_actor_username)},
|
||||
{:existing_group, nil} <- {:existing_group, Actors.get_group_by_title(title)},
|
||||
title <- String.trim(title),
|
||||
mentions <- Formatter.parse_mentions(description),
|
||||
visibility <- Map.get(args, :visibility, "public"),
|
||||
{to, cc} <- to_for_actor_and_mentions(actor, mentions, nil, visibility),
|
||||
tags <- Formatter.parse_tags(description),
|
||||
content_html <-
|
||||
make_content_html(
|
||||
description,
|
||||
mentions,
|
||||
tags,
|
||||
"text/plain"
|
||||
),
|
||||
group <-
|
||||
ActivityPubUtils.make_group_data(
|
||||
url,
|
||||
to,
|
||||
title,
|
||||
content_html,
|
||||
tags,
|
||||
cc
|
||||
) do
|
||||
ActivityPub.create(%{
|
||||
to: ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
actor: actor,
|
||||
object: group,
|
||||
local: true
|
||||
})
|
||||
else
|
||||
{:existing_group, _} ->
|
||||
{:error, :existing_group_name}
|
||||
|
||||
{:bad_actor} ->
|
||||
{:error, :bad_admin_actor}
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user