File tree Expand file tree Collapse file tree 3 files changed +28
-5
lines changed Expand file tree Collapse file tree 3 files changed +28
-5
lines changed Original file line number Diff line number Diff line change @@ -727,6 +727,11 @@ messages: {
727
727
}
728
728
```
729
729
730
+ #### Notes
731
+
732
+ - You need to create a composite index to order rooms by last message received.
733
+ The easiest way to do it is to create a room, then click the error message url in the browser debugging console.
734
+
730
735
## Use as a Web Component
731
736
732
737
### Clone vue-advance-chat project
Original file line number Diff line number Diff line change @@ -106,10 +106,22 @@ export default {
106
106
const user3 = this .users [2 ]
107
107
await usersRef .doc (user3 ._id ).set (user3)
108
108
109
- await roomsRef .add ({ users: [user1 ._id , user2 ._id ] })
110
- await roomsRef .add ({ users: [user1 ._id , user3 ._id ] })
111
- await roomsRef .add ({ users: [user2 ._id , user3 ._id ] })
112
- await roomsRef .add ({ users: [user1 ._id , user2 ._id , user3 ._id ] })
109
+ await roomsRef .add ({
110
+ users: [user1 ._id , user2 ._id ],
111
+ lastUpdated: new Date ()
112
+ })
113
+ await roomsRef .add ({
114
+ users: [user1 ._id , user3 ._id ],
115
+ lastUpdated: new Date ()
116
+ })
117
+ await roomsRef .add ({
118
+ users: [user2 ._id , user3 ._id ],
119
+ lastUpdated: new Date ()
120
+ })
121
+ await roomsRef .add ({
122
+ users: [user1 ._id , user2 ._id , user3 ._id ],
123
+ lastUpdated: new Date ()
124
+ })
113
125
114
126
this .updatingData = false
115
127
}
Original file line number Diff line number Diff line change @@ -173,6 +173,7 @@ export default {
173
173
174
174
let query = roomsRef
175
175
.where (' users' , ' array-contains' , this .currentUserId )
176
+ .orderBy (' lastUpdated' , ' desc' )
176
177
.limit (this .roomsPerPage )
177
178
178
179
if (this .startRooms ) query = query .startAfter (this .startRooms )
@@ -430,6 +431,8 @@ export default {
430
431
const { id } = await messagesRef (roomId).add (message)
431
432
432
433
if (file) this .uploadFile ({ file, messageId: id, roomId })
434
+
435
+ roomsRef .doc (roomId).update ({ lastUpdated: new Date () })
433
436
},
434
437
435
438
openFile ({ message, action }) {
@@ -623,7 +626,10 @@ export default {
623
626
624
627
const { id } = await usersRef .add ({ username: this .addRoomUsername })
625
628
await usersRef .doc (id).update ({ _id: id })
626
- await roomsRef .add ({ users: [id, this .currentUserId ] })
629
+ await roomsRef .add ({
630
+ users: [id, this .currentUserId ],
631
+ lastUpdated: new Date ()
632
+ })
627
633
628
634
this .addNewRoom = false
629
635
this .addRoomUsername = ' '
You can’t perform that action at this time.
0 commit comments