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