Hi everyone.
In this video I will show you how we can inject the message gateway and when we send a message, I want
it real, real time, right?
So how to do that?
Let's think a little bit.
So the question right now is how we can inject the gateway.
It's very easy.
The gateway right here is just a class for a reason.
We can inject class like usual.
Class.
And right now how we can send the message okay.
If you remember, if you see the normal socket we will use something like this I will not admit.
Right.
We will possibly new message event and we will put the data right.
So right now in order to use that we need to use the gateway.
This dot gateway dot right here we can delegate that job into the gateway.
It means right here we should create a method for same message.
Okay.
Actually right here I will call the.
Handle new message like this.
Okay.
And right here we need to give the this Does.
Not emit.
We emit from the server to the client.
Right.
So when when the client creates the new message.
But on send we need to send in here right.
New message with the data.
All right.
But the question right now is how we can do that.
Now if you remember I will show you.
Right here I will call handle new message.
And we need to put the sound argument right.
We already had an event name.
It Meanwhile, here we should have our data.
I will call this will be added right now.
And I will send the data.
Okay.
So what is the data?
We want to watch it over here.
Well let's take a little bit when we send a message okay.
And when we get own message.
Now you can say if I get own message you will say this is the object, right?
I want to somehow.
Send the message right here okay.
I want this is the data.
I want to put that over here.
Okay.
I want the data over here.
Will be somehow we need to convert it.
Now you will say this is the message we need to save into the database, right?
And from this same message, I want to somehow convert it into a data structure.
Okay.
It will retain and send it to client in real time.
Right.
So the question right now is how we can convert it.
If we remember.
In the read on message we already have something called Jotform DTO.
And we have a response message video.
Right.
Well, with the interceptor for the transform video, it only converts the return statement right here
into the video.
Okay.
Right now I want it to somehow, somehow convert.
The submitted into the response message video.
Okay, that's what I want, right?
Right now.
How we can convert us.
That's the question, right?
Right now.
Right now we have a save versus I will show you how we can do that in here.
We can populate, if you remember, in the get all message we already populated with sender and symbol
right.
We need to populate that also.
Let me put this over here.
Okay.
I will populate that.
And uh right now we have some row.
Actually I will remove over here.
I will remove it.
Highly populated.
In here.
I will call the.
Respond method or something like that and I will convert.
Well the first way we can manually convert it by hand, but I'm not a fan of this way.
So for that reason we can use the plan to install.
Okay.
With this thing we can put the response.
Ratio.
And we would object to save message over here.
Right.
Right here we have a save method I will populate that.
I will verbalize this here.
Let me copy this.
And I will boost over here For one hour each will mobilize the state.
And the second one, we will popularize this state also.
Okay.
And after that we will put the same message into the video over here.
Right.
And the last one will be, uh, if you open the channel from video, you will see we have one more options
right here.
Right.
I will copy that and put over here.
Okay.
Right here.
Um, actually, because this this can be.
Well.
This thing can be, uh.
All right.
Let me say that another way.
Right here.
I think I can vary it to the save the message.
Okay.
Are you going to write this dot message model dot file binary.
And I remove the save message dot over here.
Okay.
And move that over here.
Right here.
This can be known, but actually we don't need to check that because if we already create it right here
we will for sure have a would I die?
And right here I will put the first one over here.
Right.
And it will formulate a response message with your.
Let me over here and put inside the data.
And right now how we can test that would finally we cannot test that in the most main or the some tool
over here.
Okay.
But we can test that using the console over here.
We will call check data from.
Uh check data from okay.
I will call it as over here.
Now you can say if I send this message.
Follow is not have an error.
And if you hover in here now you can see it already converts fully the sender.
The sender name and sender avatar right here will be new.
I don't know why.
Let me try to.
It means right here.
We have the error.
Let me say.
Users.
We have avatar.
We have a bit of a wrong or.
I don't know the reason.
Because I forgot about you guys.
Okay, let me copy the populis and put us over here.
Put us.
Okay.
And right now, it should work.
Now you guys are right here.
We already have a sender name, sender avatar.
And we also have a sim.
Right.
And the media file right here.
Hmm.
It's already empty.
Why?
Like us?
Media file.
Let me double check over here.
Here.
I send a little bit.
Right here.
We don't have any media file right inside the body.
Right here.
Um, it means we already have something went wrong inside the.
My --.
My -- over here.
Let me try to console.log.
Or actually let me try to check the database to say we have a media file or not right here.
Actually, we already have media files, but it's not return, it means inside a wristband message model.
This array will.
All right here verify all.
So I forgot I completely forgot to put the media file over here.
Right.
So let me, uh, show you how we can do that right here.
So this is Bob, and I will show you what is inside media file.
Okay?
Now.
Let's focus right here.
I will go back to the guest and remove the console.log.
If I said okay.
Now you will say we already have a right with the object.
We need to map it and return exactly the same up here.
Right.
In here I will call object.
Files.
And will map.
Will file okay.
With the file right here.
I can copy it in and put it over here.
Right here I will replace everything into.
The box.
By.
Okay, something like that.
And let me see if I say now you will say in here, we already got the media file with this here.
Very good.
Right.
And so this is why let me open the console over here.
And let's see again I will send a message and say now let's check.
We already have a media file for record okay.
And we also have some, uh, exactly the same structure okay.
It means right now when we call Cloned API to send a message after we already send a message successfully.
We will handle that.
Okay.
We will delegate that job into the message gateway and message gateway it will send.
It will emit a new event right?
For with the new message event here with the data.
But we haven't completed the same message yet because the message should belong to the conversation.
Okay.
It means we we need to use the room concept.
Okay.
If you remember inside the socket I already introduced for use the room.
Okay.
We should create a room over here.
It means right here.
We should do some how to and convert session.
Right?
We need to put a conversation ID over here.
Yeah.
Let me ask.
Is that a conversation?
I would.
Hope that the message of it over here, what's in the conversation.
And we can use that directly over here.
Conversation.
Okay.
We will only send the message belong to the conversation.
Okay.
Very, very cool.
And of course, in the front end, we also have a event for Joy's room right now, for example, is
the client I will say socket dot emit sorry room with the conversation ID over here.
Right.
So.
It means this is the new event come from the foreign foreign region.
We should use the supply method.
Let me show you how it works.
So here I will copy the name over here.
So room and handle.
Sorry.
Room.
Okay.
Or actually I think I will call handle on conversation to be better.
Okay.
Something like that.
And right here we should have a data.
Right.
So we need to handle over here when the client sends emit the event over here.
What we need to do we need to Xyrem.
Right.
It means right here we should give you the client.
Client?
Not.
With a conversation.
But here I will call the conversation.
And I will save over here.
Okay.
With this line of code, we will design a room.
And right here.
This is the promise is a promise I can I can avoid over here.
See?
Okay, so I hope you understand.
Right.
And right now, let me give you one more idea when we work with Fortnite application.
Furthermore, it later we have an ACL for same message, right.
Same message with the some conversation with some data over here.
Right?
Well.
After we send the message, we will receive the handle.
New message over here come from there.
But in the end, the socket server, it will send the data right here for me.
And we will receive that immediately on the front end.
Right.
We already know about us, but how we can how we can send a message.
Okay.
Right now, whenever we click okay, whenever we click into the conversation.
Let me show you what it means.
Maybe you can do something like that.
Let me find the image for the messengers.
For example, in here.
No.
Okay.
It's similar right here.
When we get into the conversation, we will emit a metadata event.
Okay.
We will emit the event from the client.
Okay.
Make sure we emit the event right here from the client revision control session.
Okay.
And after that, this client right here will be inserted into the conversation.
And we can easily send a message using this API.
All right.
So that's the idea.
And so I hope you understand this video.
So I will see you in the next.