1 defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
2 use Pleroma.Web, :controller
3 alias Pleroma.{Repo, Activity, User, Notification, Stats}
5 alias Pleroma.Web.MastodonAPI.{StatusView, AccountView, MastodonView, ListView}
6 alias Pleroma.Web.ActivityPub.ActivityPub
7 alias Pleroma.Web.ActivityPub.Utils
8 alias Pleroma.Web.{CommonAPI, OStatus}
9 alias Pleroma.Web.OAuth.{Authorization, Token, App}
14 action_fallback(:errors)
16 def create_app(conn, params) do
17 with cs <- App.register_changeset(%App{}, params) |> IO.inspect(),
18 {:ok, app} <- Repo.insert(cs) |> IO.inspect() do
21 client_id: app.client_id,
22 client_secret: app.client_secret
29 def update_credentials(%{assigns: %{user: user}} = conn, params) do
33 if bio = params["note"] do
34 Map.put(params, "bio", bio)
40 if name = params["display_name"] do
41 Map.put(params, "name", name)
47 if avatar = params["avatar"] do
48 with %Plug.Upload{} <- avatar,
49 {:ok, object} <- ActivityPub.upload(avatar),
50 change = Ecto.Changeset.change(user, %{avatar: object.data}),
51 {:ok, user} = User.update_and_set_cache(change) do
61 if banner = params["header"] do
62 with %Plug.Upload{} <- banner,
63 {:ok, object} <- ActivityPub.upload(banner),
64 new_info <- Map.put(user.info, "banner", object.data),
65 change <- User.info_changeset(user, %{info: new_info}),
66 {:ok, user} <- User.update_and_set_cache(change) do
76 if locked = params["locked"] do
77 with locked <- locked == "true",
78 new_info <- Map.put(user.info, "locked", locked),
79 change <- User.info_changeset(user, %{info: new_info}),
80 {:ok, user} <- User.update_and_set_cache(change) do
89 with changeset <- User.update_changeset(user, params),
90 {:ok, user} <- User.update_and_set_cache(changeset) do
91 if original_user != user do
92 CommonAPI.update(user)
95 json(conn, AccountView.render("account.json", %{user: user}))
100 |> json(%{error: "Invalid request"})
104 def verify_credentials(%{assigns: %{user: user}} = conn, _) do
105 account = AccountView.render("account.json", %{user: user})
109 def user(conn, %{"id" => id}) do
110 with %User{} = user <- Repo.get(User, id) do
111 account = AccountView.render("account.json", %{user: user})
117 |> json(%{error: "Can't find user"})
121 @instance Application.get_env(:pleroma, :instance)
122 @mastodon_api_level "2.3.3"
124 def masto_instance(conn, _params) do
127 title: Keyword.get(@instance, :name),
128 description: "A Pleroma instance, an alternative fediverse server",
129 version: "#{@mastodon_api_level} (compatible; #{Keyword.get(@instance, :version)})",
130 email: Keyword.get(@instance, :email),
132 streaming_api: String.replace(Pleroma.Web.Endpoint.static_url(), "http", "ws")
134 stats: Stats.get_stats(),
135 thumbnail: Web.base_url() <> "/instance/thumbnail.jpeg",
136 max_toot_chars: Keyword.get(@instance, :limit)
142 def peers(conn, _params) do
143 json(conn, Stats.get_peers())
146 defp mastodonized_emoji do
147 Pleroma.Formatter.get_custom_emoji()
148 |> Enum.map(fn {shortcode, relative_url} ->
149 url = to_string(URI.merge(Web.base_url(), relative_url))
152 "shortcode" => shortcode,
154 "visible_in_picker" => true,
160 def custom_emojis(conn, _params) do
161 mastodon_emoji = mastodonized_emoji()
162 json(conn, mastodon_emoji)
165 defp add_link_headers(conn, method, activities, param \\ nil, params \\ %{}) do
166 last = List.last(activities)
167 first = List.first(activities)
173 {next_url, prev_url} =
177 Pleroma.Web.Endpoint,
180 Map.merge(params, %{max_id: min})
183 Pleroma.Web.Endpoint,
186 Map.merge(params, %{since_id: max})
192 Pleroma.Web.Endpoint,
194 Map.merge(params, %{max_id: min})
197 Pleroma.Web.Endpoint,
199 Map.merge(params, %{since_id: max})
205 |> put_resp_header("link", "<#{next_url}>; rel=\"next\", <#{prev_url}>; rel=\"prev\"")
211 def home_timeline(%{assigns: %{user: user}} = conn, params) do
214 |> Map.put("type", ["Create", "Announce"])
215 |> Map.put("blocking_user", user)
216 |> Map.put("user", user)
219 ActivityPub.fetch_activities([user.ap_id | user.following], params)
223 |> add_link_headers(:home_timeline, activities)
224 |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
227 def public_timeline(%{assigns: %{user: user}} = conn, params) do
228 local_only = params["local"] in [true, "True", "true", "1"]
232 |> Map.put("type", ["Create", "Announce"])
233 |> Map.put("local_only", local_only)
234 |> Map.put("blocking_user", user)
237 ActivityPub.fetch_public_activities(params)
241 |> add_link_headers(:public_timeline, activities, false, %{"local" => local_only})
242 |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
245 def user_statuses(%{assigns: %{user: reading_user}} = conn, params) do
246 with %User{} = user <- Repo.get(User, params["id"]) do
247 # Since Pleroma has no "pinned" posts feature, we'll just set an empty list here
249 if params["pinned"] == "true" do
252 ActivityPub.fetch_user_activities(user, reading_user, params)
256 |> add_link_headers(:user_statuses, activities, params["id"])
257 |> render(StatusView, "index.json", %{
258 activities: activities,
265 def dm_timeline(%{assigns: %{user: user}} = conn, _params) do
267 ActivityPub.fetch_activities_query([user.ap_id], %{"type" => "Create", visibility: "direct"})
269 activities = Repo.all(query)
272 |> add_link_headers(:dm_timeline, activities)
273 |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
276 def get_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
277 with %Activity{} = activity <- Repo.get(Activity, id),
278 true <- ActivityPub.visible_for_user?(activity, user) do
279 render(conn, StatusView, "status.json", %{activity: activity, for: user})
283 def get_context(%{assigns: %{user: user}} = conn, %{"id" => id}) do
284 with %Activity{} = activity <- Repo.get(Activity, id),
286 ActivityPub.fetch_activities_for_context(activity.data["context"], %{
287 "blocking_user" => user,
291 activities |> Enum.filter(fn %{id: aid} -> to_string(aid) != to_string(id) end),
293 activities |> Enum.filter(fn %{data: %{"type" => type}} -> type == "Create" end),
294 grouped_activities <- Enum.group_by(activities, fn %{id: id} -> id < activity.id end) do
300 activities: grouped_activities[true] || [],
308 activities: grouped_activities[false] || [],
318 def post_status(conn, %{"status" => "", "media_ids" => media_ids} = params)
319 when length(media_ids) > 0 do
322 |> Map.put("status", ".")
324 post_status(conn, params)
327 def post_status(%{assigns: %{user: user}} = conn, %{"status" => _} = params) do
330 |> Map.put("in_reply_to_status_id", params["in_reply_to_id"])
331 |> Map.put("no_attachment_links", true)
334 case get_req_header(conn, "idempotency-key") do
336 _ -> Ecto.UUID.generate()
340 Cachex.fetch!(:idempotency_cache, idempotency_key, fn _ -> CommonAPI.post(user, params) end)
342 render(conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity})
345 def delete_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
346 with {:ok, %Activity{}} <- CommonAPI.delete(id, user) do
352 |> json(%{error: "Can't delete this post"})
356 def reblog_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do
357 with {:ok, announce, _activity} <- CommonAPI.repeat(ap_id_or_id, user) do
358 render(conn, StatusView, "status.json", %{activity: announce, for: user, as: :activity})
362 def unreblog_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do
363 with {:ok, _unannounce, %{data: %{"id" => id}}} <- CommonAPI.unrepeat(ap_id_or_id, user),
364 %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do
365 render(conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity})
369 def fav_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do
370 with {:ok, _fav, %{data: %{"id" => id}}} <- CommonAPI.favorite(ap_id_or_id, user),
371 %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do
372 render(conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity})
376 def unfav_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do
377 with {:ok, _, _, %{data: %{"id" => id}}} <- CommonAPI.unfavorite(ap_id_or_id, user),
378 %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do
379 render(conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity})
383 def notifications(%{assigns: %{user: user}} = conn, params) do
384 notifications = Notification.for_user(user, params)
387 Enum.map(notifications, fn x ->
388 render_notification(user, x)
393 |> add_link_headers(:notifications, notifications)
397 def get_notification(%{assigns: %{user: user}} = conn, %{"id" => id} = _params) do
398 with {:ok, notification} <- Notification.get(user, id) do
399 json(conn, render_notification(user, notification))
403 |> put_resp_content_type("application/json")
404 |> send_resp(403, Jason.encode!(%{"error" => reason}))
408 def clear_notifications(%{assigns: %{user: user}} = conn, _params) do
409 Notification.clear(user)
413 def dismiss_notification(%{assigns: %{user: user}} = conn, %{"id" => id} = _params) do
414 with {:ok, _notif} <- Notification.dismiss(user, id) do
419 |> put_resp_content_type("application/json")
420 |> send_resp(403, Jason.encode!(%{"error" => reason}))
424 def relationships(%{assigns: %{user: user}} = conn, %{"id" => id}) do
426 q = from(u in User, where: u.id in ^id)
427 targets = Repo.all(q)
428 render(conn, AccountView, "relationships.json", %{user: user, targets: targets})
431 def upload(%{assigns: %{user: _}} = conn, %{"file" => file}) do
432 with {:ok, object} <- ActivityPub.upload(file) do
435 |> Map.put("id", object.id)
437 render(conn, StatusView, "attachment.json", %{attachment: data})
441 def favourited_by(conn, %{"id" => id}) do
442 with %Activity{data: %{"object" => %{"likes" => likes}}} <- Repo.get(Activity, id) do
443 q = from(u in User, where: u.ap_id in ^likes)
445 render(conn, AccountView, "accounts.json", %{users: users, as: :user})
451 def reblogged_by(conn, %{"id" => id}) do
452 with %Activity{data: %{"object" => %{"announcements" => announces}}} <- Repo.get(Activity, id) do
453 q = from(u in User, where: u.ap_id in ^announces)
455 render(conn, AccountView, "accounts.json", %{users: users, as: :user})
461 def hashtag_timeline(%{assigns: %{user: user}} = conn, params) do
462 local_only = params["local"] in [true, "True", "true", "1"]
466 |> Map.put("type", "Create")
467 |> Map.put("local_only", local_only)
468 |> Map.put("blocking_user", user)
471 ActivityPub.fetch_public_activities(params)
475 |> add_link_headers(:hashtag_timeline, activities, params["tag"], %{"local" => local_only})
476 |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
480 def followers(conn, %{"id" => id}) do
481 with %User{} = user <- Repo.get(User, id),
482 {:ok, followers} <- User.get_followers(user) do
483 render(conn, AccountView, "accounts.json", %{users: followers, as: :user})
487 def following(conn, %{"id" => id}) do
488 with %User{} = user <- Repo.get(User, id),
489 {:ok, followers} <- User.get_friends(user) do
490 render(conn, AccountView, "accounts.json", %{users: followers, as: :user})
494 def follow_requests(%{assigns: %{user: followed}} = conn, _params) do
495 with {:ok, follow_requests} <- User.get_follow_requests(followed) do
496 render(conn, AccountView, "accounts.json", %{users: follow_requests, as: :user})
500 def authorize_follow_request(%{assigns: %{user: followed}} = conn, %{"id" => id}) do
501 with %User{} = follower <- Repo.get(User, id),
502 {:ok, follower} <- User.maybe_follow(follower, followed),
503 %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed),
504 {:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "accept"),
506 ActivityPub.accept(%{
507 to: [follower.ap_id],
508 actor: followed.ap_id,
509 object: follow_activity.data["id"],
512 render(conn, AccountView, "relationship.json", %{user: followed, target: follower})
516 |> put_resp_content_type("application/json")
517 |> send_resp(403, Jason.encode!(%{"error" => message}))
521 def reject_follow_request(%{assigns: %{user: followed}} = conn, %{"id" => id}) do
522 with %User{} = follower <- Repo.get(User, id),
523 %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed),
524 {:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "reject"),
526 ActivityPub.reject(%{
527 to: [follower.ap_id],
528 actor: followed.ap_id,
529 object: follow_activity.data["id"],
532 render(conn, AccountView, "relationship.json", %{user: followed, target: follower})
536 |> put_resp_content_type("application/json")
537 |> send_resp(403, Jason.encode!(%{"error" => message}))
541 def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
542 with %User{} = followed <- Repo.get(User, id),
543 {:ok, follower} <- User.maybe_direct_follow(follower, followed),
544 {:ok, _activity} <- ActivityPub.follow(follower, followed) do
545 render(conn, AccountView, "relationship.json", %{user: follower, target: followed})
549 |> put_resp_content_type("application/json")
550 |> send_resp(403, Jason.encode!(%{"error" => message}))
554 def follow(%{assigns: %{user: follower}} = conn, %{"uri" => uri}) do
555 with %User{} = followed <- Repo.get_by(User, nickname: uri),
556 {:ok, follower} <- User.maybe_direct_follow(follower, followed),
557 {:ok, _activity} <- ActivityPub.follow(follower, followed) do
558 render(conn, AccountView, "account.json", %{user: followed})
562 |> put_resp_content_type("application/json")
563 |> send_resp(403, Jason.encode!(%{"error" => message}))
567 def unfollow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
568 with %User{} = followed <- Repo.get(User, id),
569 {:ok, _activity} <- ActivityPub.unfollow(follower, followed),
570 {:ok, follower, _} <- User.unfollow(follower, followed) do
571 render(conn, AccountView, "relationship.json", %{user: follower, target: followed})
575 def block(%{assigns: %{user: blocker}} = conn, %{"id" => id}) do
576 with %User{} = blocked <- Repo.get(User, id),
577 {:ok, blocker} <- User.block(blocker, blocked),
578 {:ok, _activity} <- ActivityPub.block(blocker, blocked) do
579 render(conn, AccountView, "relationship.json", %{user: blocker, target: blocked})
583 |> put_resp_content_type("application/json")
584 |> send_resp(403, Jason.encode!(%{"error" => message}))
588 def unblock(%{assigns: %{user: blocker}} = conn, %{"id" => id}) do
589 with %User{} = blocked <- Repo.get(User, id),
590 {:ok, blocker} <- User.unblock(blocker, blocked),
591 {:ok, _activity} <- ActivityPub.unblock(blocker, blocked) do
592 render(conn, AccountView, "relationship.json", %{user: blocker, target: blocked})
596 |> put_resp_content_type("application/json")
597 |> send_resp(403, Jason.encode!(%{"error" => message}))
601 # TODO: Use proper query
602 def blocks(%{assigns: %{user: user}} = conn, _) do
603 with blocked_users <- user.info["blocks"] || [],
604 accounts <- Enum.map(blocked_users, fn ap_id -> User.get_cached_by_ap_id(ap_id) end) do
605 res = AccountView.render("accounts.json", users: accounts, for: user, as: :user)
610 def domain_blocks(%{assigns: %{user: %{info: info}}} = conn, _) do
611 json(conn, info["domain_blocks"] || [])
614 def block_domain(%{assigns: %{user: blocker}} = conn, %{"domain" => domain}) do
615 User.block_domain(blocker, domain)
619 def unblock_domain(%{assigns: %{user: blocker}} = conn, %{"domain" => domain}) do
620 User.unblock_domain(blocker, domain)
624 def search2(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do
625 accounts = User.search(query, params["resolve"] == "true")
628 if Regex.match?(~r/https?:/, query) do
629 with {:ok, activities} <- OStatus.fetch_activity_from_url(query) do
632 %{data: %{"type" => "Create"}} -> true
643 where: fragment("?->>'type' = 'Create'", a.data),
644 where: "https://www.w3.org/ns/activitystreams#Public" in a.recipients,
647 "to_tsvector('english', ?->'object'->>'content') @@ plainto_tsquery('english', ?)",
652 order_by: [desc: :id]
655 statuses = Repo.all(q) ++ fetched
657 tags_path = Web.base_url() <> "/tag/"
662 |> Enum.filter(fn tag -> String.starts_with?(tag, "#") end)
663 |> Enum.map(fn tag -> String.slice(tag, 1..-1) end)
664 |> Enum.map(fn tag -> %{name: tag, url: tags_path <> tag} end)
667 "accounts" => AccountView.render("accounts.json", users: accounts, for: user, as: :user),
669 StatusView.render("index.json", activities: statuses, for: user, as: :activity),
676 def search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do
677 accounts = User.search(query, params["resolve"] == "true")
680 if Regex.match?(~r/https?:/, query) do
681 with {:ok, activities} <- OStatus.fetch_activity_from_url(query) do
684 %{data: %{"type" => "Create"}} -> true
695 where: fragment("?->>'type' = 'Create'", a.data),
696 where: "https://www.w3.org/ns/activitystreams#Public" in a.recipients,
699 "to_tsvector('english', ?->'object'->>'content') @@ plainto_tsquery('english', ?)",
704 order_by: [desc: :id]
707 statuses = Repo.all(q) ++ fetched
712 |> Enum.filter(fn tag -> String.starts_with?(tag, "#") end)
713 |> Enum.map(fn tag -> String.slice(tag, 1..-1) end)
716 "accounts" => AccountView.render("accounts.json", users: accounts, for: user, as: :user),
718 StatusView.render("index.json", activities: statuses, for: user, as: :activity),
725 def account_search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do
726 accounts = User.search(query, params["resolve"] == "true")
728 res = AccountView.render("accounts.json", users: accounts, for: user, as: :user)
733 def favourites(%{assigns: %{user: user}} = conn, _) do
736 |> Map.put("type", "Create")
737 |> Map.put("favorited_by", user.ap_id)
738 |> Map.put("blocking_user", user)
741 ActivityPub.fetch_public_activities(params)
745 |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
748 def get_lists(%{assigns: %{user: user}} = conn, opts) do
749 lists = Pleroma.List.for_user(user, opts)
750 res = ListView.render("lists.json", lists: lists)
754 def get_list(%{assigns: %{user: user}} = conn, %{"id" => id}) do
755 with %Pleroma.List{} = list <- Pleroma.List.get(id, user) do
756 res = ListView.render("list.json", list: list)
759 _e -> json(conn, "error")
763 def delete_list(%{assigns: %{user: user}} = conn, %{"id" => id}) do
764 with %Pleroma.List{} = list <- Pleroma.List.get(id, user),
765 {:ok, _list} <- Pleroma.List.delete(list) do
773 def create_list(%{assigns: %{user: user}} = conn, %{"title" => title}) do
774 with {:ok, %Pleroma.List{} = list} <- Pleroma.List.create(title, user) do
775 res = ListView.render("list.json", list: list)
780 def add_to_list(%{assigns: %{user: user}} = conn, %{"id" => id, "account_ids" => accounts}) do
782 |> Enum.each(fn account_id ->
783 with %Pleroma.List{} = list <- Pleroma.List.get(id, user),
784 %User{} = followed <- Repo.get(User, account_id) do
785 Pleroma.List.follow(list, followed)
792 def remove_from_list(%{assigns: %{user: user}} = conn, %{"id" => id, "account_ids" => accounts}) do
794 |> Enum.each(fn account_id ->
795 with %Pleroma.List{} = list <- Pleroma.List.get(id, user),
796 %User{} = followed <- Repo.get(Pleroma.User, account_id) do
797 Pleroma.List.unfollow(list, followed)
804 def list_accounts(%{assigns: %{user: user}} = conn, %{"id" => id}) do
805 with %Pleroma.List{} = list <- Pleroma.List.get(id, user),
806 {:ok, users} = Pleroma.List.get_following(list) do
807 render(conn, AccountView, "accounts.json", %{users: users, as: :user})
811 def rename_list(%{assigns: %{user: user}} = conn, %{"id" => id, "title" => title}) do
812 with %Pleroma.List{} = list <- Pleroma.List.get(id, user),
813 {:ok, list} <- Pleroma.List.rename(list, title) do
814 res = ListView.render("list.json", list: list)
822 def list_timeline(%{assigns: %{user: user}} = conn, %{"list_id" => id} = params) do
823 with %Pleroma.List{title: title, following: following} <- Pleroma.List.get(id, user) do
826 |> Map.put("type", "Create")
827 |> Map.put("blocking_user", user)
829 # adding title is a hack to not make empty lists function like a public timeline
831 ActivityPub.fetch_activities([title | following], params)
835 |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
840 |> json(%{error: "Error."})
844 def index(%{assigns: %{user: user}} = conn, _params) do
847 |> get_session(:oauth_token)
850 mastodon_emoji = mastodonized_emoji()
851 accounts = Map.put(%{}, user.id, AccountView.render("account.json", %{user: user}))
856 streaming_api_base_url:
857 String.replace(Pleroma.Web.Endpoint.static_url(), "http", "ws"),
860 domain: Pleroma.Web.Endpoint.host(),
863 unfollow_modal: false,
866 auto_play_gif: false,
867 display_sensitive_media: false,
868 reduce_motion: false,
869 max_toot_chars: Keyword.get(@instance, :limit)
873 default_privacy: "public",
874 default_sensitive: false
876 media_attachments: %{
877 accept_content_types: [
893 Map.get(user.info, "settings") ||
923 push_subscription: nil,
925 custom_emojis: mastodon_emoji,
926 char_limit: Keyword.get(@instance, :limit)
932 |> render(MastodonView, "index.html", %{initial_state: initial_state})
935 |> redirect(to: "/web/login")
939 def put_settings(%{assigns: %{user: user}} = conn, %{"data" => settings} = _params) do
940 with new_info <- Map.put(user.info, "settings", settings),
941 change <- User.info_changeset(user, %{info: new_info}),
942 {:ok, _user} <- User.update_and_set_cache(change) do
948 |> json(%{error: inspect(e)})
952 def login(conn, _) do
954 |> render(MastodonView, "login.html", %{error: false})
957 defp get_or_make_app() do
958 with %App{} = app <- Repo.get_by(App, client_name: "Mastodon-Local") do
963 App.register_changeset(%App{}, %{
964 client_name: "Mastodon-Local",
966 scopes: "read,write,follow"
973 def login_post(conn, %{"authorization" => %{"name" => name, "password" => password}}) do
974 with %User{} = user <- User.get_by_nickname_or_email(name),
975 true <- Pbkdf2.checkpw(password, user.password_hash),
976 {:ok, app} <- get_or_make_app(),
977 {:ok, auth} <- Authorization.create_authorization(app, user),
978 {:ok, token} <- Token.exchange_token(app, auth) do
980 |> put_session(:oauth_token, token.token)
981 |> redirect(to: "/web/getting-started")
985 |> render(MastodonView, "login.html", %{error: "Wrong username or password"})
989 def logout(conn, _) do
995 def relationship_noop(%{assigns: %{user: user}} = conn, %{"id" => id}) do
996 Logger.debug("Unimplemented, returning unmodified relationship")
998 with %User{} = target <- Repo.get(User, id) do
999 render(conn, AccountView, "relationship.json", %{user: user, target: target})
1003 def empty_array(conn, _) do
1004 Logger.debug("Unimplemented, returning an empty array")
1008 def empty_object(conn, _) do
1009 Logger.debug("Unimplemented, returning an empty object")
1013 def render_notification(user, %{id: id, activity: activity, inserted_at: created_at} = _params) do
1014 actor = User.get_cached_by_ap_id(activity.data["actor"])
1017 NaiveDateTime.to_iso8601(created_at)
1018 |> String.replace(~r/(\.\d+)?$/, ".000Z", global: false)
1020 case activity.data["type"] do
1025 created_at: created_at,
1026 account: AccountView.render("account.json", %{user: actor}),
1027 status: StatusView.render("status.json", %{activity: activity, for: user})
1031 liked_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"])
1036 created_at: created_at,
1037 account: AccountView.render("account.json", %{user: actor}),
1038 status: StatusView.render("status.json", %{activity: liked_activity, for: user})
1042 announced_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"])
1047 created_at: created_at,
1048 account: AccountView.render("account.json", %{user: actor}),
1049 status: StatusView.render("status.json", %{activity: announced_activity, for: user})
1056 created_at: created_at,
1057 account: AccountView.render("account.json", %{user: actor})
1065 def errors(conn, _) do
1068 |> json("Something went wrong")