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