summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/util.ex12
-rw-r--r--lib/web/controllers/irc_controller.ex2
-rw-r--r--lib/web/live/chat_live.ex7
-rw-r--r--lib/web/live/chat_live.html.heex4
-rw-r--r--lib/web/templates/layout/app.html.eex2
5 files changed, 20 insertions, 7 deletions
diff --git a/lib/util.ex b/lib/util.ex
index 8bd3b9d..a402519 100644
--- a/lib/util.ex
+++ b/lib/util.ex
@@ -1,5 +1,17 @@
defmodule Util do
+ defmodule Map do
+
+ def put_if_not_null(map, _key, nil) do
+ map
+ end
+
+ def put_if_not_null(map, key, value) do
+ Elixir.Map.put(map, key, value)
+ end
+
+ end
+
def to_naive_date_time(naive = %NaiveDateTime{}), do: naive
def to_naive_date_time(datetime = %DateTime{}), do: DateTime.to_naive(datetime)
def to_naive_date_time(timestamp) when is_integer(timestamp) do
diff --git a/lib/web/controllers/irc_controller.ex b/lib/web/controllers/irc_controller.ex
index e87382b..a78582e 100644
--- a/lib/web/controllers/irc_controller.ex
+++ b/lib/web/controllers/irc_controller.ex
@@ -9,7 +9,7 @@ defmodule NolaWeb.IrcController do
commands = for mod <- Enum.uniq([Nola.Plugins.Account] ++ Nola.Plugins.enabled()) do
if is_atom(mod) do
identifier = Module.split(mod) |> List.last |> Macro.underscore
- {identifier, mod.irc_doc()}
+ if Kernel.function_exported?(mod, :irc_doc, 0), do: {identifier, mod.irc_doc()}
end
end
|> Enum.filter(& &1)
diff --git a/lib/web/live/chat_live.ex b/lib/web/live/chat_live.ex
index 8a9f6f2..6902250 100644
--- a/lib/web/live/chat_live.ex
+++ b/lib/web/live/chat_live.ex
@@ -7,7 +7,7 @@ defmodule NolaWeb.ChatLive do
chan = NolaWeb.reformat_chan(chan)
connection = Nola.Irc.Connection.get_network(network, chan)
account = Nola.Account.get(account_id)
- membership = Nola.Membership.of_account(Nola.Account.get("DRgpD4fLf8PDJMLp8Dtb"))
+ membership = Nola.Membership.of_account(Nola.Account.get(account.id))
if account && connection && Enum.member?(membership, {connection.network, chan}) do
{:ok, _} = Registry.register(Nola.PubSub, "#{connection.network}:events", plugin: __MODULE__)
for t <- ["messages", "triggers", "outputs", "events"] do
@@ -88,8 +88,9 @@ defmodule NolaWeb.ChatLive do
handle_info({:irc, nil, message}, socket)
end
- def handle_info({:irc, :text, message}, socket) do
- IO.inspect({:live_message, message})
+ # type is text, out, or nil if it's self?
+ def handle_info({:irc, type, message = %Nola.Message{}}, socket) do
+ IO.inspect({:live_message, type, message})
socket = socket
|> append_to_backlog(message)
{:noreply, socket}
diff --git a/lib/web/live/chat_live.html.heex b/lib/web/live/chat_live.html.heex
index 470604f..c3bb030 100644
--- a/lib/web/live/chat_live.html.heex
+++ b/lib/web/live/chat_live.html.heex
@@ -26,10 +26,10 @@
<%= for message <- @backlog do %>
<%= if is_map(message) && Map.get(message, :__struct__) == Nola.Message do %>
<li class="flex gap-2 place-items-center message"
- data-account-id={message.account.id}>
+ data-account-id={if(message.account, do: message.account.id, else: "bot")}>
<NolaWeb.MessageComponent.content
message={message}
- self={message.account.id == @account_id}
+ self={message.account && message.account.id == @account_id}
text={message.text}
/>
</li>
diff --git a/lib/web/templates/layout/app.html.eex b/lib/web/templates/layout/app.html.eex
index b3199e2..99dbe9e 100644
--- a/lib/web/templates/layout/app.html.eex
+++ b/lib/web/templates/layout/app.html.eex
@@ -121,7 +121,7 @@
<%= @inner_content %>
</div>
<div mt-4 text-grey text-small">
- v<%= Nola.version() %> <a href="<%= Nola.source_url() %>">source</a>
+ v<%= Nola.version() %> &mdash; <a href="<%= Nola.source_url() %>">source</a>
</div>
<!-- /End replace -->
</div>