Hey everyone!
In previous video, we already created a private conversation for 1 to 1 chats.
Okay, in this video, let's create another method for creating group conversation.
Okay, so let's build us.
We need here a current user.
And let's see how we can build us.
If you take a look.
If you take a look at this create private.
We need to check the existing conversation.
And if we already have an existing we will return that.
So how about create group.
Well in the group create group conversation We don't need any object over here.
Let me show you why.
Well, the reason is very simple.
We will allow the user can create multiple groups with same frames.
Okay, let me show you what I mean.
Furthermore, it later we can have a multiple group for example like food group.
Okay.
If the food group we have A, B and C and in later we can create a relaxed group.
We will also have a, B and C and this will be completely normal okay.
We can allow the user can create that right.
So for that reason we don't need to check in here.
The existing conversation only work for chart with the one frame okay.
What is that a totally different story.
So for a reason we don't need to check anything over here.
Now let's continue with a little.
Let me check create group conversation video and let me go back over here.
Change the name.
And chain over here.
Okay.
What you saw a little.
Let me show you.
On a ski mask, you can say firstly, we did this once, right?
Right here we did participant IDs of the sprint.
Right over here.
Okay.
And, uh.
Let me show you what it means.
It creates private conversation.
We only put the one participant at a time.
Reason?
Because this is a 1 to 1 chat.
Okay.
We only chat with one frame at a time.
So we only need one participant.
But with the group, we need to boost the real participants, right?
Because we can create the group with multiple members inside us, right?
Let me show you how it works.
And right here.
And right here let's chat a little bit about arrays and the array over here.
Okay.
And It might be in future.
We can boost so many.
All right.
Right here.
If you want.
We need to add a little bit of validations.
So this is the right.
Right.
And uh we need to make sure.
And the element inside the string array here should be a MongoDB object.
And we call this array we cannot check like that okay.
We cannot do directly the mongo ID.
This only work with this is the normal string.
But since this is the uh right we can boost the option which we will choose.
Okay.
We feel it will look through the element inside the array over here and jack with every element.
It will make sure this is the mongo ID, so very good.
And let me show you this.
Here we run this.
We run this here.
So we need the avatar and group name.
So for that reason go back to the DTO and move that over here.
The avatar can be either media.
Hi sorry we are tile over here.
And group name will be straight okay.
With the avatar this can be optional.
Sorry.
The optional and width is group name I will add is not contained.
Okay, maybe you don't want to put the group name.
Okay.
You can use the the file or something like that, but I did replace I will create the group name when
we create the group chart.
Okay.
So after that uh, let's try it.
Let me copy this lab code and put that inside a group.
Right here.
Let me destructuring.
Okay.
So here let me add this.
And because this is the array.
So we need to, uh, use the separate operator over here.
And after that is here should be true.
Right.
And we have a group name and group avatar and group owner.
What is the group owner?
Group owner should be the current user, right?
And over here.
So I hope you understand this logic.
Now let me go to the controllers and I will remove the boss method over here.
Let me duplicate this.
Group.
Now let's change the method.
Okay.
Like this.
And let's remove the news import over here.
And we have the error.
Uh, come from here.
Let me click.
Um, well, it's a lot of ground up that little.
Let me remove the stain.
Remove here.
Okay.
And, uh, let's say.
We have the error come from the service.
Okay.
Let's remove the news import.
And let's say.
Right now, the application already successfully.
Let me go to here and I will go to the users and copy one more participant.
It is the Thomas Adi.
Buddha design here.
And the group name.
Can be.
For example, I put zero.
For example, let us and let's say we have.
Okay.
We only need this one.
We don't need the avatar right now.
Let me say okay.
Very good.
We already created our group and this already have a participant.
This is the current user already logged in.
Okay.
And also this one.
Right.
And we already have our own participants.
Very very cool.
And let me create one more group with the group avatar.
So let me show you how it works in the group avatar result object.
Right.
Let me create a crowded array.
Let me try to upload the file.
Let me show some file.
Say.
And.
Go down over here.
Okay, let me try to set that with the, uh, food group.
I will create a resource group with the same participant.
Let me say, okay.
We already got the group avatar.
Let me check the database.
Now, we already got the new one.
Food group and resource group with the avatar over here.
Okay, so that's for the video.
I hope you understand the logic right here.
It doesn't complicated at all, right?
So I will see you in the.