fix new room mechanic

This commit is contained in:
Ulf Gebhardt 2023-07-20 12:57:18 +02:00
parent 0b64fce5aa
commit 624f379677
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
2 changed files with 20 additions and 5 deletions

View File

@ -260,10 +260,10 @@ export default {
rms.push({
...r,
index: r.lastMessage?.date,
lastMessage: {
lastMessage: r.lastMessage ? {
...r.lastMessage,
content: r.lastMessage?.content?.trim().substring(0, 30),
},
}: null,
users: r.users.map((u) => {
return { ...u, username: u.name, avatar: u.avatar?.url }
}),
@ -416,8 +416,23 @@ export default {
},
})
.then(({ data: { CreateRoom } }) => {
this.fetchRooms({ room: CreateRoom, options: { refetch: true } })
this.selectedRoom = CreateRoom
const roomIndex = this.rooms.findIndex((r) => r.id === CreateRoom.roomId)
const room = {...CreateRoom, index: CreateRoom.lastMessage?.date, lastMessage: CreateRoom.lastMessage ? {
...CreateRoom.lastMessage,
content: CreateRoom.lastMessage?.content?.trim().substring(0, 30),
}: null,
users: CreateRoom.users.map((u) => {
return { ...u, username: u.name, avatar: u.avatar?.url }
})
}
// as long as we cannot query avatar on CreateRoom
room.avatar = room.users.find((u) => u.id === this.currentUser.id).avatar
if(roomIndex === -1){
this.rooms = [room, ...this.rooms]
}
this.fetchMessages({room, options: { refetch: true }})
this.$emit('show-chat', CreateRoom.id)
})
.catch((error) => {

View File

@ -23,7 +23,7 @@ export const createRoom = () => gql`
export const roomQuery = () => gql`
query Room($first: Int, $offset: Int, $id: ID) {
Room(first: $first, offset: $offset, id: $id, orderBy: lastMessageAt_desc) {
Room(first: $first, offset: $offset, id: $id, orderBy: [lastMessageAt_desc createdAt_desc] ) {
id
roomId
roomName