ActivityPub.ex: do not return boosted statuses from blocked users.
[akkoma] / lib / pleroma / web / mastodon_api / mastodon_api_controller.ex
1 defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
2 use Pleroma.Web, :controller
3 alias Pleroma.{Repo, Activity, User, Notification, Stats}
4 alias Pleroma.Web
5 alias Pleroma.Web.MastodonAPI.{StatusView, AccountView, MastodonView}
6 alias Pleroma.Web.ActivityPub.ActivityPub
7 alias Pleroma.Web.{CommonAPI, OStatus}
8 alias Pleroma.Web.OAuth.{Authorization, Token, App}
9 alias Comeonin.Pbkdf2
10 import Ecto.Query
11 require Logger
12
13 def create_app(conn, params) do
14 with cs <- App.register_changeset(%App{}, params) |> IO.inspect(),
15 {:ok, app} <- Repo.insert(cs) |> IO.inspect() do
16 res = %{
17 id: app.id,
18 client_id: app.client_id,
19 client_secret: app.client_secret
20 }
21
22 json(conn, res)
23 end
24 end
25
26 def update_credentials(%{assigns: %{user: user}} = conn, params) do
27 original_user = user
28
29 params =
30 if bio = params["note"] do
31 Map.put(params, "bio", bio)
32 else
33 params
34 end
35
36 params =
37 if name = params["display_name"] do
38 Map.put(params, "name", name)
39 else
40 params
41 end
42
43 user =
44 if avatar = params["avatar"] do
45 with %Plug.Upload{} <- avatar,
46 {:ok, object} <- ActivityPub.upload(avatar),
47 change = Ecto.Changeset.change(user, %{avatar: object.data}),
48 {:ok, user} = User.update_and_set_cache(change) do
49 user
50 else
51 _e -> user
52 end
53 else
54 user
55 end
56
57 user =
58 if banner = params["header"] do
59 with %Plug.Upload{} <- banner,
60 {:ok, object} <- ActivityPub.upload(banner),
61 new_info <- Map.put(user.info, "banner", object.data),
62 change <- User.info_changeset(user, %{info: new_info}),
63 {:ok, user} <- User.update_and_set_cache(change) do
64 user
65 else
66 _e -> user
67 end
68 else
69 user
70 end
71
72 with changeset <- User.update_changeset(user, params),
73 {:ok, user} <- User.update_and_set_cache(changeset) do
74 if original_user != user do
75 CommonAPI.update(user)
76 end
77
78 json(conn, AccountView.render("account.json", %{user: user}))
79 else
80 _e ->
81 conn
82 |> put_status(403)
83 |> json(%{error: "Invalid request"})
84 end
85 end
86
87 def verify_credentials(%{assigns: %{user: user}} = conn, _) do
88 account = AccountView.render("account.json", %{user: user})
89 json(conn, account)
90 end
91
92 def user(conn, %{"id" => id}) do
93 with %User{} = user <- Repo.get(User, id) do
94 account = AccountView.render("account.json", %{user: user})
95 json(conn, account)
96 else
97 _e ->
98 conn
99 |> put_status(404)
100 |> json(%{error: "Can't find user"})
101 end
102 end
103
104 @instance Application.get_env(:pleroma, :instance)
105 @mastodon_api_level "2.3.3"
106
107 def masto_instance(conn, _params) do
108 response = %{
109 uri: Web.base_url(),
110 title: Keyword.get(@instance, :name),
111 description: "A Pleroma instance, an alternative fediverse server",
112 version: "#{@mastodon_api_level} (compatible; #{Keyword.get(@instance, :version)})",
113 email: Keyword.get(@instance, :email),
114 urls: %{
115 streaming_api: String.replace(Web.base_url(), ["http", "https"], "wss")
116 },
117 stats: Stats.get_stats(),
118 thumbnail: Web.base_url() <> "/instance/thumbnail.jpeg",
119 max_toot_chars: Keyword.get(@instance, :limit)
120 }
121
122 json(conn, response)
123 end
124
125 def peers(conn, _params) do
126 json(conn, Stats.get_peers())
127 end
128
129 defp mastodonized_emoji do
130 Pleroma.Formatter.get_custom_emoji()
131 |> Enum.map(fn {shortcode, relative_url} ->
132 url = to_string(URI.merge(Web.base_url(), relative_url))
133
134 %{
135 "shortcode" => shortcode,
136 "static_url" => url,
137 "url" => url
138 }
139 end)
140 end
141
142 def custom_emojis(conn, _params) do
143 mastodon_emoji = mastodonized_emoji()
144 json(conn, mastodon_emoji)
145 end
146
147 defp add_link_headers(conn, method, activities, param \\ false) do
148 last = List.last(activities)
149 first = List.first(activities)
150
151 if last do
152 min = last.id
153 max = first.id
154
155 {next_url, prev_url} =
156 if param do
157 {
158 mastodon_api_url(Pleroma.Web.Endpoint, method, param, max_id: min),
159 mastodon_api_url(Pleroma.Web.Endpoint, method, param, since_id: max)
160 }
161 else
162 {
163 mastodon_api_url(Pleroma.Web.Endpoint, method, max_id: min),
164 mastodon_api_url(Pleroma.Web.Endpoint, method, since_id: max)
165 }
166 end
167
168 conn
169 |> put_resp_header("link", "<#{next_url}>; rel=\"next\", <#{prev_url}>; rel=\"prev\"")
170 else
171 conn
172 end
173 end
174
175 def home_timeline(%{assigns: %{user: user}} = conn, params) do
176 params =
177 params
178 |> Map.put("type", ["Create", "Announce"])
179 |> Map.put("blocking_user", user)
180 |> Map.put("user", user)
181
182 activities =
183 ActivityPub.fetch_activities([user.ap_id | user.following], params)
184 |> Enum.reverse()
185
186 conn
187 |> add_link_headers(:home_timeline, activities)
188 |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
189 end
190
191 def public_timeline(%{assigns: %{user: user}} = conn, params) do
192 params =
193 params
194 |> Map.put("type", ["Create", "Announce"])
195 |> Map.put("local_only", params["local"] in [true, "True", "true", "1"])
196 |> Map.put("blocking_user", user)
197
198 activities =
199 ActivityPub.fetch_public_activities(params)
200 |> Enum.reverse()
201
202 conn
203 |> add_link_headers(:public_timeline, activities)
204 |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
205 end
206
207 def user_statuses(%{assigns: %{user: user}} = conn, params) do
208 with %User{ap_id: ap_id} <- Repo.get(User, params["id"]) do
209 params =
210 params
211 |> Map.put("type", ["Create", "Announce"])
212 |> Map.put("actor_id", ap_id)
213 |> Map.put("whole_db", true)
214
215 activities =
216 ActivityPub.fetch_public_activities(params)
217 |> Enum.reverse()
218
219 conn
220 |> add_link_headers(:user_statuses, activities, params["id"])
221 |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
222 end
223 end
224
225 def get_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
226 with %Activity{} = activity <- Repo.get(Activity, id),
227 true <- ActivityPub.visible_for_user?(activity, user) do
228 render(conn, StatusView, "status.json", %{activity: activity, for: user})
229 end
230 end
231
232 def get_context(%{assigns: %{user: user}} = conn, %{"id" => id}) do
233 with %Activity{} = activity <- Repo.get(Activity, id),
234 activities <-
235 ActivityPub.fetch_activities_for_context(activity.data["context"], %{
236 "blocking_user" => user,
237 "user" => user
238 }),
239 activities <-
240 activities |> Enum.filter(fn %{id: aid} -> to_string(aid) != to_string(id) end),
241 activities <-
242 activities |> Enum.filter(fn %{data: %{"type" => type}} -> type == "Create" end),
243 grouped_activities <- Enum.group_by(activities, fn %{id: id} -> id < activity.id end) do
244 result = %{
245 ancestors:
246 StatusView.render(
247 "index.json",
248 for: user,
249 activities: grouped_activities[true] || [],
250 as: :activity
251 )
252 |> Enum.reverse(),
253 descendants:
254 StatusView.render(
255 "index.json",
256 for: user,
257 activities: grouped_activities[false] || [],
258 as: :activity
259 )
260 |> Enum.reverse()
261 }
262
263 json(conn, result)
264 end
265 end
266
267 def post_status(%{assigns: %{user: user}} = conn, %{"status" => _} = params) do
268 params =
269 params
270 |> Map.put("in_reply_to_status_id", params["in_reply_to_id"])
271 |> Map.put("no_attachment_links", true)
272
273 {:ok, activity} = CommonAPI.post(user, params)
274 render(conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity})
275 end
276
277 def delete_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
278 with {:ok, %Activity{}} <- CommonAPI.delete(id, user) do
279 json(conn, %{})
280 else
281 _e ->
282 conn
283 |> put_status(403)
284 |> json(%{error: "Can't delete this post"})
285 end
286 end
287
288 def reblog_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do
289 with {:ok, announce, _activity} = CommonAPI.repeat(ap_id_or_id, user) do
290 render(conn, StatusView, "status.json", %{activity: announce, for: user, as: :activity})
291 end
292 end
293
294 def fav_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do
295 with {:ok, _fav, %{data: %{"id" => id}}} = CommonAPI.favorite(ap_id_or_id, user),
296 %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do
297 render(conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity})
298 end
299 end
300
301 def unfav_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do
302 with {:ok, %{data: %{"id" => id}}} = CommonAPI.unfavorite(ap_id_or_id, user),
303 %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do
304 render(conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity})
305 end
306 end
307
308 def notifications(%{assigns: %{user: user}} = conn, params) do
309 notifications = Notification.for_user(user, params)
310
311 result =
312 Enum.map(notifications, fn x ->
313 render_notification(user, x)
314 end)
315 |> Enum.filter(& &1)
316
317 conn
318 |> add_link_headers(:notifications, notifications)
319 |> json(result)
320 end
321
322 def get_notification(%{assigns: %{user: user}} = conn, %{"id" => id} = _params) do
323 with {:ok, notification} <- Notification.get(user, id) do
324 json(conn, render_notification(user, notification))
325 else
326 {:error, reason} ->
327 conn
328 |> put_resp_content_type("application/json")
329 |> send_resp(403, Jason.encode!(%{"error" => reason}))
330 end
331 end
332
333 def clear_notifications(%{assigns: %{user: user}} = conn, _params) do
334 Notification.clear(user)
335 json(conn, %{})
336 end
337
338 def dismiss_notification(%{assigns: %{user: user}} = conn, %{"id" => id} = _params) do
339 with {:ok, _notif} <- Notification.dismiss(user, id) do
340 json(conn, %{})
341 else
342 {:error, reason} ->
343 conn
344 |> put_resp_content_type("application/json")
345 |> send_resp(403, Jason.encode!(%{"error" => reason}))
346 end
347 end
348
349 def relationships(%{assigns: %{user: user}} = conn, %{"id" => id}) do
350 id = List.wrap(id)
351 q = from(u in User, where: u.id in ^id)
352 targets = Repo.all(q)
353 render(conn, AccountView, "relationships.json", %{user: user, targets: targets})
354 end
355
356 def upload(%{assigns: %{user: _}} = conn, %{"file" => file}) do
357 with {:ok, object} <- ActivityPub.upload(file) do
358 data =
359 object.data
360 |> Map.put("id", object.id)
361
362 render(conn, StatusView, "attachment.json", %{attachment: data})
363 end
364 end
365
366 def favourited_by(conn, %{"id" => id}) do
367 with %Activity{data: %{"object" => %{"likes" => likes}}} <- Repo.get(Activity, id) do
368 q = from(u in User, where: u.ap_id in ^likes)
369 users = Repo.all(q)
370 render(conn, AccountView, "accounts.json", %{users: users, as: :user})
371 else
372 _ -> json(conn, [])
373 end
374 end
375
376 def reblogged_by(conn, %{"id" => id}) do
377 with %Activity{data: %{"object" => %{"announcements" => announces}}} <- Repo.get(Activity, id) do
378 q = from(u in User, where: u.ap_id in ^announces)
379 users = Repo.all(q)
380 render(conn, AccountView, "accounts.json", %{users: users, as: :user})
381 else
382 _ -> json(conn, [])
383 end
384 end
385
386 def hashtag_timeline(%{assigns: %{user: user}} = conn, params) do
387 params =
388 params
389 |> Map.put("type", "Create")
390 |> Map.put("local_only", !!params["local"])
391 |> Map.put("blocking_user", user)
392
393 activities =
394 ActivityPub.fetch_public_activities(params)
395 |> Enum.reverse()
396
397 conn
398 |> add_link_headers(:hashtag_timeline, activities, params["tag"])
399 |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
400 end
401
402 # TODO: Pagination
403 def followers(conn, %{"id" => id}) do
404 with %User{} = user <- Repo.get(User, id),
405 {:ok, followers} <- User.get_followers(user) do
406 render(conn, AccountView, "accounts.json", %{users: followers, as: :user})
407 end
408 end
409
410 def following(conn, %{"id" => id}) do
411 with %User{} = user <- Repo.get(User, id),
412 {:ok, followers} <- User.get_friends(user) do
413 render(conn, AccountView, "accounts.json", %{users: followers, as: :user})
414 end
415 end
416
417 def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
418 with %User{} = followed <- Repo.get(User, id),
419 {:ok, follower} <- User.follow(follower, followed),
420 {:ok, _activity} <- ActivityPub.follow(follower, followed) do
421 render(conn, AccountView, "relationship.json", %{user: follower, target: followed})
422 else
423 {:error, message} ->
424 conn
425 |> put_resp_content_type("application/json")
426 |> send_resp(403, Jason.encode!(%{"error" => message}))
427 end
428 end
429
430 def follow(%{assigns: %{user: follower}} = conn, %{"uri" => uri}) do
431 with %User{} = followed <- Repo.get_by(User, nickname: uri),
432 {:ok, follower} <- User.follow(follower, followed),
433 {:ok, _activity} <- ActivityPub.follow(follower, followed) do
434 render(conn, AccountView, "account.json", %{user: followed})
435 else
436 {:error, message} ->
437 conn
438 |> put_resp_content_type("application/json")
439 |> send_resp(403, Jason.encode!(%{"error" => message}))
440 end
441 end
442
443 # TODO: Clean up and unify
444 def unfollow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
445 with %User{} = followed <- Repo.get(User, id),
446 {:ok, follower, follow_activity} <- User.unfollow(follower, followed),
447 {:ok, _activity} <-
448 ActivityPub.insert(%{
449 "type" => "Undo",
450 "actor" => follower.ap_id,
451 # get latest Follow for these users
452 "object" => follow_activity.data["id"]
453 }) do
454 render(conn, AccountView, "relationship.json", %{user: follower, target: followed})
455 end
456 end
457
458 def block(%{assigns: %{user: blocker}} = conn, %{"id" => id}) do
459 with %User{} = blocked <- Repo.get(User, id),
460 {:ok, blocker} <- User.block(blocker, blocked) do
461 render(conn, AccountView, "relationship.json", %{user: blocker, target: blocked})
462 else
463 {:error, message} ->
464 conn
465 |> put_resp_content_type("application/json")
466 |> send_resp(403, Jason.encode!(%{"error" => message}))
467 end
468 end
469
470 def unblock(%{assigns: %{user: blocker}} = conn, %{"id" => id}) do
471 with %User{} = blocked <- Repo.get(User, id),
472 {:ok, blocker} <- User.unblock(blocker, blocked) do
473 render(conn, AccountView, "relationship.json", %{user: blocker, target: blocked})
474 else
475 {:error, message} ->
476 conn
477 |> put_resp_content_type("application/json")
478 |> send_resp(403, Jason.encode!(%{"error" => message}))
479 end
480 end
481
482 # TODO: Use proper query
483 def blocks(%{assigns: %{user: user}} = conn, _) do
484 with blocked_users <- user.info["blocks"] || [],
485 accounts <- Enum.map(blocked_users, fn ap_id -> User.get_cached_by_ap_id(ap_id) end) do
486 res = AccountView.render("accounts.json", users: accounts, for: user, as: :user)
487 json(conn, res)
488 end
489 end
490
491 def search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do
492 accounts = User.search(query, params["resolve"] == "true")
493
494 fetched =
495 if Regex.match?(~r/https?:/, query) do
496 with {:ok, activities} <- OStatus.fetch_activity_from_url(query) do
497 activities
498 |> Enum.filter(fn
499 %{data: %{"type" => "Create"}} -> true
500 _ -> false
501 end)
502 else
503 _e -> []
504 end
505 end || []
506
507 q =
508 from(
509 a in Activity,
510 where: fragment("?->>'type' = 'Create'", a.data),
511 where: "https://www.w3.org/ns/activitystreams#Public" in a.recipients,
512 where:
513 fragment(
514 "to_tsvector('english', ?->'object'->>'content') @@ plainto_tsquery('english', ?)",
515 a.data,
516 ^query
517 ),
518 limit: 20,
519 order_by: [desc: :inserted_at]
520 )
521
522 statuses = Repo.all(q) ++ fetched
523
524 tags =
525 String.split(query)
526 |> Enum.uniq()
527 |> Enum.filter(fn tag -> String.starts_with?(tag, "#") end)
528 |> Enum.map(fn tag -> String.slice(tag, 1..-1) end)
529
530 res = %{
531 "accounts" => AccountView.render("accounts.json", users: accounts, for: user, as: :user),
532 "statuses" =>
533 StatusView.render("index.json", activities: statuses, for: user, as: :activity),
534 "hashtags" => tags
535 }
536
537 json(conn, res)
538 end
539
540 def account_search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do
541 accounts = User.search(query, params["resolve"] == "true")
542
543 res = AccountView.render("accounts.json", users: accounts, for: user, as: :user)
544
545 json(conn, res)
546 end
547
548 def favourites(%{assigns: %{user: user}} = conn, _) do
549 params =
550 %{}
551 |> Map.put("type", "Create")
552 |> Map.put("favorited_by", user.ap_id)
553 |> Map.put("blocking_user", user)
554
555 activities =
556 ActivityPub.fetch_public_activities(params)
557 |> Enum.reverse()
558
559 conn
560 |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
561 end
562
563 def index(%{assigns: %{user: user}} = conn, _params) do
564 token =
565 conn
566 |> get_session(:oauth_token)
567
568 if user && token do
569 mastodon_emoji = mastodonized_emoji()
570 accounts = Map.put(%{}, user.id, AccountView.render("account.json", %{user: user}))
571
572 initial_state =
573 %{
574 meta: %{
575 streaming_api_base_url:
576 String.replace(Pleroma.Web.Endpoint.static_url(), "http", "ws"),
577 access_token: token,
578 locale: "en",
579 domain: Pleroma.Web.Endpoint.host(),
580 admin: "1",
581 me: "#{user.id}",
582 unfollow_modal: false,
583 boost_modal: false,
584 delete_modal: true,
585 auto_play_gif: false,
586 reduce_motion: false
587 },
588 compose: %{
589 me: "#{user.id}",
590 default_privacy: "public",
591 default_sensitive: false
592 },
593 media_attachments: %{
594 accept_content_types: [
595 ".jpg",
596 ".jpeg",
597 ".png",
598 ".gif",
599 ".webm",
600 ".mp4",
601 ".m4v",
602 "image\/jpeg",
603 "image\/png",
604 "image\/gif",
605 "video\/webm",
606 "video\/mp4"
607 ]
608 },
609 settings:
610 Map.get(user.info, "settings") ||
611 %{
612 onboarded: true,
613 home: %{
614 shows: %{
615 reblog: true,
616 reply: true
617 }
618 },
619 notifications: %{
620 alerts: %{
621 follow: true,
622 favourite: true,
623 reblog: true,
624 mention: true
625 },
626 shows: %{
627 follow: true,
628 favourite: true,
629 reblog: true,
630 mention: true
631 },
632 sounds: %{
633 follow: true,
634 favourite: true,
635 reblog: true,
636 mention: true
637 }
638 }
639 },
640 push_subscription: nil,
641 accounts: accounts,
642 custom_emojis: mastodon_emoji,
643 char_limit: Keyword.get(@instance, :limit)
644 }
645 |> Jason.encode!()
646
647 conn
648 |> put_layout(false)
649 |> render(MastodonView, "index.html", %{initial_state: initial_state})
650 else
651 conn
652 |> redirect(to: "/web/login")
653 end
654 end
655
656 def put_settings(%{assigns: %{user: user}} = conn, %{"data" => settings} = _params) do
657 with new_info <- Map.put(user.info, "settings", settings),
658 change <- User.info_changeset(user, %{info: new_info}),
659 {:ok, _user} <- User.update_and_set_cache(change) do
660 conn
661 |> json(%{})
662 else
663 e ->
664 conn
665 |> json(%{error: inspect(e)})
666 end
667 end
668
669 def login(conn, _) do
670 conn
671 |> render(MastodonView, "login.html", %{error: false})
672 end
673
674 defp get_or_make_app() do
675 with %App{} = app <- Repo.get_by(App, client_name: "Mastodon-Local") do
676 {:ok, app}
677 else
678 _e ->
679 cs =
680 App.register_changeset(%App{}, %{
681 client_name: "Mastodon-Local",
682 redirect_uris: ".",
683 scopes: "read,write,follow"
684 })
685
686 Repo.insert(cs)
687 end
688 end
689
690 def login_post(conn, %{"authorization" => %{"name" => name, "password" => password}}) do
691 with %User{} = user <- User.get_cached_by_nickname(name),
692 true <- Pbkdf2.checkpw(password, user.password_hash),
693 {:ok, app} <- get_or_make_app(),
694 {:ok, auth} <- Authorization.create_authorization(app, user),
695 {:ok, token} <- Token.exchange_token(app, auth) do
696 conn
697 |> put_session(:oauth_token, token.token)
698 |> redirect(to: "/web/getting-started")
699 else
700 _e ->
701 conn
702 |> render(MastodonView, "login.html", %{error: "Wrong username or password"})
703 end
704 end
705
706 def logout(conn, _) do
707 conn
708 |> clear_session
709 |> redirect(to: "/")
710 end
711
712 def relationship_noop(%{assigns: %{user: user}} = conn, %{"id" => id}) do
713 Logger.debug("Unimplemented, returning unmodified relationship")
714
715 with %User{} = target <- Repo.get(User, id) do
716 render(conn, AccountView, "relationship.json", %{user: user, target: target})
717 end
718 end
719
720 def empty_array(conn, _) do
721 Logger.debug("Unimplemented, returning an empty array")
722 json(conn, [])
723 end
724
725 def empty_object(conn, _) do
726 Logger.debug("Unimplemented, returning an empty object")
727 json(conn, %{})
728 end
729
730 def render_notification(user, %{id: id, activity: activity, inserted_at: created_at} = _params) do
731 actor = User.get_cached_by_ap_id(activity.data["actor"])
732
733 created_at =
734 NaiveDateTime.to_iso8601(created_at)
735 |> String.replace(~r/(\.\d+)?$/, ".000Z", global: false)
736
737 case activity.data["type"] do
738 "Create" ->
739 %{
740 id: id,
741 type: "mention",
742 created_at: created_at,
743 account: AccountView.render("account.json", %{user: actor}),
744 status: StatusView.render("status.json", %{activity: activity, for: user})
745 }
746
747 "Like" ->
748 liked_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"])
749
750 %{
751 id: id,
752 type: "favourite",
753 created_at: created_at,
754 account: AccountView.render("account.json", %{user: actor}),
755 status: StatusView.render("status.json", %{activity: liked_activity, for: user})
756 }
757
758 "Announce" ->
759 announced_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"])
760
761 %{
762 id: id,
763 type: "reblog",
764 created_at: created_at,
765 account: AccountView.render("account.json", %{user: actor}),
766 status: StatusView.render("status.json", %{activity: announced_activity, for: user})
767 }
768
769 "Follow" ->
770 %{
771 id: id,
772 type: "follow",
773 created_at: created_at,
774 account: AccountView.render("account.json", %{user: actor})
775 }
776
777 _ ->
778 nil
779 end
780 end
781 end