refactor live handlers

This commit is contained in:
Mayel 2021-06-06 13:41:45 +02:00
parent 96235877a7
commit e9dfde8a71
9 changed files with 25 additions and 154 deletions

View file

@ -13,6 +13,9 @@ services:
env_file:
- config/prod/public.env
- config/prod/secrets.env
environment:
- POSTGRES_HOST=db
- SEARCH_MEILI_INSTANCE=http://search:7700
depends_on:
- db
volumes:

View file

@ -15,6 +15,7 @@ services:
- config/dev/secrets.env
environment:
- POSTGRES_HOST=db
- SEARCH_MEILI_INSTANCE=http://search:7700
depends_on:
- db
# - condition: service_healthy

View file

@ -8,7 +8,7 @@ SERVER_PORT=4000
# port your visitors will access (typically 80 or 443, will be different than SERVER_PORT only if using a reverse proxy)
PUBLIC_PORT=4000
# hostname and port of meili search index
SEARCH_MEILI_INSTANCE=http://search:7700
SEARCH_MEILI_INSTANCE=http://localhost:7700
# require an email address to be invited before being able to sign up
INVITE_ONLY=true
# a name and tagline for your instance

View file

@ -8,7 +8,7 @@ SERVER_PORT=4000
# port your visitors will access (typically 80 or 443, will be different than SERVER_PORT only if using a reverse proxy)
PUBLIC_PORT=4000
# hostname and port of meili search index
SEARCH_MEILI_INSTANCE=http://search:7700
SEARCH_MEILI_INSTANCE=http://localhost:7700
# require an email address to be invited before being able to sign up
INVITE_ONLY=true
# a name and tagline for your instance

View file

@ -8,7 +8,7 @@ SERVER_PORT=4000
# port your visitors will access (typically 80 or 443, will be different than SERVER_PORT only if using a reverse proxy)
PUBLIC_PORT=4000
# hostname and port of meili search index
SEARCH_MEILI_INSTANCE=http://search:7700
SEARCH_MEILI_INSTANCE=http://localhost:7700
# require an email address to be invited before being able to sign up
INVITE_ONLY=true
# a name and tagline for your instance

View file

@ -25,8 +25,8 @@ defmodule Bonfire.Web.HomeLive do
end
defdelegate handle_params(params, attrs, socket), to: Bonfire.Web.LiveHandler
def handle_event(action, attrs, socket), do: Bonfire.Web.LiveHandler.handle_event(action, attrs, socket, __MODULE__)
def handle_info(info, socket), do: Bonfire.Web.LiveHandler.handle_info(info, socket, __MODULE__)
defdelegate handle_params(params, attrs, socket), to: Bonfire.Common.LiveHandlers
def handle_event(action, attrs, socket), do: Bonfire.Common.LiveHandlers.handle_event(action, attrs, socket, __MODULE__)
def handle_info(info, socket), do: Bonfire.Common.LiveHandlers.handle_info(info, socket, __MODULE__)
end

View file

@ -1,133 +0,0 @@
defmodule Bonfire.Web.LiveHandler do
use Bonfire.Web, :live_handler
require Logger
# start handler pattern matching
alias Bonfire.Me.{Profiles, Circles}
alias Bonfire.Social.{Flags, Boosts, Likes, Posts, Feeds, Follows}
# TODO: make this whole thing config-driven
@profile_events ["profile_save"]
@circle_events ["circle_save"]
@boundary_events ["boundary_select"]
@like_events ["like"]
@boost_events ["boost", "boost_undo"]
@flag_events ["flag", "flag_undo"]
@post_events ["post", "post_reply", "post_load_replies"]
@post_infos [:post_new_reply]
@feed_events ["feed_load_more"]
@feed_infos [:feed_new_activity]
@follow_events ["follow", "unfollow"]
# Profiles
defp do_handle_event(event, attrs, socket) when event in @profile_events or binary_part(event, 0, 7) == "profile", do: Profiles.LiveHandler.handle_event(event, attrs, socket)
# Circles
defp do_handle_event(event, attrs, socket) when event in @circle_events or binary_part(event, 0, 6) == "circle", do: Circles.LiveHandler.handle_event(event, attrs, socket)
# Boundaries
defp do_handle_event(event, attrs, socket) when event in @boundary_events or binary_part(event, 0, 8) == "boundary", do: Bonfire.Me.Web.LiveHandlers.Boundaries.LiveHandler.handle_event(event, attrs, socket)
# Likes
defp do_handle_event(event, attrs, socket) when event in @like_events or binary_part(event, 0, 4) == "like", do: Likes.LiveHandler.handle_event(event, attrs, socket)
# Boosts
defp do_handle_event(event, attrs, socket) when event in @boost_events or binary_part(event, 0, 5) == "boost", do: Boosts.LiveHandler.handle_event(event, attrs, socket)
# Flags
defp do_handle_event(event, attrs, socket) when event in @flag_events or binary_part(event, 0, 4) == "flag", do: Flags.LiveHandler.handle_event(event, attrs, socket)
# Posts
defp do_handle_params(%{"post" => params}, uri, socket), do: Posts.LiveHandler.handle_params(params, uri, socket)
defp do_handle_event(event, attrs, socket) when event in @post_events or binary_part(event, 0, 4) == "post", do: Posts.LiveHandler.handle_event(event, attrs, socket)
defp do_handle_info({info, data}, socket) when info in @post_infos, do: Posts.LiveHandler.handle_info({info, data}, socket)
defp do_handle_info({info, id, data}, socket) when info in @post_infos, do: Posts.LiveHandler.handle_info({info, id, data}, socket)
# Feeds
defp do_handle_params(%{"feed" => params}, uri, socket), do: Feeds.LiveHandler.handle_params(params, uri, socket)
defp do_handle_event(event, attrs, socket) when event in @feed_events or binary_part(event, 0, 4) == "feed", do: Feeds.LiveHandler.handle_event(event, attrs, socket)
defp do_handle_info({info, data}, socket) when info in @feed_infos, do: Feeds.LiveHandler.handle_info({info, data}, socket)
# Follows
defp do_handle_event(event, attrs, socket) when event in @follow_events or binary_part(event, 0, 6) == "follow", do: Follows.LiveHandler.handle_event(event, attrs, socket)
# Search
# defp do_handle_event(event, attrs, socket) when binary_part(event, 0, 6) == "search", do: Bonfire.Search.LiveHandler.LiveHandler.handle_event(event, attrs, socket)
# ValueFlows
# defp do_handle_event(event, attrs, socket) when binary_part(event, 0, 10) == "valueflows", do: ValueFlows.Web.LiveHandler.LiveHandler.handle_event(event, attrs, socket)
defp do_handle_event(event, attrs, socket) do
# IO.inspect(handle_event: event)
[mod, action] = String.split(event, ":", parts: 2)
# IO.inspect(mod)
# IO.inspect(action)
case Utils.maybe_str_to_module(mod<>".LiveHandler") || Utils.maybe_str_to_module(mod) do
module when is_atom(module) ->
# IO.inspect(module)
if Utils.module_enabled?(module), do: apply(module, :handle_event, [action, attrs, socket]),
else: empty(socket)
_ -> empty(socket)
end
end
# end of handler pattern matching - fallback with empty replies
defp do_handle_params(_, _, socket), do: empty(socket)
defp do_handle_event(_, _, socket), do: empty(socket)
defp do_handle_info(_, socket), do: empty(socket)
defp empty(socket), do: {:noreply, socket}
def handle_params(params, uri, socket, _source_module \\ nil) do
undead(socket, fn ->
## IO.inspect(params: params)
do_handle_params(params, uri, socket |> assign_global(current_url: URI.parse(uri).path))
end)
end
def handle_event(action, attrs, socket, source_module \\ nil) do
undead(socket, fn ->
Logger.info("handle_event in #{inspect source_module}: #{action}...")
do_handle_event(action, attrs, socket)
end)
end
def handle_info(blob, socket, source_module \\ nil)
# global handler to set a view's assigns from a component
def handle_info({:assign, {assign, value}}, socket, _) do
undead(socket, fn ->
IO.inspect(assigns_to_set: assign)
{:noreply,
socket
|> Utils.assign_global(assign, value)
# |> Phoenix.LiveView.assign(:global_assigns, [assign] ++ Map.get(socket.assigns, :global_assigns, []))
# |> IO.inspect(limit: :infinity)
}
end)
end
def handle_info({info, _data} = blob, socket, source_module) when is_atom(source_module) do
# IO.inspect(socket)
Logger.info("handle_info in #{source_module}: #{info}...")
undead(socket, fn ->
do_handle_info(blob, socket)
end)
end
def handle_info(info, socket, _) do
Logger.info("handle_info...")
undead(socket, fn ->
do_handle_info(info, socket)
end)
end
end

View file

@ -3,7 +3,7 @@ defmodule Bonfire.MixProject do
use Mix.Project
@config [
version: "0.1.0-alpha.133", # note that the flavour will automatically be added where the dash appears
version: "0.1.0-alpha.134", # note that the flavour will automatically be added where the dash appears
elixir: "~> 1.11",
default_flavour: "classic",
test_deps_prefixes: ["bonfire_", "pointers"],

View file

@ -7,11 +7,11 @@
"argon2_elixir": {:hex, :argon2_elixir, "2.3.0", "e251bdafd69308e8c1263e111600e6d68bd44f23d2cccbe43fcb1a417a76bc8e", [:make, :mix], [{:comeonin, "~> 5.3", [hex: :comeonin, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "28ccb63bff213aecec1f7f3dde9648418b031f822499973281d8f494b9d5a3b3"},
"bamboo": {:hex, :bamboo, "1.7.1", "7f0946e8c9081ce10d347cdba33c247c7c1c4f7dddc194ab0633603ef879bbdf", [:mix], [{:hackney, ">= 1.15.2", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.4", [hex: :mime, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.1", [hex: :phoenix, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "5fb34c3ab638fc409deec47c1e91f9d78ad95bf22ccb153588b434e1ff1aa730"},
"bamboo_smtp": {:hex, :bamboo_smtp, "3.0.0", "b7f0c371af96a1cb7131908918b02abb228f9db234910bf10cf4fb177c083259", [:mix], [{:bamboo, "~> 1.2", [hex: :bamboo, repo: "hexpm", optional: false]}, {:gen_smtp, "~> 0.15.0", [hex: :gen_smtp, repo: "hexpm", optional: false]}], "hexpm", "77cb1fa3076b24109e54df622161fe1e5619376b4ecf86d8b99b46f327acc49f"},
"bonfire_api_graphql": {:git, "https://github.com/bonfire-networks/bonfire_api_graphql", "8d957c12b6b9d5a33911a9249213df1056e9928a", [branch: "main"]},
"bonfire_api_graphql": {:git, "https://github.com/bonfire-networks/bonfire_api_graphql", "eea66ea3b37ea3549dcf72e8e15dd3113044e87c", [branch: "main"]},
"bonfire_boundaries": {:git, "https://github.com/bonfire-networks/bonfire_boundaries", "fe4fcd9235e6cc107c2fff2cb23c5e25477420fc", [branch: "main"]},
"bonfire_breadpub": {:git, "https://github.com/bonfire-networks/bonfire_breadpub", "29be3e313000f20a91373633c4255f4b47c3c829", [branch: "main"]},
"bonfire_classify": {:git, "https://github.com/bonfire-networks/bonfire_classify", "cfc517c1db461b6cc74aa8adb479975a1f59b324", [branch: "main"]},
"bonfire_common": {:git, "https://github.com/bonfire-networks/bonfire_common", "3d02d6e2876929eb0731cca815bd6f5a0e5d0914", [branch: "main"]},
"bonfire_breadpub": {:git, "https://github.com/bonfire-networks/bonfire_breadpub", "ee72b3fc28d7adfae626d9b06f42fd03e1c23b2f", [branch: "main"]},
"bonfire_classify": {:git, "https://github.com/bonfire-networks/bonfire_classify", "e2c86e68a4d57eee8dfd6715f9e535598e106828", [branch: "main"]},
"bonfire_common": {:git, "https://github.com/bonfire-networks/bonfire_common", "5f1a33e69530aa7ef3afd6c3b0b75fbf26a73a7b", [branch: "main"]},
"bonfire_data_access_control": {:git, "https://github.com/bonfire-networks/bonfire_data_access_control", "fe8aa3c14c36ebe3ce128943a21d4362615557b5", [branch: "main"]},
"bonfire_data_activity_pub": {:git, "https://github.com/bonfire-networks/bonfire_data_activity_pub", "e69c1e725aad182e0c17c7b6bea0f14a40d4827f", [branch: "main"]},
"bonfire_data_identity": {:git, "https://github.com/bonfire-networks/bonfire_data_identity", "2160ce737c68783f579e1838cebe2ce2da14455c", [branch: "main"]},
@ -20,19 +20,19 @@
"bonfire_fail": {:git, "https://github.com/bonfire-networks/bonfire_fail", "454f676fb82f7c0453bc839ce012a078c8d9149e", [branch: "main"]},
"bonfire_federate_activitypub": {:git, "https://github.com/bonfire-networks/bonfire_federate_activitypub", "7872961c8c10cdb5e33f2c42e7a05bf2ca27b35a", [branch: "main"]},
"bonfire_files": {:git, "https://github.com/bonfire-networks/bonfire_files", "4494e174e5258bb49df7eb70c4b8b331ca54992d", [branch: "main"]},
"bonfire_geolocate": {:git, "https://github.com/bonfire-networks/bonfire_geolocate", "8c967013dc5c3f056e4a7ace7077c4dece6e591b", [branch: "main"]},
"bonfire_geolocate": {:git, "https://github.com/bonfire-networks/bonfire_geolocate", "7eadfd43158a61c78a6ba7634a3bb28a9606099a", [branch: "main"]},
"bonfire_mailer": {:git, "https://github.com/bonfire-networks/bonfire_mailer", "d7a4a41b76c8d64b7bc7d1add7013ae63ee475fb", [branch: "main"]},
"bonfire_me": {:git, "https://github.com/bonfire-networks/bonfire_me", "650f75c76350d6f43834664535fa8ff8b5ede517", [branch: "main"]},
"bonfire_me": {:git, "https://github.com/bonfire-networks/bonfire_me", "17d194526f7f186dfc918aee0bba8e953a76e9d2", [branch: "main"]},
"bonfire_quantify": {:git, "https://github.com/bonfire-networks/bonfire_quantify", "40b808b3658ff25f3d83941156a9beb0652dad44", [branch: "main"]},
"bonfire_search": {:git, "https://github.com/bonfire-networks/bonfire_search", "6d582cc2e87bb237de5e7b853b9e99a253fc56e6", [branch: "main"]},
"bonfire_social": {:git, "https://github.com/bonfire-networks/bonfire_social", "f0f3558e8d7c3fc969f3d22e0ed85d0f82e11c78", [branch: "main"]},
"bonfire_tag": {:git, "https://github.com/bonfire-networks/bonfire_tag", "085641479cfa3ee497b43ae54bfc02f3d200590e", [branch: "main"]},
"bonfire_ui_coordination": {:git, "https://github.com/bonfire-networks/bonfire_ui_coordination", "025d1cc2c4f9e7e7060b84aae796a5d7efb6516c", [branch: "main"]},
"bonfire_ui_social": {:git, "https://github.com/bonfire-networks/bonfire_ui_social", "dd924a9a537f703c775aa0661b77b506dab9a57d", [branch: "main"]},
"bonfire_ui_valueflows": {:git, "https://github.com/bonfire-networks/bonfire_ui_valueflows", "6aee8c1351e8630fa30a28da79716824fa001116", [branch: "main"]},
"bonfire_valueflows": {:git, "https://github.com/bonfire-networks/bonfire_valueflows", "13d0f637e1b095a026e8c3ad7cda2392c6a440c6", [branch: "main"]},
"bonfire_search": {:git, "https://github.com/bonfire-networks/bonfire_search", "cae7d700b6cae32a9c4b2e811edee211475b3c22", [branch: "main"]},
"bonfire_social": {:git, "https://github.com/bonfire-networks/bonfire_social", "f6cd266e3263d26b309c5971904bf52b2a0a0229", [branch: "main"]},
"bonfire_tag": {:git, "https://github.com/bonfire-networks/bonfire_tag", "95821a077d6abcfe17588fd55f280641094fcba9", [branch: "main"]},
"bonfire_ui_coordination": {:git, "https://github.com/bonfire-networks/bonfire_ui_coordination", "f6e61b134d19c6b0d5399cc9e1b8ddb68fdc8d77", [branch: "main"]},
"bonfire_ui_social": {:git, "https://github.com/bonfire-networks/bonfire_ui_social", "cf7695b2353d04025bae07586ce052ae6d805e89", [branch: "main"]},
"bonfire_ui_valueflows": {:git, "https://github.com/bonfire-networks/bonfire_ui_valueflows", "62b1eae6a5010547e846273c81d10aced744ebbb", [branch: "main"]},
"bonfire_valueflows": {:git, "https://github.com/bonfire-networks/bonfire_valueflows", "61611e9930e62a31f8299e0ce8491eb3257b3bb7", [branch: "main"]},
"bonfire_valueflows_observe": {:git, "https://github.com/bonfire-networks/bonfire_valueflows_observe", "f90358836370fb8821b7d4020ce6cc01702ecb07", []},
"bonfire_website": {:git, "https://github.com/bonfire-networks/bonfire_website", "298813191afdd710ebbfedd4ab0553a858fb50a5", [branch: "main"]},
"bonfire_website": {:git, "https://github.com/bonfire-networks/bonfire_website", "341a3dcff82e977ecb715879ca1352d4d5f0723a", [branch: "main"]},
"cachex": {:hex, :cachex, "3.3.0", "6f2ebb8f27491fe39121bd207c78badc499214d76c695658b19d6079beeca5c2", [:mix], [{:eternal, "~> 1.2", [hex: :eternal, repo: "hexpm", optional: false]}, {:jumper, "~> 1.0", [hex: :jumper, repo: "hexpm", optional: false]}, {:sleeplocks, "~> 1.1", [hex: :sleeplocks, repo: "hexpm", optional: false]}, {:unsafe, "~> 1.0", [hex: :unsafe, repo: "hexpm", optional: false]}], "hexpm", "d90e5ee1dde14cef33f6b187af4335b88748b72b30c038969176cd4e6ccc31a1"},
"certifi": {:hex, :certifi, "2.6.1", "dbab8e5e155a0763eea978c913ca280a6b544bfa115633fa20249c3d396d9493", [:rebar3], [], "hexpm", "524c97b4991b3849dd5c17a631223896272c6b0af446778ba4675a1dff53bb7e"},
"combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm", "1b1dbc1790073076580d0d1d64e42eae2366583e7aecd455d1215b0d16f2451b"},