diff options
author | lain <lain@soykaf.club> | 2020-04-09 13:20:16 +0200 |
---|---|---|
committer | lain <lain@soykaf.club> | 2020-04-09 13:20:16 +0200 |
commit | 8e637ae1a7b75fa08679ae9cf424650fc105de85 (patch) | |
tree | 93a8aaf7ede928548d4b0424bc10c05a70a0483d /lib | |
parent | 4b047850718086a6d2edb5b2d94c6f888eba3016 (diff) | |
download | pleroma-8e637ae1a7b75fa08679ae9cf424650fc105de85.tar.gz |
CommonAPI: Basic ChatMessage support.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/common_api/common_api.ex | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 636cf3301..39e15adbf 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -8,6 +8,7 @@ defmodule Pleroma.Web.CommonAPI do alias Pleroma.Conversation.Participation alias Pleroma.FollowingRelationship alias Pleroma.Object + alias Pleroma.Repo alias Pleroma.ThreadMute alias Pleroma.User alias Pleroma.UserRelationship @@ -23,6 +24,28 @@ defmodule Pleroma.Web.CommonAPI do require Pleroma.Constants require Logger + def post_chat_message(user, recipient, content) do + transaction = + Repo.transaction(fn -> + with {_, {:ok, chat_message_data, _meta}} <- + {:build_object, Builder.chat_message(user, recipient.ap_id, content)}, + {_, {:ok, chat_message_object}} <- + {:create_object, Object.create(chat_message_data)}, + {_, {:ok, create_activity_data, _meta}} <- + {:build_create_activity, + Builder.create(user, chat_message_object.data["id"], [recipient.ap_id])}, + {_, {:ok, %Activity{} = activity, _meta}} <- + {:common_pipeline, Pipeline.common_pipeline(create_activity_data, local: true)} do + {:ok, activity} + end + end) + + case transaction do + {:ok, value} -> value + error -> error + end + end + def follow(follower, followed) do timeout = Pleroma.Config.get([:activitypub, :follow_handshake_timeout]) |