Add status posting via TwAPI.
[akkoma] / lib / pleroma / web / twitter_api / twitter_api.ex
1 defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
2 alias Pleroma.User
3 alias Pleroma.Web.ActivityPub.ActivityPub
4 alias Pleroma.Repo
5 alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
6
7 def create_status(user = %User{}, data = %{}) do
8 activity = %{
9 "type" => "Create",
10 "to" => [
11 User.ap_followers(user),
12 "https://www.w3.org/ns/activitystreams#Public"
13 ],
14 "actor" => User.ap_id(user),
15 "object" => %{
16 "type" => "Note",
17 "content" => data["status"]
18 }
19 }
20
21 ActivityPub.insert(activity)
22 end
23
24 def fetch_public_statuses do
25 activities = ActivityPub.fetch_public_activities
26
27 Enum.map(activities, fn(activity) ->
28 actor = get_in(activity.data, ["actor"])
29 user = Repo.get_by!(User, ap_id: actor)
30 ActivityRepresenter.to_map(activity, %{user: user})
31 end)
32 end
33 end