@@ -214,17 +214,17 @@ export default {
214
214
this .startRooms
215
215
)
216
216
217
- const rooms = await firestoreService .getRooms (query)
218
- // this.incrementDbCounter('Fetch Rooms', rooms.size )
217
+ const { data , docs } = await firestoreService .getRooms (query)
218
+ // this.incrementDbCounter('Fetch Rooms', data.length )
219
219
220
- this .roomsLoaded = rooms . empty || rooms . size < this .roomsPerPage
220
+ this .roomsLoaded = data . length === 0 || data . length < this .roomsPerPage
221
221
222
222
if (this .startRooms ) this .endRooms = this .startRooms
223
- this .startRooms = rooms . docs [rooms . docs .length - 1 ]
223
+ this .startRooms = docs[docs .length - 1 ]
224
224
225
225
const roomUserIds = []
226
- rooms .forEach (room => {
227
- room .data (). users .forEach (userId => {
226
+ data .forEach (room => {
227
+ room .users .forEach (userId => {
228
228
const foundUser = this .allUsers .find (user => user? ._id === userId)
229
229
if (! foundUser && roomUserIds .indexOf (userId) === - 1 ) {
230
230
roomUserIds .push (userId)
@@ -235,19 +235,17 @@ export default {
235
235
// this.incrementDbCounter('Fetch Room Users', roomUserIds.length)
236
236
const rawUsers = []
237
237
roomUserIds .forEach (userId => {
238
- const promise = firestoreService
239
- .getUser (userId)
240
- .then (user => user .data ())
238
+ const promise = firestoreService .getUser (userId)
241
239
rawUsers .push (promise)
242
240
})
243
241
244
242
this .allUsers = [... this .allUsers , ... (await Promise .all (rawUsers))]
245
243
246
244
const roomList = {}
247
- rooms .forEach (room => {
248
- roomList[room .id ] = { ... room . data () , users: [] }
245
+ data .forEach (room => {
246
+ roomList[room .id ] = { ... room, users: [] }
249
247
250
- room .data (). users .forEach (userId => {
248
+ room .users .forEach (userId => {
251
249
const foundUser = this .allUsers .find (user => user? ._id === userId)
252
250
if (foundUser) roomList[room .id ].users .push (foundUser)
253
251
})
@@ -374,17 +372,17 @@ export default {
374
372
375
373
firestoreService
376
374
.getMessages (room .roomId , this .messagesPerPage , this .lastLoadedMessage )
377
- .then (({ messages , docs }) => {
375
+ .then (({ data , docs }) => {
378
376
// this.incrementDbCounter('Fetch Room Messages', messages.length)
379
377
if (this .selectedRoom !== room .roomId ) return
380
378
381
- if (messages .length === 0 || messages .length < this .messagesPerPage ) {
379
+ if (data .length === 0 || data .length < this .messagesPerPage ) {
382
380
setTimeout (() => (this .messagesLoaded = true ), 0 )
383
381
}
384
382
385
383
if (options .reset ) this .messages = []
386
384
387
- messages .forEach (message => {
385
+ data .forEach (message => {
388
386
const formattedMessage = this .formatMessage (room, message)
389
387
this .messages .unshift (formattedMessage)
390
388
})
@@ -562,20 +560,17 @@ export default {
562
560
uploadTask .snapshot .ref
563
561
)
564
562
565
- const messageDoc = await firestoreService .getMessage (
566
- roomId,
567
- messageId
568
- )
569
-
570
- const files = messageDoc .data ().files
563
+ const message = await firestoreService .getMessage (roomId, messageId)
571
564
572
- files .forEach (f => {
565
+ message . files .forEach (f => {
573
566
if (f .url === file .localUrl ) {
574
567
f .url = url
575
568
}
576
569
})
577
570
578
- await firestoreService .updateMessage (roomId, messageId, { files })
571
+ await firestoreService .updateMessage (roomId, messageId, {
572
+ files: message .files
573
+ })
579
574
resolve (true )
580
575
}
581
576
)
@@ -644,7 +639,7 @@ export default {
644
639
user ._id
645
640
)
646
641
647
- if (! query1 .empty ) {
642
+ if (query1 .data . length ) {
648
643
return this .loadRoom (query1)
649
644
}
650
645
@@ -653,7 +648,7 @@ export default {
653
648
this .currentUserId
654
649
)
655
650
656
- if (! query2 .empty ) {
651
+ if (query2 .data . length ) {
657
652
return this .loadRoom (query2)
658
653
}
659
654
@@ -729,7 +724,7 @@ export default {
729
724
730
725
async listenRooms (query ) {
731
726
const listener = firestoreService .listenRooms (query, rooms => {
732
- // this.incrementDbCounter('Listen Rooms Typing Users', rooms.size )
727
+ // this.incrementDbCounter('Listen Rooms Typing Users', rooms.length )
733
728
rooms .forEach (room => {
734
729
const foundRoom = this .rooms .find (r => r .roomId === room .id )
735
730
if (foundRoom) {
@@ -840,8 +835,8 @@ export default {
840
835
return alert (' Nope, for demo purposes you cannot delete this room' )
841
836
}
842
837
843
- firestoreService .getMessages (roomId).then (({ messages }) => {
844
- messages .forEach (message => {
838
+ firestoreService .getMessages (roomId).then (({ data }) => {
839
+ data .forEach (message => {
845
840
firestoreService .deleteMessage (roomId, message .id )
846
841
if (message .files ) {
847
842
message .files .forEach (file => {
0 commit comments