Commit 5945ec84 authored by lain's avatar lain
Browse files

Don't save user in socket, just save the name.

parent 69f1024b
Pipeline #380 failed with stage
in 3 minutes and 1 second
......@@ -25,7 +25,7 @@ defmodule Pleroma.Web.UserSocket do
def connect(%{"token" => token}, socket) do
with {:ok, user_id} <- Phoenix.Token.verify(socket, "user socket", token, max_age: 84600),
%User{} = user <- Pleroma.Repo.get(User, user_id) do
{:ok, assign(socket, :user, user)}
{:ok, assign(socket, :user_name, user.nickname)}
_e -> :error
defmodule Pleroma.Web.ChatChannel do
use Phoenix.Channel
alias Pleroma.Web.ChatChannel.ChatChannelState
alias Pleroma.User
def join("chat:public", _message, socket) do
send(self(), :after_join)
......@@ -12,10 +13,10 @@ def handle_info(:after_join, socket) do
{:noreply, socket}
def handle_in("new_msg", %{"text" => text}, socket) do
author = socket.assigns[:user]
def handle_in("new_msg", %{"text" => text}, %{assigns: %{user_name: user_name}} = socket) do
author = User.get_cached_by_nickname(user_name)
author = Pleroma.Web.MastodonAPI.AccountView.render("account.json", user: author)
message= ChatChannelState.add_message(%{text: text, author: author})
message = ChatChannelState.add_message(%{text: text, author: author})
broadcast! socket, "new_msg", message
{:noreply, socket}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment