Merge branch 'master' into chat-notifications

This commit is contained in:
Ulf Gebhardt 2023-07-17 18:15:47 +02:00 committed by GitHub
commit deb8394fe2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 4 deletions

View File

@ -19,7 +19,12 @@ type Room {
roomId: String! @cypher(statement: "RETURN this.id")
roomName: String! @cypher(statement: "MATCH (this)<-[:CHATS_IN]-(user:User) WHERE NOT user.id = $cypherParams.currentUserId RETURN user.name")
avatar: String! @cypher(statement: "MATCH (this)<-[:CHATS_IN]-(user:User) WHERE NOT user.id = $cypherParams.currentUserId RETURN user.avatar.url")
avatar: String @cypher(statement: """
MATCH (this)<-[:CHATS_IN]-(user:User)
WHERE NOT user.id = $cypherParams.currentUserId
OPTIONAL MATCH (:User)-[:AVATAR_IMAGE]->(image:Image)
RETURN image.url
""")
lastMessageAt: String

View File

@ -61,7 +61,7 @@
<script>
import { roomQuery, createRoom } from '~/graphql/Rooms'
import { messageQuery, createMessageMutation } from '~/graphql/Messages'
import { messageQuery, createMessageMutation, markMessagesAsSeen } from '~/graphql/Messages'
import chatStyle from '~/constants/chat.js'
import { mapGetters } from 'vuex'
@ -84,7 +84,8 @@ export default {
name: 'dummyItem',
title: 'Just a dummy item',
},
/* {
/*
{
name: 'inviteUser',
title: 'Invite User',
},
@ -137,7 +138,7 @@ export default {
rooms: [],
roomsLoaded: false,
roomPage: 0,
roomPageSize: 10, // TODO pagination is a problem with single rooms - cant use
roomPageSize: 10,
singleRoom: !!this.singleRoomId || false,
selectedRoom: null,
loadingRooms: true,
@ -254,8 +255,19 @@ export default {
fetchPolicy: 'no-cache',
})
const newMsgIds = Message.filter((m) => m.seen === false).map((m) => m.id)
if (newMsgIds.length) {
this.$apollo.mutate({
mutation: markMessagesAsSeen(),
variables: {
messageIds: newMsgIds,
},
})
}
const msgs = []
;[...this.messages, ...Message].forEach((m) => {
if (m.senderId !== this.currentUser.id) m.seen = true
m.date = new Date(m.date).toDateString()
msgs[m.indexId] = m
})
@ -272,6 +284,12 @@ export default {
},
async sendMessage(message) {
// check for usersTag and change userid to username
message.usersTag.forEach((userTag) => {
const needle = `<usertag>${userTag.id}</usertag>`
const replacement = `<usertag>@${userTag.name.replaceAll(' ', '-').toLowerCase()}</usertag>`
message.content = message.content.replaceAll(needle, replacement)
})
try {
await this.$apollo.mutate({
mutation: createMessageMutation(),

View File

@ -33,3 +33,11 @@ export const createMessageMutation = () => {
}
`
}
export const markMessagesAsSeen = () => {
return gql`
mutation ($messageIds: [String!]) {
MarkMessagesAsSeen(messageIds: $messageIds)
}
`
}