Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pubnub channel group history

I have gone through pubnub channel group design pattern, http://scalabl3.github.io/pubnub-design-patterns/2015/08/11/Advanced-Channel-Groups-Friend-Lists-Status-Feed-And-Presence.html

But still am stuck with some doubts to implementing a group chat

Consider I have groups GP1,GP2

GP1--A,B,C (Members) GP2--A,D,E (Members)

  • Here do i need to subscribe 2 groups,If 2 do i need to add A in both ? or 1 group with ABCDE by filtering
  • How do i get all the group history by a single api call (Assuming if GP1 has more than 100 friends)

Thanks

like image 432
Vaisakh N Avatar asked Dec 14 '22 11:12

Vaisakh N


2 Answers

The post you are referring to that I wrote is primarily about the pattern for creating shallow friend graphs and status feeds, but you can adapt it for chats pretty easily.

For chat, you can learn from the patterns here: http://scalabl3.github.io/pubnub-design-patterns/2015/03/05/Inbound-Channel-Pattern.html

If group chats have small groups, the Inbound pattern works well, I'd say less than 5-7 people in the group chat. It does not work well for larger groups, ex. 50 people, because you are publishing to every users' Inbound channel for every chat message you send. In the case of larger groups, the group chat itself should have it's own channel. You are correct, if you participate in a large number of large group chats you will have to retrieve history on each, each one being an API call. If the chats are more 1-1 or small group, then the Inbound pattern makes it simpler to get history.

Merging both patterns means that you will use the cg-user-[uid]-status-feed (also might want to call it something different, naming convention can be your own of course, maybe cg-user-[uid]-chats), but put in the Inbound channel + any larger group chats channels.

History still is on a per channel basis, so you would get history on Inbound which will be for any 1-1 or small group chats, and then get history on any channels that are for larger group chats.

More specifically to your question:

GP1 and GP2 are both small groups, so it's simpler to have any chat messages sent to each user, via Inbound channel, in each individual group, in the JSON payload you will also include metadata like:

Message to GP1 from User A
{ 
   group_chat: "GP1",
   from: "A",
   to: "A,B,C",
   timestamp: 1443112089,
   message: "hey guys, good morning"
}

Message to GP2 from User E
{ 
   group_chat: "GP2",
   from: "E",
   to: "A,D,E",
   timestamp: 1443112192,
   message: "I'm going afk for a bit, time for the gym"
}

This message will be published 3 times, one to each of the Inbound channels for users [GP1: A,B,C, GP2: A,D,E]. With that metadata you have the information you need so that in your UI you can make sure to put the received message into the right UI container, i.e. the Group Chat for GP1 and for GP2.

If you have more questions, let me know...

like image 133
scalabl3 Avatar answered Dec 21 '22 09:12

scalabl3


PubNub Channel Group Design Patterns & Use Cases

I think you might have misunderstood the intent of the design pattern at the link you provided. So rather than try to address that specific design pattern, I am going to explain how I would implement a group chat using PubNub Channel Groups at a very high level and maybe the detailed design patter at that link might become more apparent.

Every end user has their very own channel group:

  • cg_user123
  • cg_user456
  • and so on

The end user's channel group will contain every chat room channel that they are currently participating (or at least passively listening to). So cg_user123 might have channels sports_talk, money_talk and pubnub_is_awesome_talk. cg_user456 might have money_talk and your_momma_jokes. So each user's channel group can maintain a different list of channels that are unique to that end user.

You can also think about the Facebook or Twitter design pattern (friend and followers). Each end user will have a unique channel group that has all the channels of all of their friends or people they follow. When one of those friends publishes a message on their private channel (not to be confused with their private channel group), then all of that publisher's friends will receive that message because that channel is in each of their friends' unique channel group. If I want to unfriend or unfollow someone, I just remove that private channel from my channel group.

You can also think of channel groups as topics or subjects (channels) of interest. Maybe you decide your app allows your end users to subscribe to topics like sports, finance, technology & politics. You can create a channel group for each and add channels that are related to those channel group topics/subjects. So the technology channel group would contain the pubnub_is_awesome, ruby_fanboys and long_live_cobol channels (and many more) and the other channel groups would contain channels appropriate for those topics. Then your end users would elect to receive messages from those high level topics and your app would subscribe them to the appropriate channel groups based on their topic interests. And your server side code could dynamically add new channels to these channels as new channels are created and remove channels that are no longer in use and your client code doesn't need to do any additional work.

I know this might not directly answer your question but I believe it provides a better understanding of some popular use cases for channel groups.

like image 32
Craig Conover Avatar answered Dec 21 '22 09:12

Craig Conover