mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
fix new room mechanic
This commit is contained in:
parent
0b64fce5aa
commit
624f379677
@ -260,10 +260,10 @@ export default {
|
|||||||
rms.push({
|
rms.push({
|
||||||
...r,
|
...r,
|
||||||
index: r.lastMessage?.date,
|
index: r.lastMessage?.date,
|
||||||
lastMessage: {
|
lastMessage: r.lastMessage ? {
|
||||||
...r.lastMessage,
|
...r.lastMessage,
|
||||||
content: r.lastMessage?.content?.trim().substring(0, 30),
|
content: r.lastMessage?.content?.trim().substring(0, 30),
|
||||||
},
|
}: null,
|
||||||
users: r.users.map((u) => {
|
users: r.users.map((u) => {
|
||||||
return { ...u, username: u.name, avatar: u.avatar?.url }
|
return { ...u, username: u.name, avatar: u.avatar?.url }
|
||||||
}),
|
}),
|
||||||
@ -416,8 +416,23 @@ export default {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(({ data: { CreateRoom } }) => {
|
.then(({ data: { CreateRoom } }) => {
|
||||||
this.fetchRooms({ room: CreateRoom, options: { refetch: true } })
|
const roomIndex = this.rooms.findIndex((r) => r.id === CreateRoom.roomId)
|
||||||
this.selectedRoom = CreateRoom
|
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)
|
this.$emit('show-chat', CreateRoom.id)
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
|||||||
@ -23,7 +23,7 @@ export const createRoom = () => gql`
|
|||||||
|
|
||||||
export const roomQuery = () => gql`
|
export const roomQuery = () => gql`
|
||||||
query Room($first: Int, $offset: Int, $id: ID) {
|
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
|
id
|
||||||
roomId
|
roomId
|
||||||
roomName
|
roomName
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user