Firebase one to one chat implementation for web - javascript

I implemented friendly chat. But that is group chat. I am new to firebase. Need docs for creating one to one web chat. How to get list of user accounts and selecting single user to send message? Please help me

If the users communicating have user IDs uid_1 and uid_2.
The database structure should be:
contacts
--uid1
--uid2
--uid3
-- so on (1)
--uid2
--uid1
--uid4
-- so on (2)
messages
--uid1
--uid2
-- Push messages here.(3)
--uid2
--uid3
-- Push messages here also.(4)
Adding Contacts
If USER 1 knows USER 2 you can add USER 2 in location (1) and add USER 1 in location (2). Since you are implementing with user IDs the USERS will be able to send messages if they know the other USER's uid. You can send Chat Invites to exchange uids.
Adding Messages
If USER 1 or USER 2 sends a message add at locations (3) and (4). This implementation will make sure that even if USER 1 deletes a conversation with USER 2, USER 2 will still have a copy and thus ensuring privacy.
These are the key elements to make a basic one-on-one Firebase Chat App.
NOTE: User IDs are provided by Firebase on successful authentication.

Maybe try breaking your problem into individual milestones and learn how Firebase works as you need help in each milestone.
According to what you have written, you have to:
Authenticate Users (https://firebase.google.com/docs/auth/)
Save those user profiles onto the Real-Time Firebase Database in the following data structure (https://firebase.google.com/docs/database/)
List those users in a List / RecycleView (learnhowtoprogram.com/android/data-persistence/firebase-recycleradapter)
Manage the conversation through listeners in the adapter that reference child nodes which serve as rooms between 2 people.
Think about how to make your structure as efficient as possible such as not saving conversations twice under each user but rather saving a reference to a separate 'conversations' node.
I recently implemented this in my location-based app (Occupapp) if you want a live example. You will have to register, add a service and log in from another device and select that service to chat to the owner.

Related

Sending data from another system to update HubSpot live chat properties

I'm using hubspot's live chat feature in one of my products. Currently, I am using a chatbot conversation to get user information in order to identify a user. But I need a way to get the user's input (email, username), whenever they start a conversation through the chat widget without asking them.
Is there any possible way to send data from another system to update the HubSpot live chat?

How to send browser notifications for specific users?

I want to add browser notifications for my rails app.
I'm having trouble adding notifications to specific users.
For example, i have user and lesson models.
And I want to send notifications to the user about the beginning of the lesson.
But how do I send notifications, not to all users, but only to those related to the lesson?
The first thing you should do is to get and store the subscription object for each user. Then, in your application, you should send a notification only for related users.
There are a bunch of different gems for it, e.g. https://github.com/zaru/webpush

How to have one to one chat using firebase in AngularJS

I am trying to have a one to one chat feature using firebase. Right now, my structure of messages makes sense in the fb database but I am not able to implement one to one chat feature using firebase's api in angular. I am able to spam a chat room where all the users can see everyone's messages but i would like to have a one to one chat feature in my application. My structure is good in the firebase database and i just need to manipulate my javascript code to make it work. My code is as follows.
function chatController($scope,$firebaseArray) {
var ref1=firebase.database().ref().child('users/59c1c11cec/chats/-KuRshPYbO_d9B');
$scope.chats=$firebaseArray(ref1);
var ref=firebase.database().ref().child('chats/-KuRshPYbO_d9B/messages');
$scope.messages=$firebaseArray(ref);
$scope.send=function(){
$scope.messages.$add({
message:$scope.messageText,
// date:Date.now()
})
}
}
I am able to create a one to one chat between two users by hard coding their user ids, but I was wondering if firebase's api is able to do this dynamically. If yes, how would I do it? For reference, 59c1c11cec is the current logged in user id, -KuRshPYbO_d9B is the other person's id who the current person is starting a conversation with which I don't have any access to in my own database but only in firebase's database. And using that users id I retrieve the messages between the two users. How will I be able to achieve this? I just need to replace the hard coded values with the values I talked about.Thanks a lot in advance!

How to get corresponding user information - FireBase

I am new to firebase and I need some help with something.
I am creating an application which allows users to post tasks. When a user saves a task their uid is sent to the database along with the task information. In my database I have a separate child for users which contains all of a users information, i.e name and other stuff.
When my app starts I want to pull all tasks from firebase and according to the uid saved with a task, I want to pull the user information corresponding to that task so that I could set correction information on the cards.
I need help achieving this, thanks.

StrongLoop Roles Scenario

I recently came across StrongLoop and am thinking of porting my existing app to it. However, I am unable to wrap my head around how the following scenario can be catered for:
My app is supposed to have two distinct regions Retailer and Customer. The UI and functionality for Retailers is very different from that for Customers.
The users, on the other hand, can have the roles Retailer, Customer, and even both Retailer and Customer. So when a user tries to log in, I check what roles she has assigned. If she has a single role, I redirect her to the appropriate section of the site.
If, however, she has multiple roles, I need to present her with a list of roles assigned to her where she needs to make a selection what role she wants to assume for this login. If she selects Retailer, I should redirect her to the Retailer section of the app where she should only be able to post products (let's say). If she selects Customer, I should redirect her to the Customer section of the app where she can only view the products posted by all retailers.
In a StrongLoop world, is there any way I can achieve this?

Categories