how to create basic chat app using messagekit and firebase (Realtime Database)?

397 Views Asked by At

The problem im facing is how can i recognize the sender and reciever of the message ? tried so hard but didn't find any delegate method from which i can separate message and show like chat , right now my msgs are showing like this

My Screen looks like this

the second problem is , I want my msgs on the right side but its appearing on the left side of the screen

My Firebase Schema for Chat

schema

will be very really thankful if someone could guide me

1

There are 1 best solutions below

1
On BEST ANSWER

You just need to implement

    func currentSender() -> SenderType

in your MessagesDataSource to return a struct or class that conforms to SenderType with some ID that identifies the sender in your backend. In your MessageType object, you also need to store the current sender of that message as your SenderType object. (I'm guessing the sender variable on your Firebase message schema would work for that?)

MessageKit will take care of laying out your cells on the correct side based on the senderId of message.sender vs currentSender(), you don't need to do anything explicit other than ensuring the Sender object has the correct senderId for each message, and return the current sender in your MessagesDataSource.