From d97e6d09f0db87989df42993499429883f1c224a Mon Sep 17 00:00:00 2001 From: href Date: Sun, 11 Dec 2022 01:47:26 +0000 Subject: feat(message): assign id (flake_id) --- lib/lsg_irc/logger_plugin.ex | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'lib/lsg_irc/logger_plugin.ex') diff --git a/lib/lsg_irc/logger_plugin.ex b/lib/lsg_irc/logger_plugin.ex index 667f714..e5307bc 100644 --- a/lib/lsg_irc/logger_plugin.ex +++ b/lib/lsg_irc/logger_plugin.ex @@ -13,6 +13,7 @@ defmodule LSG.IRC.LoggerPlugin do regopts = [plugin: __MODULE__] {:ok, _} = Registry.register(IRC.PubSub, "triggers", regopts) {:ok, _} = Registry.register(IRC.PubSub, "messages", regopts) + {:ok, _} = Registry.register(IRC.PubSub, "messages:private", regopts) {:ok, nil} end @@ -49,12 +50,20 @@ defmodule LSG.IRC.LoggerPlugin do state end - def format_to_db(m = %IRC.Message{}) do - %IRC.Message{m | replyfun: nil} + def format_to_db(msg = %IRC.Message{id: id}) do + msg + |> Poison.encode!() + |> Map.drop("id") + + %{"_id" => id || FlakeId.get(), + "type" => "irc.message/v1", + "object" => msg} end def format_to_db(anything) do - anything + %{"_id" => FlakeId.get(), + "type" => "object", + "object" => anything} end end -- cgit v1.2.3