Refactor Core things, including Ecto handling, ActivityPub & Transmogrifier modules
* Data doesn't need anymore to be converted to ActivityStream format to be saved (this was taken from Pleroma and not at all a good idea here) * Everything saved when creating an event is inserted into PostgreSQL in a single transaction
This commit is contained in:
@@ -6,38 +6,19 @@ defmodule MobilizonWeb.API.Groups do
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Service.ActivityPub.Utils, as: ActivityPubUtils
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
alias MobilizonWeb.API.Utils
|
||||
alias Mobilizon.Service.ActivityPub.Activity
|
||||
|
||||
@doc """
|
||||
Create a group
|
||||
"""
|
||||
@spec create_group(User.t(), map()) :: {:ok, Activity.t(), Group.t()} | any()
|
||||
def create_group(
|
||||
user,
|
||||
%{
|
||||
preferred_username: title,
|
||||
summary: summary,
|
||||
creator_actor_id: creator_actor_id,
|
||||
avatar: _avatar,
|
||||
banner: _banner
|
||||
} = args
|
||||
) do
|
||||
with {:is_owned, %Actor{} = actor} <- User.owns_actor(user, creator_actor_id),
|
||||
title <- String.trim(title),
|
||||
{:existing_group, nil} <- {:existing_group, Actors.get_group_by_title(title)},
|
||||
visibility <- Map.get(args, :visibility, :public),
|
||||
{content_html, tags, to, cc} <-
|
||||
Utils.prepare_content(actor, summary, visibility, [], nil),
|
||||
group <- ActivityPubUtils.make_group_data(actor.url, to, title, content_html, tags, cc) do
|
||||
ActivityPub.create(%{
|
||||
to: ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
actor: actor,
|
||||
object: group,
|
||||
local: true
|
||||
})
|
||||
@spec create_group(map()) :: {:ok, Activity.t(), Actor.t()} | any()
|
||||
def create_group(args) do
|
||||
with preferred_username <-
|
||||
args |> Map.get(:preferred_username) |> HtmlSanitizeEx.strip_tags() |> String.trim(),
|
||||
{:existing_group, nil} <-
|
||||
{:existing_group, Actors.get_local_group_by_title(preferred_username)},
|
||||
{:ok, %Activity{} = activity, %Actor{} = group} <- ActivityPub.create(:group, args, true) do
|
||||
{:ok, activity, group}
|
||||
else
|
||||
{:existing_group, _} ->
|
||||
{:error, "A group with this name already exists"}
|
||||
|
||||
Reference in New Issue
Block a user