Flake Ids for Users and Activities
This commit is contained in:
parent
b624b7a150
commit
28d77e373c
17 changed files with 264 additions and 32 deletions
|
|
@ -900,15 +900,10 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||
|
||||
maybe_retire_websub(user.ap_id)
|
||||
|
||||
# Only do this for recent activties, don't go through the whole db.
|
||||
# Only look at the last 1000 activities.
|
||||
since = (Repo.aggregate(Activity, :max, :id) || 0) - 1_000
|
||||
|
||||
q =
|
||||
from(
|
||||
a in Activity,
|
||||
where: ^old_follower_address in a.recipients,
|
||||
where: a.id > ^since,
|
||||
update: [
|
||||
set: [
|
||||
recipients:
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do
|
|||
"partOf" => iri,
|
||||
"totalItems" => info.note_count,
|
||||
"orderedItems" => collection,
|
||||
"next" => "#{iri}?max_id=#{min_id - 1}"
|
||||
"next" => "#{iri}?max_id=#{min_id}"
|
||||
}
|
||||
|
||||
if max_qid == nil do
|
||||
|
|
@ -207,7 +207,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do
|
|||
"partOf" => iri,
|
||||
"totalItems" => -1,
|
||||
"orderedItems" => collection,
|
||||
"next" => "#{iri}?max_id=#{min_id - 1}"
|
||||
"next" => "#{iri}?max_id=#{min_id}"
|
||||
}
|
||||
|
||||
if max_qid == nil do
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ defmodule Pleroma.Web.OAuth.Authorization do
|
|||
field(:token, :string)
|
||||
field(:valid_until, :naive_datetime)
|
||||
field(:used, :boolean, default: false)
|
||||
belongs_to(:user, Pleroma.User)
|
||||
belongs_to(:user, Pleroma.User, type: Pleroma.FlakeId)
|
||||
belongs_to(:app, App)
|
||||
|
||||
timestamps()
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ defmodule Pleroma.Web.OAuth.Token do
|
|||
field(:token, :string)
|
||||
field(:refresh_token, :string)
|
||||
field(:valid_until, :naive_datetime)
|
||||
belongs_to(:user, Pleroma.User)
|
||||
belongs_to(:user, Pleroma.User, type: Pleroma.FlakeId)
|
||||
belongs_to(:app, App)
|
||||
|
||||
timestamps()
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ defmodule Pleroma.Web.Push.Subscription do
|
|||
alias Pleroma.Web.Push.Subscription
|
||||
|
||||
schema "push_subscriptions" do
|
||||
belongs_to(:user, User)
|
||||
belongs_to(:user, User, type: Pleroma.FlakeId)
|
||||
belongs_to(:token, Token)
|
||||
field(:endpoint, :string)
|
||||
field(:key_p256dh, :string)
|
||||
|
|
|
|||
|
|
@ -265,8 +265,6 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
|||
end
|
||||
|
||||
def fetch_conversation(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||
id = String.to_integer(id)
|
||||
|
||||
with context when is_binary(context) <- TwitterAPI.conversation_id_to_context(id),
|
||||
activities <-
|
||||
ActivityPub.fetch_activities_for_context(context, %{
|
||||
|
|
@ -340,38 +338,42 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
|||
end
|
||||
|
||||
def favorite(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||
with {_, {:ok, id}} <- {:param_cast, Ecto.Type.cast(:integer, id)},
|
||||
{:ok, activity} <- TwitterAPI.fav(user, id) do
|
||||
with {:ok, activity} <- TwitterAPI.fav(user, id) do
|
||||
conn
|
||||
|> put_view(ActivityView)
|
||||
|> render("activity.json", %{activity: activity, for: user})
|
||||
else
|
||||
_ -> json_reply(conn, 400, Jason.encode!(%{}))
|
||||
end
|
||||
end
|
||||
|
||||
def unfavorite(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||
with {_, {:ok, id}} <- {:param_cast, Ecto.Type.cast(:integer, id)},
|
||||
{:ok, activity} <- TwitterAPI.unfav(user, id) do
|
||||
with {:ok, activity} <- TwitterAPI.unfav(user, id) do
|
||||
conn
|
||||
|> put_view(ActivityView)
|
||||
|> render("activity.json", %{activity: activity, for: user})
|
||||
else
|
||||
_ -> json_reply(conn, 400, Jason.encode!(%{}))
|
||||
end
|
||||
end
|
||||
|
||||
def retweet(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||
with {_, {:ok, id}} <- {:param_cast, Ecto.Type.cast(:integer, id)},
|
||||
{:ok, activity} <- TwitterAPI.repeat(user, id) do
|
||||
with {:ok, activity} <- TwitterAPI.repeat(user, id) do
|
||||
conn
|
||||
|> put_view(ActivityView)
|
||||
|> render("activity.json", %{activity: activity, for: user})
|
||||
else
|
||||
_ -> json_reply(conn, 400, Jason.encode!(%{}))
|
||||
end
|
||||
end
|
||||
|
||||
def unretweet(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||
with {_, {:ok, id}} <- {:param_cast, Ecto.Type.cast(:integer, id)},
|
||||
{:ok, activity} <- TwitterAPI.unrepeat(user, id) do
|
||||
with {:ok, activity} <- TwitterAPI.unrepeat(user, id) do
|
||||
conn
|
||||
|> put_view(ActivityView)
|
||||
|> render("activity.json", %{activity: activity, for: user})
|
||||
else
|
||||
_ -> json_reply(conn, 400, Jason.encode!(%{}))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -556,7 +558,6 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
|||
|
||||
def approve_friend_request(conn, %{"user_id" => uid} = _params) do
|
||||
with followed <- conn.assigns[:user],
|
||||
uid when is_number(uid) <- String.to_integer(uid),
|
||||
%User{} = follower <- Repo.get(User, uid),
|
||||
{:ok, follower} <- User.maybe_follow(follower, followed),
|
||||
%Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed),
|
||||
|
|
@ -578,7 +579,6 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
|||
|
||||
def deny_friend_request(conn, %{"user_id" => uid} = _params) do
|
||||
with followed <- conn.assigns[:user],
|
||||
uid when is_number(uid) <- String.to_integer(uid),
|
||||
%User{} = follower <- Repo.get(User, uid),
|
||||
%Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed),
|
||||
{:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "reject"),
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ defmodule Pleroma.Web.Websub.WebsubClientSubscription do
|
|||
field(:state, :string)
|
||||
field(:subscribers, {:array, :string}, default: [])
|
||||
field(:hub, :string)
|
||||
belongs_to(:user, User)
|
||||
belongs_to(:user, User, type: Pleroma.FlakeId)
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue