Notification for participation request/accepted participation
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
4d9ddd4f4b
commit
b3700afdd3
9 changed files with 126 additions and 11 deletions
|
@ -74,6 +74,8 @@ def unread_notifications_count(%User{id: user_id}) do
|
||||||
reblog
|
reblog
|
||||||
poll
|
poll
|
||||||
status
|
status
|
||||||
|
pleroma:participation_accepted
|
||||||
|
pleroma:participation_request
|
||||||
}
|
}
|
||||||
|
|
||||||
def changeset(%Notification{} = notification, attrs) do
|
def changeset(%Notification{} = notification, attrs) do
|
||||||
|
@ -388,7 +390,7 @@ def create_notifications(%Activity{data: %{"to" => _, "type" => "Create"}} = act
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_notifications(%Activity{data: %{"type" => type}} = activity, options)
|
def create_notifications(%Activity{data: %{"type" => type}} = activity, options)
|
||||||
when type in ["Follow", "Like", "Announce", "Move", "EmojiReact", "Flag"] do
|
when type in ["Follow", "Like", "Announce", "Move", "EmojiReact", "Flag", "Accept", "Join"] do
|
||||||
do_create_notifications(activity, options)
|
do_create_notifications(activity, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -449,6 +451,12 @@ defp type_from_activity(%{data: %{"type" => type}} = activity) do
|
||||||
activity
|
activity
|
||||||
|> type_from_activity_object()
|
|> type_from_activity_object()
|
||||||
|
|
||||||
|
"Accept" ->
|
||||||
|
"pleroma:participation_accepted"
|
||||||
|
|
||||||
|
"Join" ->
|
||||||
|
"pleroma:participation_request"
|
||||||
|
|
||||||
t ->
|
t ->
|
||||||
raise "No notification type for activity type #{t}"
|
raise "No notification type for activity type #{t}"
|
||||||
end
|
end
|
||||||
|
@ -523,7 +531,17 @@ def create_poll_notifications(%Activity{} = activity) do
|
||||||
def get_notified_from_activity(activity, local_only \\ true)
|
def get_notified_from_activity(activity, local_only \\ true)
|
||||||
|
|
||||||
def get_notified_from_activity(%Activity{data: %{"type" => type}} = activity, local_only)
|
def get_notified_from_activity(%Activity{data: %{"type" => type}} = activity, local_only)
|
||||||
when type in ["Create", "Like", "Announce", "Follow", "Move", "EmojiReact", "Flag"] do
|
when type in [
|
||||||
|
"Create",
|
||||||
|
"Like",
|
||||||
|
"Announce",
|
||||||
|
"Follow",
|
||||||
|
"Move",
|
||||||
|
"EmojiReact",
|
||||||
|
"Flag",
|
||||||
|
"Accept",
|
||||||
|
"Join"
|
||||||
|
] do
|
||||||
potential_receiver_ap_ids = get_potential_receiver_ap_ids(activity)
|
potential_receiver_ap_ids = get_potential_receiver_ap_ids(activity)
|
||||||
|
|
||||||
potential_receivers =
|
potential_receivers =
|
||||||
|
@ -576,6 +594,35 @@ def get_potential_receiver_ap_ids(%{data: %{"type" => type, "object" => object_i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_potential_receiver_ap_ids(%{data: %{"type" => "Accept", "object" => join_id}}) do
|
||||||
|
case Activity.get_by_ap_id_with_object(join_id) do
|
||||||
|
%Activity{
|
||||||
|
data: %{"type" => "Join"},
|
||||||
|
object: %Object{data: %{"type" => "Event", "joinMode" => "free"}}
|
||||||
|
} ->
|
||||||
|
[]
|
||||||
|
|
||||||
|
%Activity{data: %{"type" => "Join", "actor" => actor_id}} ->
|
||||||
|
[actor_id]
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_potential_receiver_ap_ids(%{data: %{"type" => "Join", "object" => object_id}}) do
|
||||||
|
case Object.get_by_ap_id(object_id) do
|
||||||
|
%Object{data: %{"type" => "Event", "joinMode" => "free"}} ->
|
||||||
|
[]
|
||||||
|
|
||||||
|
%Object{data: %{"type" => "Event", "actor" => actor_id}} ->
|
||||||
|
[actor_id]
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def get_potential_receiver_ap_ids(%{data: %{"type" => "Follow", "object" => object_id}}) do
|
def get_potential_receiver_ap_ids(%{data: %{"type" => "Follow", "object" => object_id}}) do
|
||||||
[object_id]
|
[object_id]
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,7 +25,6 @@ defp config, do: Config.get([:pipeline, :config], Config)
|
||||||
@spec common_pipeline(map(), keyword()) ::
|
@spec common_pipeline(map(), keyword()) ::
|
||||||
{:ok, Activity.t() | Object.t(), keyword()} | {:error, any()}
|
{:ok, Activity.t() | Object.t(), keyword()} | {:error, any()}
|
||||||
def common_pipeline(object, meta) do
|
def common_pipeline(object, meta) do
|
||||||
|
|
||||||
case Repo.transaction(fn -> do_common_pipeline(object, meta) end, Utils.query_timeout()) do
|
case Repo.transaction(fn -> do_common_pipeline(object, meta) end, Utils.query_timeout()) do
|
||||||
{:ok, {:ok, activity, meta}} ->
|
{:ok, {:ok, activity, meta}} ->
|
||||||
side_effects().handle_after_transaction(meta)
|
side_effects().handle_after_transaction(meta)
|
||||||
|
|
|
@ -49,7 +49,9 @@ def handle(
|
||||||
Activity.get_by_ap_id(activity_id) do
|
Activity.get_by_ap_id(activity_id) do
|
||||||
handle_accepted(activity, actor)
|
handle_accepted(activity, actor)
|
||||||
|
|
||||||
Notification.create_notifications(object)
|
if activity.data["type"] === "Join" do
|
||||||
|
Notification.create_notifications(object)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
{:ok, object, meta}
|
{:ok, object, meta}
|
||||||
|
@ -396,6 +398,8 @@ def handle(%{data: %{"type" => "Join"}} = object, meta) do
|
||||||
{:ok, _activity, _} = Pipeline.common_pipeline(accept_data, local: true)
|
{:ok, _activity, _} = Pipeline.common_pipeline(accept_data, local: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Notification.create_notifications(object)
|
||||||
|
|
||||||
{:ok, object, meta}
|
{:ok, object, meta}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -202,12 +202,15 @@ defp notification_type do
|
||||||
"move",
|
"move",
|
||||||
"follow_request",
|
"follow_request",
|
||||||
"poll",
|
"poll",
|
||||||
"status"
|
"status",
|
||||||
|
"pleroma:participation_accepted",
|
||||||
|
"pleroma:participation_request"
|
||||||
],
|
],
|
||||||
description: """
|
description: """
|
||||||
The type of event that resulted in the notification.
|
The type of event that resulted in the notification.
|
||||||
|
|
||||||
- `follow` - Someone followed you
|
- `follow` - Someone followed you
|
||||||
|
- `follow_request` - Someone wants to follow you
|
||||||
- `mention` - Someone mentioned you in their status
|
- `mention` - Someone mentioned you in their status
|
||||||
- `reblog` - Someone boosted one of your statuses
|
- `reblog` - Someone boosted one of your statuses
|
||||||
- `favourite` - Someone favourited one of your statuses
|
- `favourite` - Someone favourited one of your statuses
|
||||||
|
@ -217,6 +220,8 @@ defp notification_type do
|
||||||
- `pleroma:chat_mention` - Someone mentioned you in a chat message
|
- `pleroma:chat_mention` - Someone mentioned you in a chat message
|
||||||
- `pleroma:report` - Someone was reported
|
- `pleroma:report` - Someone was reported
|
||||||
- `status` - Someone you are subscribed to created a status
|
- `status` - Someone you are subscribed to created a status
|
||||||
|
- `pleroma:participation_request - Someone wants to participate in your event
|
||||||
|
- `pleroma:participation_accepted - Your event participation request was accepted
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -81,7 +81,7 @@ def perform(:incoming_ap_doc, params) do
|
||||||
nil <- Activity.normalize(params["id"]),
|
nil <- Activity.normalize(params["id"]),
|
||||||
{_, :ok} <-
|
{_, :ok} <-
|
||||||
{:correct_origin?, Containment.contain_origin_from_id(actor, params)},
|
{:correct_origin?, Containment.contain_origin_from_id(actor, params)},
|
||||||
_ <- "handling incoming",
|
_ <- "handling incoming",
|
||||||
{:ok, activity} <- Transmogrifier.handle_incoming(params) do
|
{:ok, activity} <- Transmogrifier.handle_incoming(params) do
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
else
|
else
|
||||||
|
|
|
@ -52,6 +52,8 @@ def index(conn, %{account_id: account_id} = params) do
|
||||||
pleroma:emoji_reaction
|
pleroma:emoji_reaction
|
||||||
poll
|
poll
|
||||||
status
|
status
|
||||||
|
pleroma:participation_request
|
||||||
|
pleroma:participation_accepted
|
||||||
}
|
}
|
||||||
def index(%{assigns: %{user: user}} = conn, params) do
|
def index(%{assigns: %{user: user}} = conn, params) do
|
||||||
params =
|
params =
|
||||||
|
|
|
@ -129,6 +129,12 @@ def render(
|
||||||
"pleroma:report" ->
|
"pleroma:report" ->
|
||||||
put_report(response, activity)
|
put_report(response, activity)
|
||||||
|
|
||||||
|
"pleroma:participation_accepted" ->
|
||||||
|
put_status(response, parent_activity_fn.(), reading_user, status_render_opts)
|
||||||
|
|
||||||
|
"pleroma:participation_request" ->
|
||||||
|
put_participation_request(response, activity)
|
||||||
|
|
||||||
type when type in ["follow", "follow_request"] ->
|
type when type in ["follow", "follow_request"] ->
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
@ -169,4 +175,8 @@ defp put_target(response, activity, reading_user, opts) do
|
||||||
|
|
||||||
Map.put(response, :target, target_render)
|
Map.put(response, :target, target_render)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp put_participation_request(response, activity) do
|
||||||
|
Map.put(response, :participation_message, activity.data["participationMessage"])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -367,8 +367,6 @@ def render("show.json", %{activity: %{data: %{"object" => _object}} = activity}
|
||||||
|
|
||||||
{pinned?, pinned_at} = pin_data(object, user)
|
{pinned?, pinned_at} = pin_data(object, user)
|
||||||
|
|
||||||
IO.inspect(opts[:for])
|
|
||||||
|
|
||||||
%{
|
%{
|
||||||
id: to_string(activity.id),
|
id: to_string(activity.id),
|
||||||
uri: object.data["id"],
|
uri: object.data["id"],
|
||||||
|
@ -598,7 +596,6 @@ def build_emojis(emojis) do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp build_event(%{"type" => "Event"} = data, for_user) do
|
defp build_event(%{"type" => "Event"} = data, for_user) do
|
||||||
IO.inspect(for_user)
|
|
||||||
%{
|
%{
|
||||||
name: data["name"],
|
name: data["name"],
|
||||||
start_time: data["startTime"],
|
start_time: data["startTime"],
|
||||||
|
@ -619,8 +616,6 @@ defp build_event_location(%{"type" => "Place", "name" => name}) do
|
||||||
defp build_event_location(_), do: nil
|
defp build_event_location(_), do: nil
|
||||||
|
|
||||||
defp build_event_join_state(%{ap_id: actor}, id) do
|
defp build_event_join_state(%{ap_id: actor}, id) do
|
||||||
IO.inspect(actor)
|
|
||||||
IO.inspect(id)
|
|
||||||
latest_join = Pleroma.Web.ActivityPub.Utils.get_existing_join(actor, id)
|
latest_join = Pleroma.Web.ActivityPub.Utils.get_existing_join(actor, id)
|
||||||
|
|
||||||
if latest_join do
|
if latest_join do
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
defmodule Pleroma.Repo.Migrations.AddPleromaParticipationAcceptedToNotificationsEnum do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
@disable_ddl_transaction true
|
||||||
|
|
||||||
|
def up do
|
||||||
|
"""
|
||||||
|
alter type notification_type add value 'pleroma:participation_accepted'
|
||||||
|
alter type notification_type add value 'pleroma:participation_request'
|
||||||
|
"""
|
||||||
|
|> execute()
|
||||||
|
end
|
||||||
|
|
||||||
|
def down do
|
||||||
|
alter table(:notifications) do
|
||||||
|
modify(:type, :string)
|
||||||
|
end
|
||||||
|
|
||||||
|
"""
|
||||||
|
delete from notifications where type = 'pleroma:participation_accepted'
|
||||||
|
delete from notifications where type = 'pleroma:participation_request'
|
||||||
|
"""
|
||||||
|
|> execute()
|
||||||
|
|
||||||
|
"""
|
||||||
|
drop type if exists notification_type
|
||||||
|
"""
|
||||||
|
|> execute()
|
||||||
|
|
||||||
|
"""
|
||||||
|
create type notification_type as enum (
|
||||||
|
'follow',
|
||||||
|
'follow_request',
|
||||||
|
'mention',
|
||||||
|
'move',
|
||||||
|
'pleroma:emoji_reaction',
|
||||||
|
'pleroma:chat_mention',
|
||||||
|
'reblog',
|
||||||
|
'favourite',
|
||||||
|
'pleroma:report',
|
||||||
|
'poll',
|
||||||
|
'status'
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
|> execute()
|
||||||
|
|
||||||
|
"""
|
||||||
|
alter table notifications
|
||||||
|
alter column type type notification_type using (type::notification_type)
|
||||||
|
"""
|
||||||
|
|> execute()
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue