@@ -246,24 +246,27 @@ export default {
246
246
})
247
247
248
248
this .rooms = this .rooms .concat (formattedRooms)
249
- this . rooms . map (( room , index ) => this .listenLastMessage (room, index ))
249
+ formattedRooms . map (room => this .listenLastMessage (room))
250
250
251
251
if (! this .rooms .length ) this .loadingRooms = false
252
252
253
- this .listenUsersOnlineStatus ()
253
+ this .listenUsersOnlineStatus (formattedRooms )
254
254
this .listenRoomsTypingUsers (query)
255
255
// setTimeout(() => console.log('TOTAL', this.dbRequestCount), 2000)
256
256
},
257
257
258
- listenLastMessage (room , index ) {
258
+ listenLastMessage (room ) {
259
259
const listener = messagesRef (room .roomId )
260
260
.orderBy (' timestamp' , ' desc' )
261
261
.limit (1 )
262
262
.onSnapshot (messages => {
263
263
// this.incrementDbCounter('Listen Last Room Message', messages.size)
264
264
messages .forEach (message => {
265
265
const lastMessage = this .formatLastMessage (message .data ())
266
- this .rooms [index].lastMessage = lastMessage
266
+ const roomIndex = this .rooms .findIndex (
267
+ r => room .roomId === r .roomId
268
+ )
269
+ this .rooms [roomIndex].lastMessage = lastMessage
267
270
this .rooms = [... this .rooms ]
268
271
})
269
272
if (this .loadingLastMessageByRoom < this .rooms .length ) {
@@ -579,8 +582,8 @@ export default {
579
582
})
580
583
},
581
584
582
- listenUsersOnlineStatus () {
583
- this . rooms .map (room => {
585
+ listenUsersOnlineStatus (rooms ) {
586
+ rooms .map (room => {
584
587
room .users .map (user => {
585
588
const listener = firebase
586
589
.database ()
0 commit comments