Everyone will come back.
Johnny be here with those slopes and dot com.
And this is an exciting lesson because this is our final real lesson.
We're going to continue developing features.
All right.
So we have with up till this point a practically fully functioning chat app you guys have done so much.
So proud of you all.
Hope you guys have enjoyed it had fun.
So yeah let's let's finish up.
So what we're going to do this lesson is we're going to make it to where we can have some visual indication
we can know if someone has sent a chat message in one of the other channels that we are not currently
in.
All right.
So to do that we're going to have to do a little refactor.
All right.
Over in our sockets service does Swift I realized that there would be some value in passing the new
message as in the closure to this mess in this function because then what we can do is.
So this is just a reminder what this function is doing this is listening for any new message being sent
to the API that gets sent back to us.
And so what we were doing before was we were checking here whether or not the new message channel matched
up with the selected channel.
But I think we want to be able to do that check inside of each controller because what we're going to
do is here in the channel VCT all we're gonna do is we're going to also set up the listener for new
messages.
So and what we're going to do with that is if a new message comes in that is not part of that is not
the selected channel.
Well we're going to do is we're going to add that channel to an array of unread channels and then we're
going to update our channels rose accordingly.
OK.
So let's go ahead and do that retractor real quick.
Back here in our Succot service not swift.
We're going to do is we're actually just going to pull out this new message right here and we're going
to create the new message out here.
And then this is all going to go away.
Cut that.
So now what do we have.
Well we have a new message object and no way of getting that to where we have called this message.
That is with a hard current completion handler with our closure.
So what we're going to do is we're going to do something similar like we did with our get typing users
function.
We're going to pass in our closure instead of just a simple true false Boolean.
We are going to pass this new message as an object in our closure.
All right.
So instead of this completion handload what we are going to do is we are going to say underscore a new
message and that is going to be of type message and we are returning from void.
OK so now when we call this function as part of the closure as part of the completion we can say completion
and now we are expecting a message so we can say new message.
All right.
Perfect.
And then we need to fix our chat visi.
Here we go.
So this is the one that is wrong.
So I'm going to comment that just for reference.
And when I say socket socket service the instance that get chat message and this time our closure gives
us a whoops.
This time we're going to press enter this time or close it gives us a message.
OK.
And we're going to what are we going to do with that.
Well we're going to check that new message.
I'm going to actually I'm going to name this new message.
New Message.
We're going to check our new message and pretty much we're going to do the same thing the same checks
that we were doing in the previous version of this socket function.
So we're going to say if new message got Channel I.D. is equal to our selected channel.
So a message service instance that selected channel dot ID and the Author Services logged in and we're
logged in all the service time and that is logged in.
So if all of that is true then we are going to append to that new message into same message service
that instance
dot messages dot append and the new element that we are pending is our new message.
As we go.
And then we're going to say self-doubt reload our scale self-taught table you dot reload data and then
we're going to do our scroll down to the bottom.
So we're in a say if Message Service and start messages that count is greater than zero.
Let's go ahead and let the end index.
We've got to create our index path again to index path.
And that's going to be initialized with a row and a section the row is message service that instance
that messages count as 1 and the section is zero.
So then we you're going to scroll to that Roser and say self-taught table view does scroll to grow at
the index path which is the end index at DOT bottom and I'm kind of going through this quickly because
we've already done this exact same thing before.
And the enemy it is false.
All righty.
So there we go there's a refactor everything.
Will she continue to work exactly as it was.
But now what we have done with this socket service is we've allowed to be able to access the new message
whether or not the message is coming from a channel that we have currently selected.
So what that allows us to do is over here and channel Visi his we're going to listen for four new messages
here as well.
But here we're more interested in the messages that come from channels that we do not have currently
selected.
All right.
That's going to say socket service that instance that get Chetna message.
Yes.
And the object that is passed in the closure is a message and we'll call this new message in our code.
All right so here we're going to say if the new message that channel ID does not equal our message service
instance does selected channel that ID if that's the case and we are logged in service for instance
that is logged in.
So if those two are the case then we know that we have a channel that has some unread message inside
of it.
And so what we're going to do is we're going to create an array of strings here in our message service
that represents the unread channels.
And so we're going to call this a re unread channels.
And this is just going to be a ray of strings we're going to initialize it.
And what we're going to put in here are the unread channels IDs.
OK.
So back to our channel Visi and we can say so if the new message that channel ID does not equal the
selected channel then what we're going to do is we're going to say Message Service for instance that
unread.
I think I need to say this over here.
Let's say you've put strings and that's why it needs to be just as strong as Wonder or why those stay
like that.
All right.
So then back to channel AVC unread channels.
That's a pen.
And so we're going to append into this array of strings that is going to contain our channel to use
and we're just going to say a new message channel ID.
All right.
And then we're going to say self-taught table view dot her reload data because with this array of strings
that are unread channel IDs all we can do is here in our channel.
So where you get under view channel sell we can do a check when we configure our cell whether or not
this channel is non-red channel and if it is then we're going to make the font bold and larger.
So let's go ahead and do that first we're going to set our regular default font server and say channel
name dot font is equal to you I font.
And that's going to be the name of our default font is hell.
That new dash for regular size is 17.
And so that's the that's the default.
And then we're going to say no we're going to loop through the the unread channel Id use and compare
it to our channel ID that is passed into this configure function.
And if it if it matches if any of them match then we know that that's an unread channel so we are going
to change the font to to a bold and bump up the font size here.
So when I say for Heidi in message service instance dot unroot channels if the ID in the message service
unroot channels is the same as this current channel ID then we're going to say channel name dot font
is equal to UI font and we can change it by changing the name of the font here.
And so this is going to be now a whoa that Tica new dash Bowl.
And then our size we're going to bump it up to say 22 maybe kind of we're going to save that
and I think when we make sure these are still the Vertica Helvetica I think that looks good looks good
save this and let's run it.
All right.
So going to open this up here and I'm going to open up our Mac chat app over here and I'm currently
in general right.
So I'm going to go into a random and say random ness I'm going to send it.
And if all goes according to plan this guy here should suddenly get large and bold Oh wait he naives
I'm going to go into sloop's and just send some jibberish boom those slips gets big.
All right so cool.
But now when we go into here we need a way to make it so that these go back to their normal size.
Right.
Meaning that we've entered it.
We've seen the unread messages and now just go back to regular.
All right so let's go ahead and jump back into our channel Visi because what we're going to do is we're
going to handle that when one of these are selected and that's handled down here in our Did select function.
So what we're going to need to do is we're going to need to do a check to first we're going to check
to see if there are any unread channels.
I'm just we're not doing unnecessary work so we're going to say if Message Service start instance dot
unread channels that count is greater than zero.
So if there are some unread channels then we are going to we're going to filter.
All right so we know we've selected a channel.
And so what we're going to do is we're going to filter out of the unread channels of this channel.
All right.
And that will leave all of the channels except for the one that we just clicked on with the same message
sort of instance that hundred channels is equal to its self message service for instance.
Lipsey instance not unread channels but now we're going to filter's we're actually dot filter
and we're going to do curly brace and then the dollar sign and zero say where that is not equal to channel
ID.
OK.
So basically we're saying the Annora channels are raise equal to itself but we are filtering out the
the him where is equal to this channels ID.
OK.
And then what we need to do is we need to reload that row so that the configure cell is called again
and it'll reset the font size.
But one issue with that is it when we do that it resets the set selected for some reason that will go
away.
So what we're going to do also is we're going to reload that Roe and then we're going to select that
row afterwards.
But to do that we need an index path of variables for let's create that pregnancy index equal to index
path and the index path we're going to create that from right here row and section the row is index
path that row the section is zero since we only have one and then we're going to see Table View.
Reload.
Reload rows hacked and the index path that we are reloading had is index with row animation.
We don't really moments for anything none.
And then we're going to select that road.
So selecting it and and this select is a little bit different.
So you don't have to worry it's not going to like to do a double select sort of say Table View dot select
row at the index path that we are looking at is index animated is false and the scroll position is that
none of us all right.
So just to run through this again when we click on a row if it's one that we've selected then it's going
to go through this check right here we're going to see if there are some hundreds if there are there
we're going to filter out the one that we just clicked on and then we're going to reload it which will
then reload that row and now it's not a unread channels so it won't be big.
And then we're going to re select it so that we have our set selected feed on it.
All right let's try this again.
I'm going to run it.
I'm going to open up our channels open up my Mac
and let's go in random since jibberish pops up Succot are bomb.
All right.
So let's see if this works.
When I click on random and it looks like it did go back to normal I went back to normal and went back
to normal.
All right the piece we are on.
This is this has been a huge huge gap.
I think we've been going on something like eight or nine 10 hours.
So I want to thank you for hanging out with me and coding along and I hope you have learned a lot.
You know reach out to us in the chat rooms let us know how you how you've been enjoying the course.
And yeah this is the last the last big video.
The next lesson we're just going to talk about where you can go from here.
I'm going to give you a little bit of homework to get you guys thinking on your own and trying to implement
some little features.
All right.
But yeah I really hope you guys have had fun.
We've learned so much we've learned about collection views table views dynamic sizing of cells sockets
web connections API eyes.
I mean just just just a whole ton and you got yourself here a real nice looking app with a nice slide
menu.
So yeah I mean I hope you guys really really like what you have created.
And yeah I'll see you in the next little lesson where I'm going to give you some homework.
All right.
So up until then I'm just going to add and commit as you guys should also be doing.
And I'll see you in the next one.