This repository has been archived by the owner on Jun 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
106 changed files
with
3,174 additions
and
548 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use Mix.Config | ||
|
||
config :helix, Helix.Notification.Repo, | ||
priv: "priv/repo/notification", | ||
pool_size: 3, | ||
adapter: Ecto.Adapters.Postgres, | ||
username: System.get_env("HELIX_DB_USER") || "postgres", | ||
password: System.get_env("HELIX_DB_PASS") || "postgres", | ||
hostname: System.get_env("HELIX_DB_HOST") || "localhost", | ||
types: HELL.PostgrexTypes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use Mix.Config | ||
|
||
prefix = System.get_env("HELIX_DB_PREFIX") || "helix" | ||
|
||
config :helix, Helix.Notification.Repo, | ||
database: prefix <> "_dev_notification" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use Mix.Config | ||
|
||
prefix = "${HELIX_DB_PREFIX}" | ||
|
||
config :helix, Helix.Notification.Repo, | ||
pool_size: "${HELIX_DB_POOL_SIZE}", | ||
username: "${HELIX_DB_USER}", | ||
password: "${HELIX_DB_PASS}", | ||
hostname: "${HELIX_DB_HOST}", | ||
database: prefix <> "_prod_notification" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use Mix.Config | ||
|
||
prefix = System.get_env("HELIX_DB_PREFIX") || "helix" | ||
|
||
config :helix, Helix.Notification.Repo, | ||
pool: Ecto.Adapters.SQL.Sandbox, | ||
database: prefix <> "_test_notification", | ||
ownership_timeout: 90_000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
defmodule Helix.Core.Validator.Model do | ||
@moduledoc """ | ||
This is a helper module to create a syntactic sugar for Helix models that | ||
implement verifications for the `Helix.Core.Validator`. | ||
""" | ||
|
||
@doc """ | ||
Pure syntactic sugar. | ||
""" | ||
defmacro validator(do: block) do | ||
parent_module = __CALLER__.module | ||
module_name = Module.concat(parent_module, "Validator") | ||
|
||
quote do | ||
|
||
defmodule unquote(module_name) do | ||
alias unquote(parent_module) | ||
|
||
unquote(block) | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,39 @@ | ||
defmodule Helix.Event.Notificable.Flow do | ||
|
||
import HELL.Macros | ||
alias Helix.Notification.Model.Code, as: NotificationCode | ||
|
||
alias Phoenix.Socket | ||
alias HELL.HETypes | ||
alias Helix.Event | ||
alias Helix.Event.Notificable | ||
|
||
@type event_id :: HETypes.uuid | ||
|
||
@doc """ | ||
Top-level macro for an event that wants to implement the Notificable protocol. | ||
""" | ||
defmacro notify(do: block) do | ||
defmacro notification(do: block) do | ||
quote do | ||
|
||
defimpl Helix.Event.Notificable do | ||
@moduledoc false | ||
|
||
@event nil | ||
@class nil | ||
@code nil | ||
|
||
unquote(block) | ||
|
||
@event || raise "You must set an event name with @event" | ||
@class || raise "You must set a notification class with @class" | ||
@code || raise "You must set a notification code with @code" | ||
|
||
NotificationCode.code_exists?(@class, @code) | ||
|| raise "Notification not found: #{inspect {@class, @code}}" | ||
|
||
@doc """ | ||
Returns the event name as a string | ||
Returns notification data (tuple with class and code) | ||
""" | ||
def get_event_name(_event) do | ||
to_string(@event) | ||
def get_notification_data(_event) do | ||
{@class, @code} | ||
end | ||
end | ||
|
||
end | ||
end | ||
|
||
@spec generate_event(struct, Socket.t) :: | ||
{:ok, %{data: term, event: String.t, meta: Event.Meta.rendered}} | ||
| :noreply | ||
@doc """ | ||
Attempts to generate the payload for that event. If the implementation of the | ||
Notificable protocol returns a valid payload (i.e. it wants to notify that | ||
specific user), then we'll set up the event metadata and return it ready to | ||
be sent to the player. | ||
""" | ||
def generate_event(event, socket) do | ||
case Notificable.generate_payload(event, socket) do | ||
{:ok, data} -> | ||
payload = | ||
%{ | ||
data: data, | ||
event: Notificable.get_event_name(event), | ||
meta: Event.Meta.render(event) | ||
} | ||
# Fallbacks | ||
|
||
{:ok, payload} | ||
@doc false | ||
def extra_params(_) do | ||
%{} | ||
end | ||
end | ||
|
||
noreply -> | ||
noreply | ||
end | ||
end | ||
|
||
@spec add_event_identifier(struct) :: | ||
struct | ||
@doc """ | ||
Adds the event unique identifier. | ||
Keep in mind that this unique identifier is for the *event*, i.e. the fact | ||
that something happened. If this event gets broadcasted to multiple players, | ||
each one of them will share the same event identifier. | ||
""" | ||
def add_event_identifier(event), | ||
do: Event.set_event_id(event, generate_event_uuid()) | ||
|
||
@spec generate_event_uuid :: | ||
event_id | ||
docp """ | ||
Returns a valid UUIDv4 used as event identifier. | ||
""" | ||
defp generate_event_uuid, | ||
do: Ecto.UUID.generate() | ||
end |
Oops, something went wrong.