Skip to content

Commit

Permalink
Merge pull request #6595 from Ocelot-Social-Community/chat-last-messages
Browse files Browse the repository at this point in the history
feat(webapp): show last message and unread count in room list
  • Loading branch information
ulfgebhardt authored Jul 18, 2023
2 parents aa86db4 + f9dad60 commit 3dab3c2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
3 changes: 3 additions & 0 deletions backend/src/graphql/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export const messageQuery = () => {
indexId
content
senderId
author {
id
}
username
avatar
date
Expand Down
2 changes: 2 additions & 0 deletions backend/src/graphql/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const createRoomMutation = () => {
roomName
lastMessageAt
unreadCount
#avatar
users {
_id
id
Expand All @@ -29,6 +30,7 @@ export const roomQuery = () => {
id
roomId
roomName
avatar
lastMessageAt
unreadCount
lastMessage {
Expand Down
22 changes: 11 additions & 11 deletions webapp/graphql/Messages.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import gql from 'graphql-tag'

export const createMessageMutation = () => {
return gql`
mutation ($roomId: ID!, $content: String!) {
CreateMessage(roomId: $roomId, content: $content) {
id
content
}
}
`
}

export const messageQuery = () => {
return gql`
query ($roomId: ID!, $first: Int, $offset: Int) {
Expand All @@ -23,17 +34,6 @@ export const messageQuery = () => {
`
}

export const createMessageMutation = () => {
return gql`
mutation ($roomId: ID!, $content: String!) {
CreateMessage(roomId: $roomId, content: $content) {
id
content
}
}
`
}

export const chatMessageAdded = () => {
return gql`
subscription chatMessageAdded($userId: ID!) {
Expand Down
32 changes: 23 additions & 9 deletions webapp/graphql/Rooms.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
import gql from 'graphql-tag'

export const createRoom = () => gql`
mutation ($userId: ID!) {
CreateRoom(userId: $userId) {
id
roomId
}
}
`

export const roomQuery = () => gql`
query Room($first: Int, $offset: Int, $id: ID) {
Room(first: $first, offset: $offset, id: $id, orderBy: lastMessageAt_desc) {
id
roomId
roomName
avatar
lastMessageAt
unreadCount
lastMessage {
_id
id
content
senderId
username
avatar
date
saved
distributed
seen
}
users {
_id
id
Expand All @@ -19,15 +42,6 @@ export const roomQuery = () => gql`
}
`

export const createRoom = () => gql`
mutation ($userId: ID!) {
CreateRoom(userId: $userId) {
id
roomId
}
}
`

export const unreadRoomsQuery = () => {
return gql`
query {
Expand Down

0 comments on commit 3dab3c2

Please sign in to comment.