elixir - How to keep a user subscribed to every chat it is following -


enter image description here

thats messenger's facebook ui

if implementing phoenix (elixir framework)

would create 1 phoenix-channel 1 chat?

which implies client (mobile, web etc...) have open 1 channel every chat suscribed at

which implies if there 2000 chats suscribed at, have open 2000 channels (client load).

would create 1 phoenix-channel 1 user?

which implies client (mobile, web etc...) have open 1 channel ,

which implies every incoming message you'll have query al users in room (server load).

in messaging apps, there 2 primary concerns. managing list of resources (users, rooms, etc) user subscribed too. typically displayed list in client. need render list , update thinks presence, new message alerts, , perhaps showing if use has open chat window. solution part similar regardless if users/rooms point-to-point or multi-user (rooms).

the second concern displaying messages in individual chat windows open/visible. solution may vary depending on whether point-to-point or multi-user. however, facebook support multi-user chat, i'll answer based on experience building slack clone in phoenix.

i recommend 2 channels, 1 users , 1 open chat windows, lets call chat. each user have 1 instance of user channel , instance of chat channel each open chat window. user_id can used topic of user channel "user:" <> user.user_id. have schema each of chat sessions (which uses part of chat session). use id chat channel topic "chat:" <> chat.id.

you can broadcast new incoming messages in chat channel , go out in chat session (people have chat window open). work both point-to-point , multi-user windows.

the example provided in question shows 2 uses different state (text color). 1 shows missed call , other presume indicates unread message. type of state typically specific user, use use channel put push information.

to track indicators on user list, can subscribe messages in chat channel user channel. receive info messages in user channel , take appropriate actions if needed. if subscribe chat join messages, can build list of these , store in socket.assigns struct. see phoenix channels - multiple channels per socket more details.

another api use messaging apps intercept api. allows define handle_out function gets called specific broadcast events of channel. can used filter or manipulate outgoing messages broadcast on channel


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -