Merge branch 'feature/direct_conversation_id_web_push' into 'develop'
Add `direct_conversation_id` to web push payload See merge request pleroma/pleroma!2012
This commit is contained in:
commit
139b1feda1
|
@ -303,4 +303,17 @@ def restrict_deactivated_users(query) do
|
||||||
end
|
end
|
||||||
|
|
||||||
defdelegate search(user, query, options \\ []), to: Pleroma.Activity.Search
|
defdelegate search(user, query, options \\ []), to: Pleroma.Activity.Search
|
||||||
|
|
||||||
|
def direct_conversation_id(activity, for_user) do
|
||||||
|
alias Pleroma.Conversation.Participation
|
||||||
|
|
||||||
|
with %{data: %{"context" => context}} when is_binary(context) <- activity,
|
||||||
|
%Pleroma.Conversation{} = conversation <- Pleroma.Conversation.get_for_ap_id(context),
|
||||||
|
%Participation{id: participation_id} <-
|
||||||
|
Participation.for_user_and_conversation(for_user, conversation) do
|
||||||
|
participation_id
|
||||||
|
else
|
||||||
|
_ -> nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,8 +9,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
|
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.ActivityExpiration
|
alias Pleroma.ActivityExpiration
|
||||||
alias Pleroma.Conversation
|
|
||||||
alias Pleroma.Conversation.Participation
|
|
||||||
alias Pleroma.HTML
|
alias Pleroma.HTML
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
|
@ -245,12 +243,8 @@ def render("show.json", %{activity: %{data: %{"object" => _object}} = activity}
|
||||||
direct_conversation_id =
|
direct_conversation_id =
|
||||||
with {_, nil} <- {:direct_conversation_id, opts[:direct_conversation_id]},
|
with {_, nil} <- {:direct_conversation_id, opts[:direct_conversation_id]},
|
||||||
{_, true} <- {:include_id, opts[:with_direct_conversation_id]},
|
{_, true} <- {:include_id, opts[:with_direct_conversation_id]},
|
||||||
{_, %User{} = for_user} <- {:for_user, opts[:for]},
|
{_, %User{} = for_user} <- {:for_user, opts[:for]} do
|
||||||
%{data: %{"context" => context}} when is_binary(context) <- activity,
|
Activity.direct_conversation_id(activity, for_user)
|
||||||
%Conversation{} = conversation <- Conversation.get_for_ap_id(context),
|
|
||||||
%Participation{id: participation_id} <-
|
|
||||||
Participation.for_user_and_conversation(for_user, conversation) do
|
|
||||||
participation_id
|
|
||||||
else
|
else
|
||||||
{:direct_conversation_id, participation_id} when is_integer(participation_id) ->
|
{:direct_conversation_id, participation_id} when is_integer(participation_id) ->
|
||||||
participation_id
|
participation_id
|
||||||
|
|
|
@ -33,6 +33,8 @@ def perform(
|
||||||
gcm_api_key = Application.get_env(:web_push_encryption, :gcm_api_key)
|
gcm_api_key = Application.get_env(:web_push_encryption, :gcm_api_key)
|
||||||
avatar_url = User.avatar_url(actor)
|
avatar_url = User.avatar_url(actor)
|
||||||
object = Object.normalize(activity)
|
object = Object.normalize(activity)
|
||||||
|
user = User.get_cached_by_id(user_id)
|
||||||
|
direct_conversation_id = Activity.direct_conversation_id(activity, user)
|
||||||
|
|
||||||
for subscription <- fetch_subsriptions(user_id),
|
for subscription <- fetch_subsriptions(user_id),
|
||||||
get_in(subscription.data, ["alerts", type]) do
|
get_in(subscription.data, ["alerts", type]) do
|
||||||
|
@ -45,7 +47,8 @@ def perform(
|
||||||
icon: avatar_url,
|
icon: avatar_url,
|
||||||
preferred_locale: "en",
|
preferred_locale: "en",
|
||||||
pleroma: %{
|
pleroma: %{
|
||||||
activity_id: activity_id
|
activity_id: activity_id,
|
||||||
|
direct_conversation_id: direct_conversation_id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|> Jason.encode!()
|
|> Jason.encode!()
|
||||||
|
|
Loading…
Reference in a new issue