From 8f3009715ee9ccdd7ecb54fea1244a32a29b62c0 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 3 Jul 2018 15:42:17 +0200 Subject: Initialize shard repo with code from somewhere --- lib/app/chat.ex | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib/app/chat.ex (limited to 'lib/app') 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 -- cgit v1.2.3