     UcxChat.Endpoint.broadcast!(CC.chan_user() <> "#{user_id}", "room:leave", %{room: room, user_id: user_id})
   end
 
-  # intercept ~w(room:join room:leave)
-  # intercept ["room:join", "room:leave", "user:update"]
   intercept ["room:join", "room:leave"]
 
   def join(CC.chan_user() <>  user_id, params, socket) do

        push socket, "code:update", %{html: html2, selector: ~s(.user-card-room[data-status-name="#{user.username}"]), action: "html"}
      end
    else
      # warn event, payload, "closed"
    end
    {:noreply, socket}
  end

  def handle_info(%Broadcast{topic: _, event: "user:action" = event, payload: %{action: "removed"} = payload}, %{assigns: assigns} = socket) do
    warn event, payload, "assigns: #{inspect assigns}"
    current_user = Helpers.get_user! assigns.user_id
    user = Helpers.get_user! payload.user_id
    if Flex.open? assigns.flex, assigns.channel_id, "Members List" do
      warn event, payload, "removed open"

      push socket, "code:update", %{selector: ~s(.user-card-room[data-status-name='#{user.username}']), action: "remove"}
      push socket, "code:update", %{selector: ".flex-tab-container .user-view", action: "addClass", html: "animated-hidden"}
    else
      warn event, payload, "closed"
    end
    {:noreply, socket}
  end
  def handle_info(%Broadcast{topic: _, event: "user:action" = event, payload: %{action: "unhide"} = payload}, %{assigns: assigns} = socket) do
    warn event, payload, "assigns: #{inspect assigns}"
    # current_user = Helpers.get_user! assigns.user_id
    # user = Helpers.get_user! payload.user_id

    UserSocket.push_rooms_list_update(socket, payload.channel_id, payload.user_id)

    # if Flex.open? assigns.flex, assigns.channel_id, "Members List" do
    #   warn event, payload, "removed open"

    #   push socket, "code:update", %{selector: ~s(.user-card-room[data-status-name='#{user.username}']), action: "remove"}
    #   push socket, "code:update", %{selector: ".flex-tab-container .user-view", action: "addClass", html: "animated-hidden"}
    # else
    #   warn event, payload, "closed"
    # end
    {:noreply, socket}
  end
  def handle_info(%Broadcast{topic: _, event: "user:entered" = event, payload: %{user: user} = payload}, %{assigns: %{user: user} = assigns} = socket) do
    warn event, payload, "assigns: #{inspect assigns}"
    old_channel_id = assigns[:channel_id]
    channel_id = payload[:channel_id]
    socket = %{assigns: assigns} = assign(socket, :channel_id, channel_id)

  # Info messages

  def handle_info(:after_join, socket) do
    debug "after_join", socket.assigns
    {:noreply, socket}
  end

  def handle_info(%Broadcast{topic: _, event: "room:update:name" = event, payload: payload}, socket) do
    debug event, payload
    push socket, event, payload
    socket.enkdpoint.unsubscribe(CC.chan_room <> payload[:old_name])
    {:noreply, assign(socket, :subscribed, [payload[:new_name] | List.delete(socket.assigns[:subscribed], payload[:old_name])])}
  end

  def handle_info(%Broadcast{topic: _, event: "user:action" = event, payload: %{action: "owner"} = payload}, %{assigns: assigns} = socket) do
    debug event, payload
    current_user = Helpers.get_user! assigns.user_id
    user = Helpers.get_user! payload.user_id
    if Flex.open? assigns.flex, assigns.channel_id, "Members List" do
      html1 = Helpers.render(FlexBarView, "user_card_actions.html", current_user: current_user, channel_id: assigns.channel_id, user: user)
      push socket, "code:update", %{html: html1, selector: ~s(.user-view nav[data-username="#{user.username}"]), action: "html"}
    end
    {:noreply, socket}
  end

  def handle_info(%Broadcast{topic: _, event: "user:action" = event, payload:
      %{action: action} = payload}, %{assigns: assigns} = socket) when action in ~w(block) do
    debug event, payload, "assigns: #{inspect assigns}"
    current_user = Helpers.get_user! assigns.user_id
    user = Helpers.get_user! payload.user_id
    channel = Helpers.get!(Channel, assigns.channel_id)
    if Flex.open? assigns.flex, assigns.channel_id, "User Info" do
      # debug event, payload, action <> " open"
      user_info = FlexBarService.user_info channel, direct: true
      html1 = Helpers.render(FlexBarView, "user_card_actions.html", current_user: current_user, channel_id: assigns.channel_id, user: user, user_info: user_info)
      push socket, "code:update", %{html: html1, selector: ~s(.user-view nav[data-username="#{user.username}"]), action: "html"}
    else
      # debug event, payload, "closed"
    end
    {:noreply, socket}
  end

  def handle_info(%Broadcast{topic: _, event: "user:action" = event, payload:
      %{action: action} = payload}, %{assigns: assigns} = socket) when action in ~w(mute moderator owner) do
    debug event, payload
    current_user = Helpers.get_user! assigns.user_id
    user = Helpers.get_user! payload.user_id
    if Flex.open? assigns.flex, assigns.channel_id, "Members List" do
      # debug event, payload, action <> " open"
      html1 = Helpers.render(FlexBarView, "user_card_actions.html", current_user: current_user, channel_id: assigns.channel_id, user: user)
      push socket, "code:update", %{html: html1, selector: ~s(.user-view nav[data-username="#{user.username}"]), action: "html"}

