Skip to content

Commit

Permalink
fix: implement match check
Browse files Browse the repository at this point in the history
  • Loading branch information
zvonimirr committed Jun 16, 2024
1 parent 19504da commit 7c2bd58
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/swipex_web/live/chat_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ defmodule SwipexWeb.ChatLive do
use SwipexWeb, :live_view
alias Phoenix.PubSub

def mount(%{"id" => id}, %{"user_id" => _user_id}, socket) do
case Swipex.User.get_user_by_id(id) do
{:ok, user} ->
PubSub.subscribe(Swipex.PubSub, "swipex")
{:ok, assign(socket, :recipient, user)}
def mount(%{"id" => id}, %{"user_id" => user_id}, socket) do
IO.inspect({id, user_id})

{:error, _} ->
with true <- Swipex.User.has_matched(id, user_id),
{:ok, user} <- Swipex.User.get_user_by_id(id) do
PubSub.subscribe(Swipex.PubSub, "swipex")
{:ok, assign(socket, :recipient, user)}
else
_ ->
{:ok, socket |> put_flash(:error, "Something went wrong.") |> redirect(to: "/profile")}
end
end
Expand Down

0 comments on commit 7c2bd58

Please sign in to comment.