8000 Use actor helper for RSVP notifications by mwoods79 · Pull Request #144 · huddlz-hq/huddlz · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule Huddlz.Communities.Huddl.Changes.NotifyRsvpCancelled do

defp notify(cs, huddl) do
with true <- cs.context[:rsvp_cancelled] == true,
%{id: _} = actor <- cs.context[:private][:actor] do
%{id: _} = actor <- RecipientHelpers.actor(cs) do
deliver(huddl, actor)
{:ok, huddl}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule Huddlz.Communities.Huddl.Changes.NotifyRsvpReceived do

defp notify(cs, huddl) do
with true <- cs.context[:rsvp_created] == true,
%{id: _} = actor <- cs.context[:private][:actor] do
%{id: _} = actor <- RecipientHelpers.actor(cs) do
deliver(huddl, actor)
{:ok, huddl}
else
Expand Down
11 changes: 10 additions & 1 deletion lib/huddlz/communities/huddl/changes/recipient_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,21 @@ defmodule Huddlz.Communities.Huddl.Changes.RecipientHelpers do
"""
@spec actor_id(Ash.Changeset.t()) :: Ecto.UUID.t() | nil
def actor_id(changeset) do
case changeset.context[:private][:actor] do
case actor(changeset) do
%{id: id} -> id
_ -> nil
end
end

@doc """
Pull the actor out of an Ash.Changeset's private context. Returns
`nil` when no actor is present (e.g. system-driven actions).
"""
@spec actor(Ash.Changeset.t()) :: struct() | nil
def actor(changeset) do
changeset.context[:private][:actor]
end

@doc """
Fan a notification trigger out to a list of user_ids, fetching users
with `authorize?: false` and skipping any that no longer exist
Expand Down
Loading
0