aboutsummaryrefslogtreecommitdiff
path: root/shard/lib/app/chat.ex
diff options
context:
space:
mode:
Diffstat (limited to 'shard/lib/app/chat.ex')
-rw-r--r--shard/lib/app/chat.ex6
1 files changed, 5 insertions, 1 deletions
diff --git a/shard/lib/app/chat.ex b/shard/lib/app/chat.ex
index fa62c9e..db2cb64 100644
--- a/shard/lib/app/chat.ex
+++ b/shard/lib/app/chat.ex
@@ -52,7 +52,8 @@ defmodule SApp.Chat do
Shard.Manager.dispatch_to(id, nil, self())
{:ok, page_store} = SApp.PageStore.start_link(id, :page_store)
mst = %MST{store: %SApp.PageStore{pid: page_store},
- cmp: &msg_cmp/2}
+ cmp: &msg_cmp/2,
+ root: Shard.Manager.load_state(id)}
GenServer.cast(self(), :init_pull)
{:ok,
%{channel: channel,
@@ -104,6 +105,7 @@ defmodule SApp.Chat do
prev_root = state.mst.root
mst = MST.insert(state.mst, msgitem)
state = %{state | mst: mst}
+ Shard.Manager.save_state(state.id, mst.root)
for pid <- state.subs do
if Process.alive?(pid) do
@@ -160,6 +162,7 @@ defmodule SApp.Chat do
if mst2.root == new_root do
# This was the only message missing, we are happy!
state = %{state | mst: mst2}
+ Shard.Manager.save_state(state.id, mst2.root)
GenServer.cast(state.page_store, {:set_roots, [mst2.root]})
msg_callback(state, msgitem)
state
@@ -200,6 +203,7 @@ defmodule SApp.Chat do
end
GenServer.cast(state.page_store, {:set_roots, [mst.root]})
+ Shard.Manager.save_state(state.id, mst.root)
%{state | mst: mst}
end