I'm currently creating a random chat application where the user presses a button and is paired with another user and then they can chat.
I plan on using Parse for user control and file storage, and pubnub for chat.
My question is, what would be the correct way to pair and connect two users and put them into a chat together?
Lets say user1 presses the search button to start searching for another user, user1's status in the parse database is then updated to 'searching' and the app then queries the database for another user who's status is also 'searching'. the query returns user2 and a new chat channel is created from the two users names combined together (e.g. Pubnub Chat Channel: 'user1user2').
User1 is then put into this chat channel and the chat activity is started. This is where I get confused, how will my app then know that it needs to put user2 into a chat with user1? Because from my thinking, user2 has also pressed the search button to query the parse database for another user and therefore they could be put into a chat with another random user and not user1.
Any help on the correct method to achieve this would be really appreciated, thanks.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
This is a cool use case. Here's some insight into how to get started with this design.
Setup
ch_user123
andcg_user123
, respectively.cg_idle
,cg_searching
,cg_active
. This channel group will contain all the unique user channel names of users that are not actively engaged in a chat and not searching for a chat partner.User Login
When a user logs in (successfully), your server will add that user's unique channel to the channel group
idle
and to the user's unique channel group (IOW - addch_user123
tocg_user123
and tocg_idle
Search of Chat Partner
When a user clicks the search for chat partner button, your server app will
cg_idle
channel groupcg_searching
channel grouplist_channels
of thecg_idle
to get a list of chat partner candidatescg_idle
candidatescg_idle
again to get an updated list) - IOW, go back to step 4cg_idle
and add it tocg_active
cg_searching
and add it tocg_active
1234-5678-9ABC
tocg_user123
andcg_user456
. These two users are not subscribe to the same channel to begin their chatting adventure with each other.cg_active
, added tocg_idle
, and the share chat channel is removed from both users' unique channel groups.I can think of several details and features that would need to be addressed above and race conditions that your service would have control but this should expose how you can use channel groups to control the state of the users and a way of creating a name directory of users.