aboutsummaryrefslogtreecommitdiff
path: root/shard/lib/app/chat.ex
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2018-10-11 17:52:25 +0200
committerAlex Auvolat <alex@adnab.me>2018-10-11 17:52:25 +0200
commit28c9cac2e92011e2f7e6f23e93e8a5d9480a0922 (patch)
treead81473619ba5b9c18e925323264f58982311662 /shard/lib/app/chat.ex
parente5a7330d0526efb592e200ab96c3f33585ae8d02 (diff)
downloadshard-28c9cac2e92011e2f7e6f23e93e8a5d9480a0922.tar.gz
shard-28c9cac2e92011e2f7e6f23e93e8a5d9480a0922.zip
Fix initiation issues
Diffstat (limited to 'shard/lib/app/chat.ex')
-rw-r--r--shard/lib/app/chat.ex13
1 files changed, 8 insertions, 5 deletions
diff --git a/shard/lib/app/chat.ex b/shard/lib/app/chat.ex
index 61403b8..f874e86 100644
--- a/shard/lib/app/chat.ex
+++ b/shard/lib/app/chat.ex
@@ -154,8 +154,7 @@ defmodule SApp.Chat do
end
def handle_cast({:peer_connected, conn_pid}, state) do
- # this is called by the SNet.Group thing so it is already authenticated
- SNet.Manager.send_pid(conn_pid, {state.id, nil, {:root, state.mst.root}})
+ GenServer.cast(conn_pid, {:send_msg, {:interested, [state.id]}})
{:noreply, state}
end
@@ -165,7 +164,7 @@ defmodule SApp.Chat do
"""
def handle_cast({:interested, conn_pid, auth}, state) do
if SNet.Group.in_group?(state.netgroup, conn_pid, auth) do
- SNet.Manager.send_pid(conn_pid, {state.id, nil, {:root, state.mst.root}})
+ SNet.Manager.send_pid(conn_pid, {state.id, nil, {:root, state.mst.root, true}})
end
{:noreply, state}
end
@@ -225,13 +224,17 @@ defmodule SApp.Chat do
state
end
end
- {:root, new_root} ->
- if new_root == state.mst.root do
+ {:root, new_root, ask_reply} ->
+ state = if new_root == state.mst.root do
# already up to date, ignore
state
else
init_merge(state, new_root, conn_pid)
end
+ if ask_reply do
+ SNet.Manager.send_pid(conn_pid, {state.id, nil, {:root, state.mst.root, false}})
+ end
+ state
x ->
Logger.info("Unhandled message: #{inspect x}")
state