diff options
author | Roger Braun <roger@rogerbraun.net> | 2017-07-02 15:01:59 +0200 |
---|---|---|
committer | Roger Braun <roger@rogerbraun.net> | 2017-07-02 15:01:59 +0200 |
commit | e343c0c9c42968316c93ebb52a570ccd5778acb0 (patch) | |
tree | c8e2f4213a46913f0ca3cd54bd25056bd9506d67 /lib | |
parent | 5d8352a4296dc06fd548f3e53db3f1f38040cfd0 (diff) | |
download | pleroma-e343c0c9c42968316c93ebb52a570ccd5778acb0.tar.gz |
Add way to update most recent notification id.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/user.ex | 6 | ||||
-rw-r--r-- | lib/pleroma/web/router.ex | 2 | ||||
-rw-r--r-- | lib/pleroma/web/twitter_api/twitter_api_controller.ex | 16 |
3 files changed, 23 insertions, 1 deletions
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 23e650ce5..a30c8daed 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -46,6 +46,12 @@ defmodule Pleroma.User do |> validate_required([:following]) end + def info_changeset(struct, params \\ %{}) do + struct + |> cast(params, [:info]) + |> validate_required([:info]) + end + def user_info(%User{} = user) do note_count_query = from a in Object, where: fragment("? @> ?", a.data, ^%{actor: user.ap_id, type: "Note"}), diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 5a0f3b63f..d92ee29ba 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -49,6 +49,8 @@ defmodule Pleroma.Web.Router do get "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials post "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials + post "/account/most_recent_notification", TwitterAPI.Controller, :update_most_recent_notification + get "/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline get "/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline get "/statuses/mentions", TwitterAPI.Controller, :mentions_timeline diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 407a7931a..2b29b6ccf 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -2,7 +2,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do use Pleroma.Web, :controller alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView} alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter - alias Pleroma.{Repo, Activity} + alias Pleroma.{Repo, Activity, User} alias Pleroma.Web.ActivityPub.ActivityPub alias Ecto.Changeset @@ -196,6 +196,20 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end + def update_most_recent_notification(%{assigns: %{user: user}} = conn, %{"id" => id}) do + with id when is_number(id) <- String.to_integer(id), + info <- user.info, + mrn <- max(id, user.info["most_recent_notification"] || 0), + updated_info <- Map.put(info, "most_recent_notification", mrn), + changeset <- User.info_changeset(user, %{info: updated_info}), + {:ok, user} <- Repo.update(changeset) do + conn + |> json_reply(200, Poison.encode!(mrn)) + else + _e -> bad_request_reply(conn, "Can't update.") + end + end + defp bad_request_reply(conn, error_message) do json = error_json(conn, error_message) json_reply(conn, 400, json) |