mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
notify leave group
This commit is contained in:
parent
1d277e96a7
commit
a25e6eb326
@ -62,6 +62,17 @@ const handleJoinGroup = async (resolve, root, args, context, resolveInfo) => {
|
||||
return user
|
||||
}
|
||||
|
||||
const handleLeaveGroup = async (resolve, root, args, context, resolveInfo) => {
|
||||
const { groupId, userId } = args
|
||||
const user = await resolve(root, args, context, resolveInfo)
|
||||
if (user) {
|
||||
await publishNotifications(context, [
|
||||
notifyOwnersOfGroup(groupId, userId, 'user_left_group', context),
|
||||
])
|
||||
}
|
||||
return user
|
||||
}
|
||||
|
||||
const handleContentDataOfPost = async (resolve, root, args, context, resolveInfo) => {
|
||||
const idsOfUsers = extractMentionedUsers(args.content)
|
||||
const post = await resolve(root, args, context, resolveInfo)
|
||||
@ -232,5 +243,6 @@ export default {
|
||||
CreateComment: handleContentDataOfComment,
|
||||
UpdateComment: handleContentDataOfComment,
|
||||
JoinGroup: handleJoinGroup,
|
||||
LeaveGroup: handleLeaveGroup,
|
||||
},
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ import createServer, { pubsub } from '../../server'
|
||||
import {
|
||||
createGroupMutation,
|
||||
joinGroupMutation,
|
||||
// leaveGroupMutation,
|
||||
leaveGroupMutation,
|
||||
// changeGroupMemberRoleMutation,
|
||||
// removeUserFromGroupMutation,
|
||||
} from '../../graphql/groups'
|
||||
@ -704,5 +704,64 @@ describe('notifications', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('user leaves group', () => {
|
||||
beforeEach(async () => {
|
||||
authenticatedUser = await notifiedUser.toJson()
|
||||
await mutate({
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'closed-group',
|
||||
userId: authenticatedUser.id,
|
||||
},
|
||||
})
|
||||
await mutate({
|
||||
mutation: leaveGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'closed-group',
|
||||
userId: authenticatedUser.id,
|
||||
},
|
||||
})
|
||||
authenticatedUser = await groupOwner.toJson()
|
||||
})
|
||||
|
||||
it('has two the notification in database', async () => {
|
||||
await expect(
|
||||
query({
|
||||
query: notificationQuery,
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
data: {
|
||||
notifications: [
|
||||
{
|
||||
read: false,
|
||||
reason: 'user_left_group',
|
||||
createdAt: expect.any(String),
|
||||
from: {
|
||||
__typename: 'Group',
|
||||
id: 'closed-group',
|
||||
},
|
||||
relatedUser: {
|
||||
id: 'you',
|
||||
},
|
||||
},
|
||||
{
|
||||
read: false,
|
||||
reason: 'user_joined_group',
|
||||
createdAt: expect.any(String),
|
||||
from: {
|
||||
__typename: 'Group',
|
||||
id: 'closed-group',
|
||||
},
|
||||
relatedUser: {
|
||||
id: 'you',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -47,7 +47,8 @@ export default {
|
||||
`
|
||||
MATCH (resource {deleted: false, disabled: false})-[notification:NOTIFIED]->(user:User {id:$id})
|
||||
${whereClause}
|
||||
OPTIONAL MATCH (resource)<-[membership:MEMBER_OF]-(relatedUser:User { id: notification.relatedUserId })
|
||||
OPTIONAL MATCH (relatedUser:User { id: notification.relatedUserId })
|
||||
OPTIONAL MATCH (resource)<-[membership:MEMBER_OF]-(relatedUser)
|
||||
WITH user, notification, resource, membership, relatedUser,
|
||||
[(resource)<-[:WROTE]-(author:User) | author {.*}] AS authors,
|
||||
[(resource)-[:COMMENTS]->(post:Post)<-[:WROTE]-(author:User) | post {.*, author: properties(author)} ] AS posts
|
||||
|
||||
@ -23,6 +23,7 @@ enum NotificationReason {
|
||||
mentioned_in_comment
|
||||
commented_on_post
|
||||
user_joined_group
|
||||
user_left_group
|
||||
}
|
||||
|
||||
type Query {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user