aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2018-10-15 10:54:03 +0200
committerAlex Auvolat <alex@adnab.me>2018-10-15 10:54:03 +0200
commit0f8acfa78bf101ed1c2ae993684b22de89d94bf7 (patch)
tree7058cdd8a377f3ff2cb901ae1d629d7d15d9b6e7
parentb26c794c3b4f8a5ec7892c512193f11656264814 (diff)
downloadshard-0f8acfa78bf101ed1c2ae993684b22de89d94bf7.tar.gz
shard-0f8acfa78bf101ed1c2ae993684b22de89d94bf7.zip
adapt (badly) to unsynced clocks
-rw-r--r--shard/lib/app/chat.ex8
-rw-r--r--shardweb/lib/templates/chat/chat.html.eex2
2 files changed, 8 insertions, 2 deletions
diff --git a/shard/lib/app/chat.ex b/shard/lib/app/chat.ex
index be3b848..2e5e076 100644
--- a/shard/lib/app/chat.ex
+++ b/shard/lib/app/chat.ex
@@ -163,7 +163,13 @@ defmodule SApp.Chat do
with all connected peers.
"""
def handle_cast({:chat_send, pk, msg}, state) do
- msgbin = SData.term_bin {(System.os_time :seconds), msg}
+ next_ts = case MST.last(state.mst, nil, 1) do
+ [] -> System.os_time :seconds
+ [{{_, msgbin, _}, true}] ->
+ {ts, _msg} = SData.term_unbin msgbin
+ max(ts + 1, System.os_time :seconds)
+ end
+ msgbin = SData.term_bin {next_ts, msg}
{:ok, sign} = Shard.Keys.sign_detached(pk, msgbin)
msgitem = {pk, msgbin, sign}
diff --git a/shardweb/lib/templates/chat/chat.html.eex b/shardweb/lib/templates/chat/chat.html.eex
index 28cc9e6..499e14d 100644
--- a/shardweb/lib/templates/chat/chat.html.eex
+++ b/shardweb/lib/templates/chat/chat.html.eex
@@ -6,7 +6,7 @@
#<%= @chan %>
<small>public chat room</small>
<% else %>
- #<%= @nicks %>
+ <%= @nicks %>
<small>private chat</small>
<% end %>