Merge pull request #6615 from Ocelot-Social-Community/fix-chat-last-message-check

fix(webapp): fix lastMessage to contain proper values
This commit is contained in:
Hannes Heine 2023-07-19 16:23:50 +02:00 committed by GitHub
commit d23eb77d3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View File

@ -353,7 +353,9 @@ export default {
async sendMessage(message) {
try {
await this.$apollo.mutate({
const {
data: { CreateMessage: createdMessage },
} = await this.$apollo.mutate({
mutation: createMessageMutation(),
variables: {
roomId: message.roomId,
@ -362,7 +364,7 @@ export default {
})
const roomIndex = this.rooms.findIndex((r) => r.id === message.roomId)
const changedRoom = { ...this.rooms[roomIndex] }
changedRoom.lastMessage = message
changedRoom.lastMessage = createdMessage
changedRoom.lastMessage.content = changedRoom.lastMessage.content.trim().substring(0, 30)
this.rooms[roomIndex] = changedRoom
} catch (error) {

View File

@ -4,8 +4,23 @@ export const createMessageMutation = () => {
return gql`
mutation ($roomId: ID!, $content: String!) {
CreateMessage(roomId: $roomId, content: $content) {
#_id
id
indexId
content
senderId
author {
id
}
username
avatar
date
room {
id
}
saved
distributed
seen
}
}
`
@ -26,6 +41,9 @@ export const messageQuery = () => {
username
avatar
date
room {
id
}
saved
distributed
seen