Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into develop
This commit is contained in:
commit
193be32f45
6 changed files with 194 additions and 3 deletions
|
|
@ -212,6 +212,7 @@ defmodule Pleroma.Web.Router do
|
|||
get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
|
||||
get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
|
||||
get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
|
||||
get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
|
||||
|
||||
post("/statuses/update", TwitterAPI.Controller, :status_update)
|
||||
post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
defmodule Pleroma.Web.TwitterAPI.Controller do
|
||||
use Pleroma.Web, :controller
|
||||
alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView}
|
||||
alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView, NotificationView}
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.{Repo, Activity, User}
|
||||
alias Pleroma.{Repo, Activity, User, Notification}
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Ecto.Changeset
|
||||
|
||||
|
|
@ -119,6 +119,13 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
|||
|> render(ActivityView, "index.json", %{activities: activities, for: user})
|
||||
end
|
||||
|
||||
def notifications(%{assigns: %{user: user}} = conn, params) do
|
||||
notifications = Notification.for_user(user, params)
|
||||
|
||||
conn
|
||||
|> render(NotificationView, "notification.json", %{notifications: notifications, for: user})
|
||||
end
|
||||
|
||||
def follow(%{assigns: %{user: user}} = conn, params) do
|
||||
case TwitterAPI.follow(user, params) do
|
||||
{:ok, user, followed, _activity} ->
|
||||
|
|
|
|||
47
lib/pleroma/web/twitter_api/views/notification_view.ex
Normal file
47
lib/pleroma/web/twitter_api/views/notification_view.ex
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
defmodule Pleroma.Web.TwitterAPI.NotificationView do
|
||||
use Pleroma.Web, :view
|
||||
alias Pleroma.{Notification, User}
|
||||
alias Pleroma.Web.CommonAPI.Utils
|
||||
alias Pleroma.Web.MediaProxy
|
||||
alias Pleroma.Web.TwitterAPI.UserView
|
||||
alias Pleroma.Web.TwitterAPI.ActivityView
|
||||
|
||||
defp get_user(ap_id, opts) do
|
||||
cond do
|
||||
user = opts[:users][ap_id] ->
|
||||
user
|
||||
|
||||
String.ends_with?(ap_id, "/followers") ->
|
||||
nil
|
||||
|
||||
ap_id == "https://www.w3.org/ns/activitystreams#Public" ->
|
||||
nil
|
||||
|
||||
true ->
|
||||
User.get_cached_by_ap_id(ap_id)
|
||||
end
|
||||
end
|
||||
|
||||
def render("notification.json", %{notifications: notifications, for: user}) do
|
||||
render_many(notifications, Pleroma.Web.TwitterAPI.NotificationView, "notification.json", for: user)
|
||||
end
|
||||
|
||||
def render("notification.json", %{notification: %Notification{id: id, seen: seen, activity: activity, inserted_at: created_at}, for: user} = opts) do
|
||||
ntype = case activity.data["type"] do
|
||||
"Create" -> "mention"
|
||||
"Like" -> "like"
|
||||
"Announce" -> "repeat"
|
||||
"Follow" -> "follow"
|
||||
end
|
||||
from = get_user(activity.data["actor"], opts)
|
||||
|
||||
%{
|
||||
"id" => id,
|
||||
"ntype" => ntype,
|
||||
"notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
|
||||
"from_profile" => UserView.render("show.json", %{user: from, for: user}),
|
||||
"is_seen" => (if seen, do: 1, else: 0),
|
||||
"created_at" => created_at |> Utils.format_naive_asctime()
|
||||
}
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue