1
00:00:08,130 --> 00:00:09,240
Everyone will come back.

2
00:00:09,240 --> 00:00:11,680
Johnny be here with those slopes and dot com.

3
00:00:11,790 --> 00:00:18,480
And this is an exciting lesson because this is our final real lesson where we're going to continue developing

4
00:00:18,480 --> 00:00:19,110
features.

5
00:00:19,110 --> 00:00:19,670
All right.

6
00:00:19,860 --> 00:00:25,560
So we have with up till this point a practically fully functioning chat app.

7
00:00:25,710 --> 00:00:27,480
You guys have done so much.

8
00:00:27,480 --> 00:00:28,710
So proud of you all.

9
00:00:28,760 --> 00:00:31,700
Hope you guys have enjoyed it had fun.

10
00:00:31,770 --> 00:00:33,640
So yeah let's let's finish up.

11
00:00:33,690 --> 00:00:34,580
What we're going to do.

12
00:00:34,590 --> 00:00:43,020
This lesson is we're going to make it to where we can have some visual indication we can know if someone

13
00:00:43,020 --> 00:00:48,790
has sent a chat message and one of the other channels that we are not currently in.

14
00:00:48,930 --> 00:00:49,430
All right.

15
00:00:49,830 --> 00:00:52,970
So to do that we're going to have to do a little refactor.

16
00:00:52,970 --> 00:01:02,130
All right over in our sockets service does Swift I realized that there would be some value in passing

17
00:01:02,130 --> 00:01:10,630
the new message as in the closure to this mess in this function because then what we can do is so it

18
00:01:10,740 --> 00:01:17,130
is just a reminder what this function is doing this is listening for any new message being sent to the

19
00:01:17,130 --> 00:01:19,120
API that gets sent back to us.

20
00:01:19,340 --> 00:01:25,830
And so what we were doing before was we were checking here whether or not the new message channel matched

21
00:01:25,830 --> 00:01:27,950
up with the selected channel.

22
00:01:27,960 --> 00:01:32,220
But I think we want to be able to do that check inside of each controller because what we're going to

23
00:01:32,220 --> 00:01:39,030
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

24
00:01:39,030 --> 00:01:40,010
messages.

25
00:01:40,020 --> 00:01:46,500
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

26
00:01:46,620 --> 00:01:47,960
selected channel.

27
00:01:48,090 --> 00:01:55,080
Well we're going to do is we're going to add that channel to an array of unread channels and then we're

28
00:01:55,080 --> 00:01:58,430
going to update our channels rose accordingly.

29
00:01:58,620 --> 00:01:59,150
OK.

30
00:01:59,400 --> 00:02:02,460
So let's go ahead and do that Reflektor real quick.

31
00:02:02,790 --> 00:02:06,560
Back here in our Succot service not swift.

32
00:02:06,790 --> 00:02:13,560
Well we're going to do is we're actually just going to pull out this new message right here and we're

33
00:02:13,560 --> 00:02:16,160
going to create a new message out here.

34
00:02:16,530 --> 00:02:21,230
And then this is all going to go away.

35
00:02:22,020 --> 00:02:23,600
Cut that.

36
00:02:23,640 --> 00:02:25,010
So now what do we have.

37
00:02:25,050 --> 00:02:32,790
Well we have a new message object and no way of getting that to where we have called this message.

38
00:02:32,790 --> 00:02:36,350
That is with a hard current completion handler with our closure.

39
00:02:36,780 --> 00:02:40,280
So we're going to do is we're going to do something similar like we did with our get typing.

40
00:02:40,270 --> 00:02:47,730
Users function we're going to pass in our closure instead of just a simple true false Boolean.

41
00:02:47,760 --> 00:02:51,240
We are going to pass this new message as an object in our closure.

42
00:02:51,240 --> 00:02:51,620
All right.

43
00:02:51,720 --> 00:02:58,830
So instead of this completion handling what we are going to do is we are going to say underscore a new

44
00:02:59,130 --> 00:03:07,270
message and that is going to be of type message and we are returning void.

45
00:03:07,740 --> 00:03:18,030
OK so now when we call this function as part of the closure as part of the completion we can say completion

46
00:03:18,900 --> 00:03:20,920
and now we are expecting a message.

47
00:03:20,940 --> 00:03:23,110
We can say new message.

48
00:03:23,520 --> 00:03:23,840
All right.

49
00:03:23,840 --> 00:03:24,790
Perfect.

50
00:03:25,200 --> 00:03:29,640
And then we need to fix our chat we see here we are.

51
00:03:29,880 --> 00:03:32,300
So this is the one that is wrong.

52
00:03:32,940 --> 00:03:35,030
So I'm going to comment that out just for reference.

53
00:03:35,040 --> 00:03:43,190
And when I say socket socket service the instance that get chat message.

54
00:03:43,200 --> 00:03:47,340
And this time our closure gives us a pause.

55
00:03:47,700 --> 00:03:50,850
This time I'm going to press enter this time or close it gives us a message.

56
00:03:51,090 --> 00:03:51,610
OK.

57
00:03:52,050 --> 00:03:54,580
And we're going to what are we going to do with that.

58
00:03:54,600 --> 00:03:57,180
Well we're going to check that new message.

59
00:03:57,180 --> 00:04:00,950
I'm going actually I'm going to name this new message new message.

60
00:04:01,290 --> 00:04:05,490
We're going to check our new message and pretty much we're going to do the same thing the same checks

61
00:04:05,490 --> 00:04:10,310
that we were doing in the previous version of this socket function.

62
00:04:10,320 --> 00:04:20,850
So we're going to say if new message dot channel ID is equal to our selected channel ID so a message

63
00:04:20,850 --> 00:04:30,090
service type instance dot selected channel dot ID and the Author Services logged in and were logged

64
00:04:30,090 --> 00:04:33,910
in health service by instance that is logged in.

65
00:04:33,990 --> 00:04:39,500
So if all of that is true then we are going to append to that new message same message service that

66
00:04:39,720 --> 00:04:40,550
instance

67
00:04:43,030 --> 00:04:52,710
dot messages dot append and the new element that we are pending is our new message as we go.

68
00:04:53,010 --> 00:05:04,110
And then we're going to say self-doubt reload our sales self-taught table dot reload data and then we're

69
00:05:04,110 --> 00:05:06,150
going to do our scroll down to the bottom.

70
00:05:06,150 --> 00:05:17,850
So we're going to say if Message Service stopped and start messages that count is greater than zero.

71
00:05:18,060 --> 00:05:22,790
Let's go ahead and let the and index.

72
00:05:22,800 --> 00:05:26,910
We've got to create our index path again to index path.

73
00:05:27,240 --> 00:05:37,410
And that's going to be initialized with a row and a section the row is message service that instance

74
00:05:37,800 --> 00:05:46,400
that messages count minus 1 and the section is zero.

75
00:05:46,890 --> 00:05:54,030
OK so then where you're going to scroll to that Roser and say self-taught table view does scroll to

76
00:05:54,030 --> 00:06:01,590
grow at the index path which is the end index at DOT bottom and I'm kind of going through this quickly

77
00:06:01,590 --> 00:06:08,320
because we've already done this exact same thing before and the animated is false.

78
00:06:08,320 --> 00:06:09,400
All righty.

79
00:06:09,570 --> 00:06:12,180
So there we go there's a refactor.

80
00:06:12,300 --> 00:06:15,900
Everything will continue to work exactly as it was.

81
00:06:16,170 --> 00:06:22,590
But now what we have done with this socket service is we've allowed to be able to access the new message

82
00:06:22,650 --> 00:06:29,130
whether or not that the message is coming from a channel that we have currently selected.

83
00:06:29,140 --> 00:06:37,590
So what that allows us to do is over here and channel Visi His We're going to listen for four new messages

84
00:06:37,590 --> 00:06:38,710
here as well.

85
00:06:39,000 --> 00:06:45,000
But here we're more interested in the messages that come from channels that we do not have currently

86
00:06:45,000 --> 00:06:45,570
selected.

87
00:06:45,570 --> 00:06:46,070
All right.

88
00:06:46,220 --> 00:06:52,730
We're going to say socket service dot instance that get Chetna message.

89
00:06:53,250 --> 00:06:53,830
Yes.

90
00:06:53,970 --> 00:07:03,810
And the object that is passed in the closure is a message and we'll call this new message in our code.

91
00:07:03,810 --> 00:07:14,380
All right so here we're going to say if the new message that channel ID does not equal our message service

92
00:07:14,800 --> 00:07:29,430
instance selected channel that ID if that's the case and we are logged in service for instance that

93
00:07:29,490 --> 00:07:31,530
is logged in.

94
00:07:31,530 --> 00:07:38,580
So if those two are the case then we know that we have a channel that has some unread message inside

95
00:07:38,580 --> 00:07:39,540
of it.

96
00:07:39,540 --> 00:07:46,620
And so what we're going to do is we're going to create an array of strings here in our message service

97
00:07:47,100 --> 00:07:50,340
that represents the unread channels.

98
00:07:50,340 --> 00:07:53,960
And so we're going to call this a re unread channels.

99
00:07:54,090 --> 00:07:59,350
And this is just going to be a ray of strings we're going to initialize it.

100
00:07:59,580 --> 00:08:03,140
And what we're going to put in here are the unread channels IDs.

101
00:08:03,210 --> 00:08:03,730
OK.

102
00:08:03,870 --> 00:08:10,200
So back to our channel to the sea and we can say so if the new message that channel ID does not equal

103
00:08:10,200 --> 00:08:16,470
the selected channel then what we're going to do is we're going to say Message Service for instance

104
00:08:16,530 --> 00:08:19,910
that unread.

105
00:08:20,100 --> 00:08:21,720
I think I need to say this over here.

106
00:08:22,010 --> 00:08:29,110
Let's say you've put strings and that's why it needs to be just string.

107
00:08:29,130 --> 00:08:31,050
I was wondering why that would stay like that.

108
00:08:31,060 --> 00:08:31,270
All right.

109
00:08:31,270 --> 00:08:36,940
So then back to channel Visi unread channels not a pen.

110
00:08:36,950 --> 00:08:43,180
And so we're going to append into this array of strings that is going to contain our channel to use

111
00:08:43,180 --> 00:08:47,800
and we're just going to see a new message channel ID.

112
00:08:47,860 --> 00:08:48,410
All right.

113
00:08:48,670 --> 00:08:57,580
And then we're going to say self-taught table view dot her reload data because with this array of strings

114
00:08:57,730 --> 00:09:07,360
that are unread channel IDs what we can do is here in our channel cell where you get under view channel

115
00:09:07,360 --> 00:09:15,790
so all we can do is check when we configure our cell whether or not this channel is an unread channel

116
00:09:16,030 --> 00:09:22,190
and if it is then we're going to make the font bold and larger.

117
00:09:22,330 --> 00:09:25,210
So let's go ahead and do that.

118
00:09:25,540 --> 00:09:34,530
First we're going to set our regular default font and say channel name dot font is equal to you.

119
00:09:34,530 --> 00:09:36,080
I font.

120
00:09:36,580 --> 00:09:43,790
And that's going to be the name of our default font is hell.

121
00:09:43,820 --> 00:09:51,880
That new dash a regular size is 17.

122
00:09:52,600 --> 00:09:55,050
And so that's the that's the default.

123
00:09:55,060 --> 00:10:01,780
And then we're going to say no we're going to loop through the the unread channel Id use and compare

124
00:10:01,780 --> 00:10:09,070
it to our channel ID that has passed into this configure function and if it matches if any of them match

125
00:10:09,340 --> 00:10:15,550
then we know that it's an unread channel so we are going to change the font to to a bold and bump up

126
00:10:15,550 --> 00:10:16,990
the font size here.

127
00:10:16,990 --> 00:10:30,150
So when you say for ID in message service instance dot unread channels if the ID in the message service

128
00:10:30,890 --> 00:10:41,520
unroot channels is the same as this current channel ID then we're going to say channel name dot font

129
00:10:42,360 --> 00:10:50,070
is equal to UI font and we can change it by changing the name of the font here.

130
00:10:50,620 --> 00:10:58,030
And so this is going to be now a hoe that Tica new dash Bowl.

131
00:10:58,260 --> 00:11:06,270
And then our size we're going to bump it up to say 22 maybe we're going to save that.

132
00:11:06,530 --> 00:11:12,590
And I think when we make sure these are still the whole Buddika Helvetica I think that looks good.

133
00:11:12,600 --> 00:11:14,610
Tillich's Good to see this.

134
00:11:14,870 --> 00:11:18,080
And let's run it.

135
00:11:18,110 --> 00:11:18,450
All right.

136
00:11:18,470 --> 00:11:29,600
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

137
00:11:29,600 --> 00:11:30,830
general right.

138
00:11:31,430 --> 00:11:36,220
So I'm going to go into a random and say random ness.

139
00:11:36,280 --> 00:11:36,970
I want to send it.

140
00:11:36,980 --> 00:11:43,410
And if all goes according to plan this guy here should suddenly get large and bold.

141
00:11:44,270 --> 00:11:53,810
Maybe he's going to go into debt slopes and just send some jibberish boom slips gets big.

142
00:11:54,030 --> 00:11:55,400
All right so cool.

143
00:11:55,820 --> 00:12:04,760
But now when we go into here we need a way to make it so that these go back to their normal size.

144
00:12:04,760 --> 00:12:05,170
Right.

145
00:12:05,360 --> 00:12:06,770
Meaning that we've entered it.

146
00:12:06,770 --> 00:12:10,340
We've seen the unread messages and now just go back to regular.

147
00:12:10,340 --> 00:12:16,970
All right so let's go ahead and jump back into our channel ABC because what we're going to do is we're

148
00:12:16,970 --> 00:12:24,520
going to handle that when one of these are selected and that's handled down here in our Did select function.

149
00:12:24,830 --> 00:12:30,500
So what we're going to need to do is we're going to need to do a check too.

150
00:12:30,560 --> 00:12:34,450
First we're going to check to see if there are any unread channels.

151
00:12:34,580 --> 00:12:36,710
Just we're not doing unnecessary work.

152
00:12:36,740 --> 00:12:44,790
We're going to see if Message Service instance dot unread channels count is greater than zero.

153
00:12:44,790 --> 00:12:50,870
So if there are some unread channels then we are going to we're going to filter.

154
00:12:50,870 --> 00:12:54,370
All right so we know we've selected a channel.

155
00:12:54,470 --> 00:12:59,450
And so what we're going to do is we're going to filter out of the unread channels of this channel.

156
00:12:59,450 --> 00:13:03,310
All right and that will leave all of the channels except for the one that we just clicked on.

157
00:13:03,340 --> 00:13:12,760
That's right and same message sort of instance that hundred channels is equal to its self message service

158
00:13:12,760 --> 00:13:14,120
for instance.

159
00:13:14,190 --> 00:13:21,290
Lipsey instance not unread channels but now we're going to filter's we're actually dot filter

160
00:13:24,580 --> 00:13:33,610
and we're going to do curly brace and then the dollar sign and zero and say where that is not equal

161
00:13:33,610 --> 00:13:37,420
to what channel ID.

162
00:13:37,760 --> 00:13:44,470
OK so basically we're saying the Annora channels are raise equal to itself but we are filtering out

163
00:13:45,980 --> 00:13:51,250
the the item where is equal to this channels ID.

164
00:13:51,350 --> 00:13:52,030
OK.

165
00:13:52,450 --> 00:14:03,370
And then what we need to do is we need to reload that row so that the configure cell is called again

166
00:14:03,430 --> 00:14:05,760
and it'll reset the font size.

167
00:14:06,100 --> 00:14:15,190
But one issue with that is when we do that it resets the set selected for some reason that will go away.

168
00:14:15,190 --> 00:14:19,330
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

169
00:14:19,330 --> 00:14:20,550
row afterwards.

170
00:14:20,820 --> 00:14:27,250
But to do that we need an index path of variables for let's create that and to say let index equal to

171
00:14:27,310 --> 00:14:35,520
index path and the index path we're going to create that from right here row and section.

172
00:14:35,560 --> 00:14:39,920
The row is index path dot row.

173
00:14:40,000 --> 00:14:49,630
The section is zero since we only have one and I'm going to say table view to reload

174
00:14:52,030 --> 00:15:03,070
reload rows half and the index path that we are reloading is index with row on a mission.

175
00:15:03,070 --> 00:15:05,200
We don't really Momence forensic none.

176
00:15:05,500 --> 00:15:09,080
And then we're going to re select that Roe V.

177
00:15:09,370 --> 00:15:13,950
So selecting it and and this select is a little bit different.

178
00:15:13,950 --> 00:15:22,560
So you don't have to worry it's not going to like to do a double select swing say Table View dot select

179
00:15:23,950 --> 00:15:31,900
grow at the index path that we're looking at is index animated is false and the scroll position is that

180
00:15:32,170 --> 00:15:35,750
none of.

181
00:15:36,300 --> 00:15:36,540
All right.

182
00:15:36,540 --> 00:15:44,310
So just to run through this again when we click on a row if it's one that we selected then it's going

183
00:15:44,310 --> 00:15:48,720
to go through this check right here we're going to see if there are some other threads if there are

184
00:15:48,980 --> 00:15:53,670
there we're going to filter out the one that we just clicked on and then we're going to reload it which

185
00:15:53,670 --> 00:15:59,210
will then reload that row and now it's not a unread channel so it won't be big.

186
00:15:59,430 --> 00:16:06,360
And then we're going to re select it so that we have our set selected fade on it.

187
00:16:06,360 --> 00:16:07,650
All right let's try this again.

188
00:16:07,650 --> 00:16:09,220
I'm going to run it.

189
00:16:09,830 --> 00:16:14,010
I'm going to open up our channels open up my Mac

190
00:16:16,600 --> 00:16:18,820
and let's go in.

191
00:16:18,970 --> 00:16:25,460
Random since the gibberish that pops up Succot are bomb.

192
00:16:25,600 --> 00:16:26,080
All right.

193
00:16:26,140 --> 00:16:27,730
So let's see if this works.

194
00:16:27,730 --> 00:16:34,810
When I click on random and it looks like it did go back to normal I went back to normal and went back

195
00:16:34,810 --> 00:16:35,680
to normal.

196
00:16:35,680 --> 00:16:37,420
All right peeps we are done.

197
00:16:37,480 --> 00:16:41,150
This is this has been a huge huge app.

198
00:16:41,350 --> 00:16:45,920
I think we've been going on something like eight or nine 10 hours.

199
00:16:47,440 --> 00:16:56,080
So I want to thank you for hanging out with me and coding along and I hope you have learned a lot.

200
00:16:56,080 --> 00:17:01,370
You know reach out to us in the chat rooms let us know how you how you've been enjoying the course.

201
00:17:01,370 --> 00:17:05,300
And yeah this is the last the last big video.

202
00:17:05,380 --> 00:17:08,200
The next lesson we're just going to talk about where you can go from here.

203
00:17:08,260 --> 00:17:13,600
I'm going to give you a little bit of homework to get you guys thinking on your own and trying to implement

204
00:17:14,170 --> 00:17:15,480
some little features.

205
00:17:15,790 --> 00:17:16,040
All right.

206
00:17:16,050 --> 00:17:17,980
But yeah I really hope you guys have had fun.

207
00:17:17,980 --> 00:17:26,080
We've learned so much we've learned about collection views table views dynamic sizing of cells sockets

208
00:17:26,350 --> 00:17:29,310
web connections API eyes.

209
00:17:29,500 --> 00:17:37,960
I mean just just just a whole ton and you got yourself here a real nice looking app with a nice slide

210
00:17:38,050 --> 00:17:38,950
menu.

211
00:17:39,220 --> 00:17:45,290
So yeah I mean I hope you guys really really like what you have created.

212
00:17:45,470 --> 00:17:49,750
And yeah I'll see you in the next little lesson where I'm going to give you some homework.

213
00:17:49,750 --> 00:17:50,360
All right.

214
00:17:50,650 --> 00:17:55,840
So up until then I'm just going to add and commit as you guys should also be doing.

215
00:17:55,870 --> 00:17:57,430
And I'll see you in the next one.

