So hi everyone.
In this video I will show you how we can create one more method.
Okay, for the app participants into the group chat okay into the conversation group.
Okay, so let me show you how we can do that.
Let's create the app okay.
See one.
Method over here okay.
And now what we need firstly we need a the conversation ID right.
We need a conversation ID and we need the current user.
And we need the.
ID we want to add, right?
Right here, instead of moving directly over here, we can create the new.
Than the data.
Let me show you right here.
I will create at least one.
Of the S class are visible.
Right here.
Okay.
Right here.
We need to put the participant array over here.
Right.
And let's add a little bit of validation.
Okay.
And right here with the art practice ribbon.
Okay.
Firstly we need to find the conversation.
What we have right now.
Before anybody with the idea over here.
And we need to check if.
We're not part of the conversation or conversation is is not over.
Okay.
It will not follow conversation.
Or if the conversation is, uh, is not a verb I will throw.
Nail not file exception.
Sorry.
Okay.
The reason In order to add a participant, we only allow add participants into the group chat.
Okay, so if this is not a group, we will draw the arrow.
And right here we need to add a little bit of code over here.
Let me list just three.
But this is what okay.
This is the participant we want to to add right.
We want to add into the group chat.
So.
What we need to do.
Is add a conversation.
We have a participants right.
We have one right now.
We can add that.
We can put Booth does over here with the conversation part one and the new part one, and we need to
remove the duplicate also.
Okay.
With this approach we have a little TypeScript problem.
Um.
Uh, so for that reason, let me, uh, try to fix us instead of this one.
This is the ID, okay?
This is the structuring of ID, so we need to somehow find the participant and convert it into the user
document and put that over here.
Right here will be participant.
Okay.
I will call this either a right.
Anyway.
And I will look through the participant array.
Again and I will find the user.
So in this case we need to inject the user service over here.
And it does insert a module.
After that let's go back.
Use are equal.
Please do not use a service dot file one with a participant array over here.
Okay.
With here.
We have a user.
Right.
And right here we can put that into the one user over here.
Okay.
Right here we need to add.
The user document.
All right.
Let us.
And that is right.
Right here let me uncomment And we will use the participant over here.
And this already fixed the issue.
And we need one more.
One more thing.
We need to remove the duplicate right.
We need to remove duplicate.
So how do we do that.
So.
With this approach it will duplicate for sure.
For example with the conversation number 31.
It can be a b and C.
Okay.
What about this participant over here is under C and d okay.
It means it will somehow merge into this thing will be a, b, c and c and d Okay.
Okay.
This man right here will be duplicate for sure.
Right.
So we need to add a little bit of jack over here.
Let me separate thing into the another variable.
We will call the existing existing participant.
Class.
Okay.
And in here we will check that if the existing participant dot include.
The.
But this one had a uh.
Right here we will user whom we cannot compare to object.
So for a reason with this guy, we need to map it into the object.
Also, I will call this here will be practicing one practice 1.10.2.
Okay.
And I will call existing participants.
It is something like that.
And now here we need to check if exit participant ID is right here.
In close.
If it not close we will boost that into here.
Okay.
So with this approach it will for sure not duplicate because we already checked over here right.
If the participant right here.
Is already inside exiting a knot inside the exiting we will boost that.
Okay so arrow here we have a current user.
We need to check only the owner can.
Add the participant okay.
Okay.
If the current user is not group owner we will route No problem, etc..
Linus.
Now let's try this.
Okay, let me create a controller first.
I will still use the match method and add the segments.
Okay, now let's take a look at document.
Uh.
In order to add member to chat group, we will use conversation ID and class members.
Right.
Something like that.
And we did the other day and released the update.
Now we need that up a little.
Over here.
Let's save it as.
We have an error over here.
Let me change.
The current user will be the last argument.
So let's take that.
Let me duplicate.
And I will call up members to convert session.
We did conversation today and we need are members.
Okay.
And right now we are in with the owner account.
Here.
And we need to add the participle.
Now let's say what is here.
Now let me file split ID inside MongoDB.
So say.
Conversations.
This data here will be one, two, three.
Here we already have a three partition one right.
Right.
Now if I add exactly the same to say it duplicate or not.
Okay.
Now let me say.
Its value in this.
Again I already a little bit raw.
No.
Let me generate a little bit.
I already incorrect placement.
It is okay.
These are the service.
Let's fix that.
And right here let me fix that also.
Now let me say.
The message will be success.
Now let's check the database.
From here it not duplicate at all.
Right.
Now if I remove the last one, we will a nine.
Okay, let me move.
Uh, we have some error.
Let me, uh, refresh.
Remove eight.
Nine.
Hmm.
We have some error right now.
I don't know why.
Maybe.
Maybe I will add into this group.
Okay, I will add into this group.
And I will add a member.
Okay.
Right now you can say we only have three members inside here, right?
I will add with three member.
Also, I expect it will add only one member because we already had a duplicate right now, right.
Finite and zero f finite one here and zero f okay I want to add all these 43189 over here.
Let's say.
Inside the conversation of five.
Billion.
Conversation of five.
Why?
Are there isn't because.
This is the AC waveform.
Okay.
We cannot do that.
Let me try to remove this one.
Okay.
I can update this here.
Let me copy and boost over here.
Instead.
Success.
Let me refresh.
I only will have a three in here.
Roger is.
Still are.
You still here?
Hmm.
Let's see.
Let me check a little bit.
Let me try to console.log.
Say.
We already have here.
Right.
And let me console.log the exiting.
Okay.
So.
And we say.
Okay, we have here.
Here.
It already worked.
But why?
Let me try to console.
Up over here.
Oh.
Another reason.
The reason I forgot to say.
Into the database.
Okay.
Conversation side.
Okay.
My bad.
Now let me say.
And let's check the data wise.
Here we already have a three.
Okay.
And even if I send one more time, it's still free.
Okay.
It means the logic right here already work.
And we have so many mistake over here because.
I want to sleep.
So that is.
I hope you understand this video and I will see you in.