aboutsummaryrefslogtreecommitdiff
path: root/shard/lib/cli/cli.ex
diff options
context:
space:
mode:
Diffstat (limited to 'shard/lib/cli/cli.ex')
-rw-r--r--shard/lib/cli/cli.ex28
1 files changed, 9 insertions, 19 deletions
diff --git a/shard/lib/cli/cli.ex b/shard/lib/cli/cli.ex
index 3778b2d..2e35e45 100644
--- a/shard/lib/cli/cli.ex
+++ b/shard/lib/cli/cli.ex
@@ -12,13 +12,7 @@ defmodule SCLI do
GenServer.cast(chpid, {:subscribe, self()})
end
- pk = case Shard.Keys.list_identities do
- [pk1|_] -> pk1
- _ ->
- IO.puts "Generating a new identity..."
- Shard.Keys.new_identity
- end
-
+ pk = Shard.Keys.get_any_identity
run(%State{room_pid: nil, id_pid: nil, pk: pk})
end
@@ -63,8 +57,10 @@ defmodule SCLI do
defp handle_messages() do
receive do
- {:chat_recv, chan, {ts, nick, msg}} ->
- IO.puts "#{ts |> DateTime.from_unix! |> DateTime.to_iso8601} ##{chan} <#{nick}> #{msg}"
+ {:chat_recv, chan, {pk, msgbin, _sign}} ->
+ {ts, msg} = SData.term_unbin msgbin
+ nick = SApp.Identity.get_nick pk
+ IO.puts "#{ts |> DateTime.from_unix! |> DateTime.to_iso8601} ##{chan} <#{nick} #{Shard.Keys.pk_display pk}> #{msg}"
handle_messages()
{:chat_send, _, _} ->
# do nothing
@@ -95,16 +91,10 @@ defmodule SCLI do
else
GenServer.call(state.room_pid, {:read_history, nil, 25})
|> Enum.each(fn {{pk, msgbin, _sign}, true} ->
- {ts, msg} = SData.term_unbin msgbin
- nick = case SApp.Identity.find_proc pk do
- nil ->
- SApp.Identity.default_nick pk
- pid ->
- info = GenServer.call(pid, :get_info)
- info.nick
- end
- IO.puts "#{ts |> DateTime.from_unix! |> DateTime.to_iso8601} <#{nick} #{pk|>binary_part(0, 4)|>Base.encode16|>String.downcase}> #{msg}"
- end)
+ {ts, msg} = SData.term_unbin msgbin
+ nick = SApp.Identity.get_nick pk
+ IO.puts "#{ts |> DateTime.from_unix! |> DateTime.to_iso8601} <#{nick} #{Shard.Keys.pk_display pk}> #{msg}"
+ end)
end
state
end