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 where 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.
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 and 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 it
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 or we're going to do is we're going to also set up the listener for new
messages.
So 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 Reflektor real quick.
Back here in our Succot service not swift.
Well 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 a 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 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 handling 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 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.
We can say new message.
All right.
Perfect.
And then we need to fix our chat we see here we are.
So this is the one that is wrong.
So I'm going to comment that out just for reference.
And when I say socket socket service the instance that get chat message.
And this time our closure gives us a pause.
This time I'm 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 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 dot channel ID is equal to our selected channel ID so a message
service type instance dot selected channel dot ID and the Author Services logged in and were logged
in health service by instance that is logged in.
So if all of that is true then we are going to append to that new message 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 sales self-taught table dot reload data and then we're
going to do our scroll down to the bottom.
So we're going to say if Message Service stopped and start messages that count is greater than zero.
Let's go ahead and let the and 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 minus 1 and the section is zero.
OK so then where 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 animated is false.
All righty.
So there we go there's a refactor.
Everything will 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 that 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.
We're going to say socket service dot 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 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 to the sea 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 string.
I was wondering why that would stay like that.
All right.
So then back to channel Visi unread channels not 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 see 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 what we can do is here in our channel cell where you get under view channel
so all we can do is check when we configure our cell whether or not this channel is an unread 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 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 a 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 has passed into this configure function and if it matches if any of them match
then we know that it'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 you say for ID in message service instance dot unread 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 hoe that Tica new dash Bowl.
And then our size we're going to bump it up to say 22 maybe we're going to save that.
And I think when we make sure these are still the whole Buddika Helvetica I think that looks good.
Tillich's Good to see this.
And let's run it.
All right.
So you can 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 want to send it.
And if all goes according to plan this guy here should suddenly get large and bold.
Maybe he's going to go into debt slopes and just send some jibberish boom 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 ABC 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 too.
First we're going to check to see if there are any unread channels.
Just we're not doing unnecessary work.
We're going to see if Message Service instance dot unread channels 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.
That's right and 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 and say where that is not equal
to what channel ID.
OK so basically we're saying the Annora channels are raise equal to itself but we are filtering out
the the item 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 when we do that it resets the set selected for some reason that will go away.
So what we're going to do it's also we're going to reload that row 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 and to say let 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 dot row.
The section is zero since we only have one and I'm going to say table view to reload
reload rows half and the index path that we are reloading is index with row on a mission.
We don't really Momence forensic none.
And then we're going to re select that Roe V.
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 swing say Table View dot select
grow at the index path that we're looking at is index animated is false and the scroll position is that
none of.
All right.
So just to run through this again when we click on a row if it's one that we selected then it's going
to go through this check right here we're going to see if there are some other threads 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 channel so it won't be big.
And then we're going to re select it so that we have our set selected fade 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 the gibberish that 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 peeps we are done.
This is this has been a huge huge app.
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.