aboutsummaryrefslogtreecommitdiff
path: root/lib/app/chat.ex
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2018-07-03 15:42:17 +0200
committerAlex Auvolat <alex@adnab.me>2018-07-03 15:42:17 +0200
commit8f3009715ee9ccdd7ecb54fea1244a32a29b62c0 (patch)
tree416fb96c39effa4217864bb6a93243803ba8edba /lib/app/chat.ex
downloadshard-8f3009715ee9ccdd7ecb54fea1244a32a29b62c0.tar.gz
shard-8f3009715ee9ccdd7ecb54fea1244a32a29b62c0.zip
Initialize shard repo with code from somewhere
Diffstat (limited to 'lib/app/chat.ex')
-rw-r--r--lib/app/chat.ex21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/app/chat.ex b/lib/app/chat.ex
new file mode 100644
index 0000000..4a56085
--- /dev/null
+++ b/lib/app/chat.ex
@@ -0,0 +1,21 @@
+defmodule SApp.Chat do
+ def send(msg) do
+ msgitem = {(System.os_time :seconds),
+ Shard.Identity.get_nickname(),
+ msg}
+ GenServer.cast(SApp.Chat.Log, {:insert, msgitem})
+
+ SNet.ConnSupervisor
+ |> DynamicSupervisor.which_children
+ |> Enum.each(fn {_, pid, _, _} -> GenServer.cast(pid, :init_push) end)
+ end
+
+ def msg_callback({ts, nick, msg}) do
+ IO.puts "#{ts |> DateTime.from_unix! |> DateTime.to_iso8601} <#{nick}> #{msg}"
+ end
+
+ def msg_cmp({ts1, nick1, msg1}, {ts2, nick2, msg2}) do
+ SData.MerkleList.cmp_ts_str({ts1, nick1<>"|"<>msg1},
+ {ts2, nick2<>"|"<>msg2})
+ end
+end