dwyl / dwyl/phoenix-liveview-chat-example

Going further: set up a private chat between users

Open
#83 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
Elixir
Stars
162
Forks
12
Avg merge
1d 9h
Merged PRs (30d)
3

Description

![image](https://user-images.githubusercontent.com/6793008/204131115-e63f171f-477a-4020-b172-5e6ded08bafa.png)

Question: **How do you create a private chat between two users?**

> I did not find a way to get all subscribers.

When you look at the [code for Phoenix.PubSub.subscribe](https://github.com/phoenixframework/phoenix_pubsub/blob/v2.1.1/lib/phoenix/pubsub.ex#L119):
```elixir
# Phoenix.PubSub.subscribe
def subscribe(pubsub, topic, opts \\ [])
when is_atom(pubsub) and is_binary(topic) and is_list(opts) do
case Registry.register(pubsub, topic, opts[:metadata]) do
{:ok, _} -> :ok

# Phoenix.PubSub.unsubscribe
def unsubscribe(pubsub, topic) when is_atom(pubsub) and is_binary(topic) do
Registry.unregister(pubsub, topic)
```

Dwyl/I use `Phoenix.Endpoint` instead of `Phoenix.PubSub` and the PubSub is started with:

```elixir
{Phoenix.PubSub, name: MyApp.PubSub},
```

and the standard configuration is:

```elixir
config :live_map, MyAppWeb.Endpoint,
pubsub_server: MyApp.PubSub,
```

We don't use the "atom" form" . Does this start a registry?

I don't see anything:

```bash
iex> Registry.count(MyAppPubSub)
# 12 ????
iex> Registry.keys(MyApp.PubSub, self())
# [] ?????

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.