我将在哪里存储主题 ID?
至于套接字,我可以使用:
def join("topic:" <> topic_id, _params, socket) do
...
socket= assign(socket, :topic_id, topic_id)
{:ok, socket}
end
那是在套接字范围内,但是我的用户可以同时加入多个主题,这意味着每次加入新主题时,上面的代码都会覆盖 topic_id,是这样吗?
如果我想知道哪个主题 ID 在 中处于活动状态handle_in
怎么办?
例如:
def handle_in("new_message", params, socket) do
# what is the active topic id here?
end
我虽然这样:
def handle_in("new_message:" <> topic_id, params, socket) do
# now, I know that topic_id is the active topic
end
还有另一种方法可以做到这一点吗?或者这就是它的完成方式?