1
00:00:08,140 --> 00:00:13,090
Hey guys this is Caleb with Debb slopes and in this video we're going to set up the sending of messages

2
00:00:13,090 --> 00:00:16,830
in group feed Visi VC we're going to upload them to firebase in our group.

3
00:00:16,870 --> 00:00:22,420
We're also going to go ahead and we're going to set up a function in our data service to download all

4
00:00:22,420 --> 00:00:28,170
of our feed messages for the desired group that we want and we're also going to do a really cool table

5
00:00:28,170 --> 00:00:32,950
view scroll animation so that when a message is sent it'll scroll the table view all the way to the

6
00:00:32,950 --> 00:00:33,620
bottom.

7
00:00:33,730 --> 00:00:36,620
And so that we can see the most current message is very cool.

8
00:00:36,640 --> 00:00:42,580
So let's go ahead and let's pull open our X code project and we're actually going to start by setting

9
00:00:42,580 --> 00:00:47,770
up how the send button works we're going to set it up so that when we type a message and press send.

10
00:00:47,770 --> 00:00:50,750
It's going to upload a post to our desired group.

11
00:00:50,770 --> 00:00:56,110
Now I don't know if you remember this it was a while ago but we've already set up a function in here

12
00:00:56,110 --> 00:00:57,530
called upload post.

13
00:00:57,700 --> 00:01:01,140
And when we were doing that we added with group key.

14
00:01:01,270 --> 00:01:07,540
It's optional and we didn't use it but we need to basically set up what happens when we want to upload

15
00:01:07,540 --> 00:01:09,730
a post to a certain group.

16
00:01:09,820 --> 00:01:11,110
And so that's really easy.

17
00:01:11,110 --> 00:01:17,260
Thankfully all we have to do is basically go into our groups reference.

18
00:01:17,260 --> 00:01:20,830
We have to find the specific group thanks to our group key.

19
00:01:21,040 --> 00:01:26,860
Then what we're going to do is we're going to basically go into the messages array then we're going

20
00:01:26,860 --> 00:01:30,690
to go into the messages child which may or may not be created.

21
00:01:30,700 --> 00:01:35,380
Thankfully firebase will create it for us and then we're going to go ahead and go into that child and

22
00:01:35,410 --> 00:01:38,680
update the child values to include all the message content that we need.

23
00:01:38,680 --> 00:01:41,080
So let's set that up really fast.

24
00:01:41,080 --> 00:01:43,510
Like I said we're going to go into ref groups.

25
00:01:43,780 --> 00:01:50,350
We're going to go ahead and go into the child for the group key which actually we don't need to do it

26
00:01:50,350 --> 00:01:52,290
like that we can just say group key.

27
00:01:52,330 --> 00:01:53,500
All right very cool.

28
00:01:53,500 --> 00:01:56,590
We need to force on Rapido because it is optional coming in.

29
00:01:56,950 --> 00:02:01,270
So now that we are in the specific group let's just take a look at firebase so we can remember what

30
00:02:01,270 --> 00:02:02,730
we're doing here.

31
00:02:02,770 --> 00:02:03,050
OK.

32
00:02:03,070 --> 00:02:03,790
So cool.

33
00:02:03,850 --> 00:02:09,160
In each group you'll notice there are three components but I want to add in a messages array that's

34
00:02:09,160 --> 00:02:12,280
going to hold all of the messages that we need.

35
00:02:12,280 --> 00:02:15,900
And so what we're going to do is we basically just passed in the key.

36
00:02:15,900 --> 00:02:19,120
So now we're in the proper group.

37
00:02:19,390 --> 00:02:24,720
So we're going to go ahead and we're going to pass a child in that we have not yet created.

38
00:02:24,730 --> 00:02:27,790
But when we send a message it will automatically create it.

39
00:02:27,940 --> 00:02:30,010
It's going to be called messages.

40
00:02:30,490 --> 00:02:36,910
And then what we're going to do is for each message we're going to create a child by Auto-ID it's going

41
00:02:36,910 --> 00:02:41,710
to just be a random thing because each message doesn't necessarily need to be linked by its ID to a

42
00:02:41,710 --> 00:02:46,550
specific user because inside that child we're going to pass in the sender's ID.

43
00:02:46,570 --> 00:02:52,780
So inside this new child inside of messages we're going to go ahead and update child values with the

44
00:02:52,780 --> 00:02:53,720
dictionary.

45
00:02:53,740 --> 00:02:56,560
This is where we will pass it content.

46
00:02:56,910 --> 00:02:57,340
OK.

47
00:02:57,370 --> 00:02:58,590
Just like a feed.

48
00:02:58,840 --> 00:03:00,040
Just like a feed cell.

49
00:03:00,160 --> 00:03:06,340
If you remember the feed cell has content and a Sender ID and the content will come from the message

50
00:03:06,340 --> 00:03:09,670
passed in with the string appear message.

51
00:03:09,850 --> 00:03:13,790
Then we're going to have another one called Sender ID.

52
00:03:14,020 --> 00:03:14,670
OK.

53
00:03:14,770 --> 00:03:18,940
And that will come in from the ID we pass in can remember that.

54
00:03:18,940 --> 00:03:19,540
Very cool.

55
00:03:19,540 --> 00:03:20,640
So that's super simple.

56
00:03:20,640 --> 00:03:23,470
It's basically the same thing as down here.

57
00:03:23,650 --> 00:03:29,980
But this will create a messages folder inside any group will assign each message a random ID and then

58
00:03:29,980 --> 00:03:35,220
inside that will have content message and the sender ID from the ID.

59
00:03:35,260 --> 00:03:36,670
So that's good to go.

60
00:03:36,880 --> 00:03:42,280
Now let's go ahead and let's right get all messages for a desired group.

61
00:03:42,280 --> 00:03:46,810
That is the function we want and we're going to put it right beneath get all feed messages because it's

62
00:03:46,810 --> 00:03:48,340
kind of a similar function.

63
00:03:48,640 --> 00:03:51,200
So let's go ahead and put it right in the middle here.

64
00:03:51,430 --> 00:03:59,500
And like I said the name is phunk get all messages for desired group.

65
00:03:59,500 --> 00:04:01,410
Now I'm just going to use.

66
00:04:02,170 --> 00:04:03,920
I won't use an internal parameter for this.

67
00:04:03,940 --> 00:04:05,510
I'm just going to pass it a group.

68
00:04:05,740 --> 00:04:08,800
Then we need a handler that's going to return all the messages.

69
00:04:08,800 --> 00:04:09,310
OK.

70
00:04:09,550 --> 00:04:10,630
So go ahead and type.

71
00:04:10,630 --> 00:04:11,890
Handler.

72
00:04:11,950 --> 00:04:14,320
It's going to be escaping like always.

73
00:04:14,320 --> 00:04:19,740
And then we're going to have to go in and put some parentheses here or some curly brackets.

74
00:04:19,870 --> 00:04:25,130
And for what actually escapes the closure we're going to just call it messages array.

75
00:04:25,510 --> 00:04:29,540
And it's going to be an array of type message which we already created.

76
00:04:29,560 --> 00:04:31,050
Just like up here.

77
00:04:31,120 --> 00:04:31,720
Very cool.

78
00:04:31,720 --> 00:04:33,100
Very simple.

79
00:04:33,130 --> 00:04:39,370
So what we need to do is we basically need to go through and find the right group.

80
00:04:39,370 --> 00:04:44,170
We need to find the messages and then we need to cycle through and create all the messages that we need

81
00:04:44,470 --> 00:04:49,690
and append them back up to the group basically like we did here we observed the feed.

82
00:04:49,690 --> 00:04:50,850
We created a snapshot.

83
00:04:50,860 --> 00:04:55,210
We cycled through all of them created message objects appended them and then returned them.

84
00:04:55,210 --> 00:04:59,980
So we're going to do the same thing but let's start with an array that we're going to actually append

85
00:04:59,980 --> 00:05:01,320
all of our messages to.

86
00:05:01,600 --> 00:05:07,350
And let's call it var group message array and it's going to be an array of Messud.

87
00:05:07,750 --> 00:05:09,030
Let's instantiate it.

88
00:05:09,370 --> 00:05:15,200
And now let's go ahead and let's observe the desired groups messages child.

89
00:05:15,380 --> 00:05:19,210
So type ref groups dot child.

90
00:05:19,210 --> 00:05:24,560
Now of course the key is going to be the group or sorry the desired group.

91
00:05:25,630 --> 00:05:27,500
We're going to force on rapid there.

92
00:05:27,650 --> 00:05:30,480
Now we're going to go ahead and oh you know what.

93
00:05:30,490 --> 00:05:31,440
Sorry it's not optional.

94
00:05:31,450 --> 00:05:35,590
So we don't need to we don't need to unwrap it that way.

95
00:05:35,590 --> 00:05:43,360
So we are in the proper group that we've selected then we need to go into the messages child so choose

96
00:05:43,360 --> 00:05:47,080
child by path string and type messages.

97
00:05:47,080 --> 00:05:50,550
Then inside of that we want to observe the whole thing.

98
00:05:50,560 --> 00:05:54,360
So we're going to type observe single event of type value.

99
00:05:54,370 --> 00:05:58,230
We're going to observe all the values and this is only going to happen once.

100
00:05:58,330 --> 00:06:03,160
But we're going to call an observer from the actual view controller so that when a change happens it'll

101
00:06:03,160 --> 00:06:05,520
cycle through and update all the changes.

102
00:06:05,740 --> 00:06:10,990
And this will this will prevent basically any issues of this being called multiple times and loading

103
00:06:10,990 --> 00:06:12,040
the data multiple times.

104
00:06:12,040 --> 00:06:15,640
I ran into an issue with that but I found that this is a great solution.

105
00:06:15,640 --> 00:06:23,980
So for the closure go ahead and call data snapshot group message snapshot because it's coming specifically

106
00:06:23,980 --> 00:06:25,230
from the group.

107
00:06:25,510 --> 00:06:31,600
And now we're going to use guard like we have to create a constant holding that snapshot guard let a

108
00:06:31,600 --> 00:06:41,310
group message snapshot equals group message snapshot children all objects.

109
00:06:41,350 --> 00:06:45,140
And we're going to cast it as a an array of data snapshot.

110
00:06:45,580 --> 00:06:50,020
If we can't do that or else return.

111
00:06:50,380 --> 00:06:56,600
And now we have a group message snapshot so now let's go ahead and cycle through that four group met

112
00:06:57,370 --> 00:07:03,700
with two O's group message in group message snapshot.

113
00:07:04,090 --> 00:07:07,370
We're going to go ahead and basically do what we did up here.

114
00:07:07,510 --> 00:07:13,180
We're going to get the content and the sender ID then we're going to go ahead and pull that together

115
00:07:13,210 --> 00:07:16,720
into a message object and we're going to append that to our message.

116
00:07:16,750 --> 00:07:25,330
So let content equals group message child snapshot for path content.

117
00:07:26,080 --> 00:07:32,980
And we want the value and we want to cast it as a string so that it can be added as text data then we

118
00:07:32,980 --> 00:07:34,000
want the sender ID.

119
00:07:34,180 --> 00:07:39,760
So go ahead and type let sender ID equals group message child snapshot.

120
00:07:40,270 --> 00:07:43,110
The path of course is sender ID.

121
00:07:43,210 --> 00:07:45,930
We want the value of that and we want to cast that as a strength.

122
00:07:46,080 --> 00:07:46,330
OK.

123
00:07:46,360 --> 00:07:48,640
Just like we did with the content.

124
00:07:48,790 --> 00:07:55,810
Now we're going to create a message object by typing let message equals message and let's instantiate

125
00:07:55,810 --> 00:07:59,500
that bad boy and we're going to give him some content.

126
00:07:59,830 --> 00:08:02,930
There we go and we're going to pass it a Sender ID as well.

127
00:08:03,250 --> 00:08:04,570
Excellent.

128
00:08:04,570 --> 00:08:10,710
Next after we have created our message object we're going to append that to our group message array.

129
00:08:10,870 --> 00:08:15,010
And you know what just to be specific I'm going to call this group message.

130
00:08:15,010 --> 00:08:21,430
So now that we want to append that we're going to type group message array append and you'll see it

131
00:08:21,430 --> 00:08:28,600
requires a message which we have in group message perfect.

132
00:08:28,900 --> 00:08:34,500
K so once that's all done after the for loop is finished we're going to call our handler which asks

133
00:08:34,500 --> 00:08:39,140
us to return an array of message which we have in group message array.

134
00:08:39,310 --> 00:08:46,440
This function is going to be handy for returning all the messages for the specific group that we want.

135
00:08:46,450 --> 00:08:51,170
Let's go ahead and let's set this up in group feed Visi now.

136
00:08:51,460 --> 00:08:59,080
So when we go into view we'll appear we load all of the titles stuff we load all of the emails.

137
00:08:59,080 --> 00:09:06,520
That's great but now we're going to go ahead and observe our groups reference and we're going to call

138
00:09:06,530 --> 00:09:08,960
get all messages for desired group.

139
00:09:08,980 --> 00:09:15,890
So let's go ahead and call data service instance ref groups and we want to observe all changes.

140
00:09:15,940 --> 00:09:19,160
If anything changes we want to update all the messages.

141
00:09:19,360 --> 00:09:27,260
So go ahead and call observe and we're going to type value because we want to observe all values changing.

142
00:09:27,280 --> 00:09:32,200
Now the snapshot for this one we don't care about because we're not actually using it we're just using

143
00:09:32,200 --> 00:09:34,030
this to observe our groups reference.

144
00:09:34,030 --> 00:09:41,910
But what we are going to do is call data service instance to get all messages for desired group.

145
00:09:41,950 --> 00:09:47,520
Well what group are we going to pass in the group that we downloaded when we initialized the view controller

146
00:09:47,530 --> 00:09:53,370
so called self group because we are now inside of a closure so we have to call self.

147
00:09:53,710 --> 00:09:58,550
And that's the group that we want and this will give us all the messages back that we need.

148
00:09:58,570 --> 00:10:02,920
So let's call this returned group messages.

149
00:10:02,980 --> 00:10:03,910
I'm just going to copy that.

150
00:10:03,910 --> 00:10:05,390
That's a long name.

151
00:10:05,620 --> 00:10:10,810
And now that we have this returned we should set an array locally.

152
00:10:11,050 --> 00:10:14,030
In this view controller that will hold all those messages.

153
00:10:14,230 --> 00:10:19,170
So let's go ahead and do that let's create var group messages.

154
00:10:19,630 --> 00:10:23,930
And that's going to be of course an array of message and we're going to instantiate it.

155
00:10:24,160 --> 00:10:25,510
Really cool.

156
00:10:25,510 --> 00:10:34,890
Next we're going to go ahead and let's think we need to set self dot group messages to be equal to returned

157
00:10:34,900 --> 00:10:38,140
group messages whichever messages got returned back.

158
00:10:38,230 --> 00:10:39,510
That's what we want to do.

159
00:10:39,850 --> 00:10:40,150
All right.

160
00:10:40,150 --> 00:10:47,830
And now now that we have those group messages returned we can call self table view reload data and all

161
00:10:47,830 --> 00:10:52,080
of the messages will flood in and show up where they're supposed to be.

162
00:10:52,180 --> 00:10:57,310
But we have a problem folks we have not yet set up our table view in this view controller.

163
00:10:57,310 --> 00:10:58,700
Let's do that now.

164
00:10:58,810 --> 00:11:04,390
I'm going to tab down here so you can see plenty of things and we're going to do this with an extension

165
00:11:04,750 --> 00:11:13,750
by typing extension group feed Visi and we're going to conform to you I'd table view delegate and you

166
00:11:13,810 --> 00:11:17,390
table your data source like we have like 100 times in this course.

167
00:11:17,950 --> 00:11:25,600
And we need number of sections in table view number of rows in Section and self-growth index path.

168
00:11:25,660 --> 00:11:26,650
That's great.

169
00:11:26,650 --> 00:11:29,640
Let's return one section.

170
00:11:29,830 --> 00:11:37,480
Let's go ahead and return the group messages array count because we need to return how many messages

171
00:11:37,480 --> 00:11:39,700
we have that's just makes sense.

172
00:11:39,760 --> 00:11:44,520
And now what we're going to do is we're going to set up a cell and we're going to go ahead and initialize

173
00:11:44,520 --> 00:11:45,940
it with everything that we need.

174
00:11:45,970 --> 00:11:49,430
So go ahead and type guard let sell.

175
00:11:49,440 --> 00:11:54,470
Like we have equals table view dot dequeue.

176
00:11:54,500 --> 00:12:00,100
Whoa delegate dequeue reusable cell with identifier for index path.

177
00:12:00,280 --> 00:12:04,060
And of course we have group feed cell.

178
00:12:04,210 --> 00:12:08,880
We've already set up that name in the main storyboard and we're just going to give it the index path.

179
00:12:08,920 --> 00:12:09,550
OK.

180
00:12:09,910 --> 00:12:19,420
Now we need to cast this as a group feed cell and if that doesn't work else we're going to return a

181
00:12:19,840 --> 00:12:24,040
table view cell just instantiate it like so.

182
00:12:24,280 --> 00:12:29,640
But assuming this works which it will we're going to go ahead and configure our cell.

183
00:12:29,740 --> 00:12:36,340
So go ahead and type cell doc configure cell and like always it needs a profile image and email and

184
00:12:36,340 --> 00:12:37,000
content.

185
00:12:37,000 --> 00:12:41,220
So let's give it that from our group message array.

186
00:12:41,410 --> 00:12:45,970
We can pull out the message for the index and get all the data we need by typing let.

187
00:12:45,970 --> 00:12:53,860
Message equals group messages and we can just pull the index path dot row to get the specific message

188
00:12:53,860 --> 00:12:54,520
all the way down.

189
00:12:54,520 --> 00:12:56,720
We've done this throughout the whole course.

190
00:12:56,840 --> 00:13:03,930
So let's go ahead and let's pull out message dot sender ID.

191
00:13:04,000 --> 00:13:05,170
Oh that's a problem.

192
00:13:05,170 --> 00:13:10,270
We'll fix that in a second so we don't have an e-mail yet but we can get it.

193
00:13:10,290 --> 00:13:14,410
So for the content though we can definitely get message content.

194
00:13:14,700 --> 00:13:18,100
But for the e-mail we're going to have to use our user name function.

195
00:13:18,130 --> 00:13:24,620
So go ahead and call a data service instance get e-mail.

196
00:13:24,730 --> 00:13:29,120
Let's see you get username you I.D. because remember we called it username.

197
00:13:29,130 --> 00:13:31,580
We really should have called an e-mail.

198
00:13:31,950 --> 00:13:39,660
But what we can do is we can pass the message sender ID and the handler of course is an e-mail so we

199
00:13:39,660 --> 00:13:45,540
can move our configuration of the cell into this function and for the e-mail we can just pass an e-mail

200
00:13:45,540 --> 00:13:48,290
that we get back from our get user name function.

201
00:13:48,300 --> 00:13:54,750
The profile limits though is another story and we can actually just go ahead and call you image named

202
00:13:55,170 --> 00:14:00,990
and it's just default profile image we're not going to actually download or upload images for this section

203
00:14:00,990 --> 00:14:05,670
of the course but that is something that you could do to extend this app.

204
00:14:05,670 --> 00:14:10,250
Hint hint now that it's configured we're going to go ahead and return the cell.

205
00:14:10,500 --> 00:14:13,980
And now we should be good to go to get all feed messages.

206
00:14:13,980 --> 00:14:16,350
The only issue we haven't set it up to send yet.

207
00:14:16,350 --> 00:14:18,420
We can't do anything if we push that send button.

208
00:14:18,420 --> 00:14:22,140
So let's go ahead and let's send a message.

209
00:14:22,230 --> 00:14:26,400
We need to make sure though that we actually have typed something so let's make sure that the message

210
00:14:26,400 --> 00:14:28,580
textfield is not nil or empty.

211
00:14:28,830 --> 00:14:34,840
So go ahead and type if message textfield text is not equal to nothing.

212
00:14:35,030 --> 00:14:38,590
If it's not empty We're going to go ahead and disable the textfield.

213
00:14:38,600 --> 00:14:42,570
We're going to disable the button as soon as we press it so that we can't press it multiple times and

214
00:14:42,570 --> 00:14:43,760
send multiple messages.

215
00:14:43,770 --> 00:14:51,630
It's just kind of a nice way to just verify that we don't send accidental input so call message textfield

216
00:14:51,690 --> 00:15:02,690
dot isn't enabled WIPs is enabled is false and send button dot is enabled is also going to be false.

217
00:15:02,790 --> 00:15:07,220
Then after that we're going to call data service for instance.

218
00:15:07,260 --> 00:15:10,540
And from this point it's just like uploading a post to the feed.

219
00:15:10,710 --> 00:15:14,270
We're going to take message textfield dot text unwrap it.

220
00:15:14,310 --> 00:15:17,010
That's the message we're going to send the I.D..

221
00:15:17,010 --> 00:15:21,240
We're going to send is off from firebase Auth.

222
00:15:23,940 --> 00:15:25,840
we forgot to import firebase.

223
00:15:25,990 --> 00:15:29,480
Let's go to that import firebase sneaky thing.

224
00:15:29,590 --> 00:15:33,810
And now for the off Id We can call off off.

225
00:15:33,910 --> 00:15:41,140
Current User ID and it's going to yell at us in just a second but this time instead of sending it to

226
00:15:41,140 --> 00:15:46,680
the feed we're going to pass in a group key which we can get from group Dom key.

227
00:15:46,840 --> 00:15:50,700
We need to force unwrap it of course because it is optional.

228
00:15:51,040 --> 00:15:55,540
And you know what it's yelling at us that we need to force unwrap the off as well.

229
00:15:55,540 --> 00:15:57,020
That's fine.

230
00:15:57,020 --> 00:16:02,440
Now oh interesting so I guess oh no no sorry because I pulled it.

231
00:16:02,450 --> 00:16:03,790
Optionally here that's fine.

232
00:16:03,790 --> 00:16:10,190
We have a value and send complete is going to be a bully and that comes back.

233
00:16:10,210 --> 00:16:12,130
Let's just say status.

234
00:16:12,610 --> 00:16:19,890
And we're going to say well no maybe complete that makes a little more sense if complete meaning if

235
00:16:19,890 --> 00:16:28,630
the send is complete we're going to re-enable message textfield that isn't enabled equals true and send

236
00:16:28,630 --> 00:16:34,000
button did it again send button is enabled is also true.

237
00:16:34,000 --> 00:16:34,840
Very very cool.

238
00:16:34,840 --> 00:16:40,090
And when we send it we also want to blank out the message textfield so that it's empty again because

239
00:16:40,090 --> 00:16:41,620
we don't want to send the same message twice.

240
00:16:41,620 --> 00:16:46,060
So go ahead and type message textfield dot text is empty.

241
00:16:46,060 --> 00:16:46,610
Very cool.

242
00:16:46,630 --> 00:16:49,000
And of course it's yelling at us we're in a closure.

243
00:16:49,000 --> 00:16:52,990
So we need to do self dot all these things.

244
00:16:52,990 --> 00:16:55,720
Now whoops we deleted the whole thing let's try that again.

245
00:16:55,720 --> 00:16:57,670
Self-taught send button is enabled.

246
00:16:58,000 --> 00:16:58,810
Let's go try it out.

247
00:16:58,810 --> 00:17:04,450
This should work to send a message and to download all of them at the same exact time.

248
00:17:04,450 --> 00:17:09,450
Let's give it a shot simulator is opening up.

249
00:17:10,060 --> 00:17:12,310
It is building and running.

250
00:17:12,310 --> 00:17:13,840
Here we go let's try it.

251
00:17:14,050 --> 00:17:16,550
Click on groups click on nerd herd.

252
00:17:16,570 --> 00:17:17,800
We have our e-mails.

253
00:17:18,010 --> 00:17:19,380
Let's send a message.

254
00:17:19,750 --> 00:17:20,790
Hey guys.

255
00:17:20,800 --> 00:17:21,520
And you know what.

256
00:17:21,550 --> 00:17:23,230
Let's watch firebase just for fun.

257
00:17:23,440 --> 00:17:26,580
Here's our group and here we go.

258
00:17:26,590 --> 00:17:27,100
Send

259
00:17:30,930 --> 00:17:32,080
and nothing happens.

260
00:17:32,080 --> 00:17:34,780
Interesting messages shows up here.

261
00:17:34,780 --> 00:17:40,900
So it looks like we pressed send and nothing happened.

262
00:17:41,260 --> 00:17:51,010
Well we said if complete it should re-enable everything and it should show in the table view but weird.

263
00:17:51,030 --> 00:17:53,540
Yeah it appears it's complete it's an firebase.

264
00:17:53,560 --> 00:18:02,530
Let's go look at that upload post function and let's see oh we never send We never used our hndler

265
00:18:02,530 --> 00:18:03,730
to say that we were done.

266
00:18:03,730 --> 00:18:05,760
That's totally why it's not completing.

267
00:18:05,800 --> 00:18:09,100
So let's call our handler here send complete and let's pass it.

268
00:18:09,100 --> 00:18:10,490
True.

269
00:18:10,510 --> 00:18:11,020
There we go.

270
00:18:11,020 --> 00:18:14,110
That should be the problem we were just not telling it that the message was done.

271
00:18:14,110 --> 00:18:19,450
So it had no idea whether or not it should know that it's done or not so let's let's try this out.

272
00:18:19,660 --> 00:18:24,760
Let's go into groups let's open it up and we're still not getting any messages we'll have to investigate

273
00:18:24,760 --> 00:18:25,440
that in a second.

274
00:18:25,450 --> 00:18:33,100
But let's try to send a message Haloo when I send it it looks like it sends everything goes away.

275
00:18:33,100 --> 00:18:36,420
But our table view is definitely not doing anything.

276
00:18:36,650 --> 00:18:42,940
Oh we didn't set up the table if you delegate or datasource simple stuff folks to this table view that

277
00:18:42,970 --> 00:18:45,780
delegate equals self table view.

278
00:18:45,870 --> 00:18:49,490
Datasource equals self and let's build and run it.

279
00:18:49,540 --> 00:18:51,260
That should actually solve the problem.

280
00:18:51,260 --> 00:18:57,020
It's sometimes the simplest things that you just gloss over things I've done like a million times anyway.

281
00:18:57,040 --> 00:18:58,920
So let's open it up.

282
00:18:59,050 --> 00:18:59,980
There's our messages.

283
00:18:59,980 --> 00:19:00,870
That's amazing.

284
00:19:00,940 --> 00:19:02,890
Let's send it.

285
00:19:03,070 --> 00:19:05,610
Batman rules.

286
00:19:06,130 --> 00:19:10,810
And when I when I send it let's see what happens.

287
00:19:10,900 --> 00:19:11,410
There it is.

288
00:19:11,410 --> 00:19:11,830
Boom.

289
00:19:11,860 --> 00:19:14,830
The message appears exactly as we hoped.

290
00:19:14,830 --> 00:19:16,990
That is so so cool.

291
00:19:16,990 --> 00:19:20,390
Amazing it popped up in real time just like you would expect.

292
00:19:20,440 --> 00:19:26,110
Now the last thing we need to do is we need to set up a scroll animation for whenever we reload data

293
00:19:26,140 --> 00:19:33,270
and get some new messages because we should have it animate to show the most recent message every time.

294
00:19:33,270 --> 00:19:37,120
And to do that we first need to make sure we have messages because if there is nothing in the table

295
00:19:37,130 --> 00:19:39,100
view this is going to cause a crash.

296
00:19:39,100 --> 00:19:51,160
So if self dot group messages that count is greater than zero what we're going to do is we're going

297
00:19:51,160 --> 00:19:59,380
to call a self table view that scroll to row an index path at your table if you scroll position and

298
00:19:59,380 --> 00:20:00,280
animated.

299
00:20:00,280 --> 00:20:05,420
Well of course we want it to be animated and the position we're going to have it scroll to none.

300
00:20:05,500 --> 00:20:05,790
OK.

301
00:20:05,800 --> 00:20:09,590
And you'll see why in a second you can have it scroll to the middle bottom or top.

302
00:20:09,700 --> 00:20:11,690
But sometimes there can be issues.

303
00:20:11,710 --> 00:20:17,650
So none basically just tells it to scroll all the way to the index path that we set.

304
00:20:17,650 --> 00:20:24,490
Now the thing is the index path is an interesting thing because we cannot tell it to scroll to the bottom

305
00:20:24,520 --> 00:20:27,840
but we can tell it to go to group messages don't count.

306
00:20:27,850 --> 00:20:37,960
So if we give it an index path and we call in it to get the row and section what we can do is we can

307
00:20:37,960 --> 00:20:46,390
basically say the section is zero of course because we only have one section and we're using that we're

308
00:20:46,390 --> 00:20:48,110
using zero indexing here.

309
00:20:48,220 --> 00:20:55,450
Now for the row we want to scroll to the very bottom row and in order to get to that we could just call

310
00:20:55,450 --> 00:20:59,490
self group messages don't count.

311
00:20:59,500 --> 00:21:03,540
So let's say we had 30 messages I could scroll to the thirtieth row.

312
00:21:03,640 --> 00:21:04,210
Right.

313
00:21:04,270 --> 00:21:07,090
If we had 31 suddenly it was scroll to the 31st row.

314
00:21:07,210 --> 00:21:12,430
But the issue is that the count shows the true value so if there are 30 messages it would come back

315
00:21:12,460 --> 00:21:13,600
as 30.

316
00:21:13,600 --> 00:21:19,690
But the array only goes up to 29 on the index because I raise you zero indexing.

317
00:21:19,690 --> 00:21:21,610
So let's go ahead and do self-talk.

318
00:21:21,610 --> 00:21:24,150
Group messages don't count minus 1.

319
00:21:24,340 --> 00:21:29,170
And believe it or not guys this will make a really cool animation that will animate to the very bottom

320
00:21:29,170 --> 00:21:31,450
of our table view whenever we send a message.

321
00:21:31,450 --> 00:21:33,310
So let's go ahead and build and run.

322
00:21:33,460 --> 00:21:37,170
Let's go check this out and let's see how we did and we'll call this video.

323
00:21:37,170 --> 00:21:37,930
Good.

324
00:21:38,410 --> 00:21:38,740
OK.

325
00:21:38,740 --> 00:21:43,140
Go to groups go to your group let's send some messages.

326
00:21:43,280 --> 00:21:47,760
Hi yo yo.

327
00:21:47,890 --> 00:21:50,250
And this one should animate nicely.

328
00:21:50,260 --> 00:21:51,350
Nice.

329
00:21:51,400 --> 00:21:54,760
See that it animates nicely but problem.

330
00:21:54,760 --> 00:21:57,760
We're covering the table view.

331
00:21:58,360 --> 00:22:01,210
We can see that it's animating but we need to fix that constraint.

332
00:22:01,270 --> 00:22:04,300
So let's go into the storyboard here.

333
00:22:04,390 --> 00:22:08,700
Let's go ahead and fix that really quickly and then we'll call this video quits.

334
00:22:12,550 --> 00:22:13,130
All right.

335
00:22:13,300 --> 00:22:18,040
So the table view the bottom constraint here goes to the very bottom of the view and that views just

336
00:22:18,160 --> 00:22:20,260
happens to be on top of the table view.

337
00:22:20,620 --> 00:22:25,950
Let's get rid of our bottom constraint and we're going to go ahead and pin it 8 to the bottom.

338
00:22:25,960 --> 00:22:27,230
Well not eight but zero.

339
00:22:27,250 --> 00:22:28,410
So that it matches exactly.

340
00:22:28,410 --> 00:22:29,270
Up next to it.

341
00:22:29,500 --> 00:22:34,000
Press Enter to set that constraint and let's build and run one more time.

342
00:22:34,000 --> 00:22:35,670
That should solve our issue.

343
00:22:35,680 --> 00:22:38,710
Guys this app is coming together it's looking amazing.

344
00:22:38,710 --> 00:22:40,960
Great great job so far.

345
00:22:40,960 --> 00:22:43,380
And guys we've done a lot of work to make this awesome.

346
00:22:43,420 --> 00:22:48,420
So let's go ahead and head in there is our most recent message let's send a new one.

347
00:22:48,730 --> 00:22:55,590
Harvey stinks and send and it animates up just like we were hoping.

348
00:22:55,600 --> 00:23:00,130
Now the cool thing is when you enter into this let's say people have sent new messages since you last

349
00:23:00,130 --> 00:23:01,780
went and watched this.

350
00:23:02,050 --> 00:23:08,200
When you go in that animates you see that maybe any to send a few more may send a few more here kind

351
00:23:08,200 --> 00:23:09,580
of spamming my channel here.

352
00:23:09,740 --> 00:23:12,250
OK let's go back and watch this.

353
00:23:12,250 --> 00:23:13,930
Do you see that it animates when it pops up.

354
00:23:13,930 --> 00:23:15,200
It's really really cool.

355
00:23:15,340 --> 00:23:18,790
And I will be able to see it better later when we animate this in from the left.

356
00:23:18,790 --> 00:23:20,410
But guys amazing work.

357
00:23:20,410 --> 00:23:23,910
We now are getting group messages now to prove it.

358
00:23:23,950 --> 00:23:28,170
It's not coming into this one faded boom.

359
00:23:28,960 --> 00:23:31,370
Different messages for different groups.

360
00:23:31,390 --> 00:23:32,690
Super super cool.

361
00:23:32,710 --> 00:23:33,870
Amazing work.

362
00:23:33,970 --> 00:23:39,340
Let's head over to the next video where we're going to go ahead and we're going to set up a view controller

363
00:23:39,340 --> 00:23:45,040
extension that's going to animate this view controller to the left instead of popping up from the bottom.

364
00:23:45,040 --> 00:23:46,140
And then we're done.

365
00:23:46,150 --> 00:23:47,620
This app is finished.

366
00:23:47,620 --> 00:23:48,810
Amazing work.

367
00:23:48,910 --> 00:23:50,880
And let's head over to that next video now.

