1 # THIS MODULE IS DEPRECATED! DON'T USE IT!
2 # USE THE Pleroma.Web.TwitterAPI.Views.ActivityView MODULE!
3 defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
4 use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter
5 alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
6 alias Pleroma.{Activity, User}
7 alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView}
8 alias Pleroma.Web.CommonAPI.Utils
9 alias Pleroma.Formatter
12 defp user_by_ap_id(user_list, ap_id) do
13 Enum.find(user_list, fn %{ap_id: user_id} -> ap_id == user_id end)
17 %Activity{data: %{"type" => "Announce", "actor" => actor, "published" => created_at}} =
19 %{users: users, announced_activity: announced_activity} = opts
21 user = user_by_ap_id(users, actor)
22 created_at = created_at |> Utils.date_to_asctime()
24 text = "#{user.nickname} retweeted a status."
26 announced_user = user_by_ap_id(users, announced_activity.data["actor"])
27 retweeted_status = to_map(announced_activity, Map.merge(%{user: announced_user}, opts))
31 "user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
32 "statusnet_html" => text,
34 "is_local" => activity.local,
35 "is_post_verb" => false,
36 "uri" => "tag:#{activity.data["id"]}:objectType=note",
37 "created_at" => created_at,
38 "retweeted_status" => retweeted_status,
39 "statusnet_conversation_id" => conversation_id(announced_activity),
40 "external_url" => activity.data["id"],
41 "activity_type" => "repeat"
46 %Activity{data: %{"type" => "Like", "published" => created_at}} = activity,
47 %{user: user, liked_activity: liked_activity} = opts
49 created_at = created_at |> Utils.date_to_asctime()
51 text = "#{user.nickname} favorited a status."
55 "user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
56 "statusnet_html" => text,
58 "is_local" => activity.local,
59 "is_post_verb" => false,
60 "uri" => "tag:#{activity.data["id"]}:objectType=Favourite",
61 "created_at" => created_at,
62 "in_reply_to_status_id" => liked_activity.id,
63 "external_url" => activity.data["id"],
64 "activity_type" => "like"
69 %Activity{data: %{"type" => "Follow", "object" => followed_id}} = activity,
72 created_at = activity.data["published"] || DateTime.to_iso8601(activity.inserted_at)
73 created_at = created_at |> Utils.date_to_asctime()
75 followed = User.get_cached_by_ap_id(followed_id)
76 text = "#{user.nickname} started following #{followed.nickname}"
80 "user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
82 "statusnet_html" => text,
84 "is_local" => activity.local,
85 "is_post_verb" => false,
86 "created_at" => created_at,
87 "in_reply_to_status_id" => nil,
88 "external_url" => activity.data["id"],
89 "activity_type" => "follow"
94 # Make this more proper. Just a placeholder to not break the frontend.
97 data: %{"type" => "Undo", "published" => created_at, "object" => undid_activity}
101 created_at = created_at |> Utils.date_to_asctime()
103 text = "#{user.nickname} undid the action at #{undid_activity["id"]}"
107 "user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
109 "statusnet_html" => text,
111 "is_local" => activity.local,
112 "is_post_verb" => false,
113 "created_at" => created_at,
114 "in_reply_to_status_id" => nil,
115 "external_url" => activity.data["id"],
116 "activity_type" => "undo"
121 %Activity{data: %{"type" => "Delete", "published" => created_at, "object" => _}} =
125 created_at = created_at |> Utils.date_to_asctime()
129 "uri" => activity.data["object"],
130 "user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
132 "statusnet_html" => "deleted notice {{tag",
133 "text" => "deleted notice {{tag",
134 "is_local" => activity.local,
135 "is_post_verb" => false,
136 "created_at" => created_at,
137 "in_reply_to_status_id" => nil,
138 "external_url" => activity.data["id"],
139 "activity_type" => "delete"
144 %Activity{data: %{"object" => %{"content" => content} = object}} = activity,
147 created_at = object["published"] |> Utils.date_to_asctime()
148 like_count = object["like_count"] || 0
149 announcement_count = object["announcement_count"] || 0
150 favorited = opts[:for] && opts[:for].ap_id in (object["likes"] || [])
151 repeated = opts[:for] && opts[:for].ap_id in (object["announcements"] || [])
153 mentions = opts[:mentioned] || []
157 |> Enum.map(fn ap_id -> Enum.find(mentions, fn user -> ap_id == user.ap_id end) end)
159 |> Enum.map(fn user -> UserView.render("show.json", %{user: user, for: opts[:for]}) end)
161 conversation_id = conversation_id(activity)
163 tags = activity.data["object"]["tag"] || []
164 possibly_sensitive = activity.data["object"]["sensitive"] || Enum.member?(tags, "nsfw")
166 tags = if possibly_sensitive, do: Enum.uniq(["nsfw" | tags]), else: tags
168 {summary, content} = ActivityView.render_content(object)
171 HTML.filter_tags(content, User.html_filter_policy(opts[:for]))
172 |> Formatter.emojify(object["emoji"])
175 if object["type"] == "Video" do
181 attachments = (object["attachment"] || []) ++ video
185 "uri" => activity.data["object"]["id"],
186 "user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
187 "statusnet_html" => html,
188 "text" => HTML.strip_tags(content),
189 "is_local" => activity.local,
190 "is_post_verb" => true,
191 "created_at" => created_at,
192 "in_reply_to_status_id" => object["inReplyToStatusId"],
193 "statusnet_conversation_id" => conversation_id,
194 "attachments" => attachments |> ObjectRepresenter.enum_to_list(opts),
195 "attentions" => attentions,
196 "fave_num" => like_count,
197 "repeat_num" => announcement_count,
198 "favorited" => to_boolean(favorited),
199 "repeated" => to_boolean(repeated),
200 "external_url" => object["external_url"] || object["id"],
202 "activity_type" => "post",
203 "possibly_sensitive" => possibly_sensitive,
204 "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object),
205 "summary" => object["summary"]
209 def conversation_id(activity) do
210 with context when not is_nil(context) <- activity.data["context"] do
211 TwitterAPI.context_to_conversation_id(context)
217 defp to_boolean(false) do
221 defp to_boolean(nil) do
225 defp to_boolean(_) do