mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
notify user when removed from group
This commit is contained in:
parent
ed217a0c14
commit
6adfac1c7b
@ -84,6 +84,17 @@ const handleChangeGroupMemberRole = async (resolve, root, args, context, resolve
|
||||
return user
|
||||
}
|
||||
|
||||
const handleRemoveUserFromGroup = async (resolve, root, args, context, resolveInfo) => {
|
||||
const { groupId, userId } = args
|
||||
const user = await resolve(root, args, context, resolveInfo)
|
||||
if (user) {
|
||||
await publishNotifications(context, [
|
||||
notifyMemberOfGroup(groupId, userId, 'removed_user_from_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)
|
||||
@ -160,15 +171,17 @@ const notifyOwnersOfGroup = async (groupId, userId, reason, context) => {
|
||||
}
|
||||
|
||||
const notifyMemberOfGroup = async (groupId, userId, reason, context) => {
|
||||
const { user: owner } = context
|
||||
const cypher = `
|
||||
MATCH (group:Group { id: $groupId })<-[membership:MEMBER_OF]-(user:User { id: $userId })
|
||||
MATCH (user:User { id: $userId })
|
||||
MATCH (group:Group { id: $groupId })
|
||||
WITH user, group
|
||||
MERGE (group)-[notification:NOTIFIED {reason: $reason}]->(user)
|
||||
WITH group, user, notification
|
||||
SET notification.read = FALSE
|
||||
SET notification.createdAt = COALESCE(notification.createdAt, toString(datetime()))
|
||||
SET notification.updatedAt = toString(datetime())
|
||||
SET notification.relatedUserId = $userId
|
||||
SET notification.relatedUserId = $ownerId
|
||||
RETURN notification {.*, from: group, to: properties(user)}
|
||||
`
|
||||
const session = context.driver.session()
|
||||
@ -177,6 +190,7 @@ const notifyMemberOfGroup = async (groupId, userId, reason, context) => {
|
||||
groupId,
|
||||
reason,
|
||||
userId,
|
||||
ownerId: owner.id,
|
||||
})
|
||||
return notificationTransactionResponse.records.map((record) => record.get('notification'))
|
||||
})
|
||||
@ -287,5 +301,6 @@ export default {
|
||||
JoinGroup: handleJoinGroup,
|
||||
LeaveGroup: handleLeaveGroup,
|
||||
ChangeGroupMemberRole: handleChangeGroupMemberRole,
|
||||
RemoveUserFromGroup: handleRemoveUserFromGroup,
|
||||
},
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ import {
|
||||
joinGroupMutation,
|
||||
leaveGroupMutation,
|
||||
changeGroupMemberRoleMutation,
|
||||
// removeUserFromGroupMutation,
|
||||
removeUserFromGroupMutation,
|
||||
} from '../../graphql/groups'
|
||||
|
||||
let server, query, mutate, notifiedUser, authenticatedUser
|
||||
@ -803,7 +803,7 @@ describe('notifications', () => {
|
||||
id: 'closed-group',
|
||||
},
|
||||
relatedUser: {
|
||||
id: 'you',
|
||||
id: 'group-owner',
|
||||
},
|
||||
},
|
||||
],
|
||||
@ -812,5 +812,53 @@ describe('notifications', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('user is removed from group', () => {
|
||||
beforeEach(async () => {
|
||||
authenticatedUser = await notifiedUser.toJson()
|
||||
await mutate({
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'closed-group',
|
||||
userId: authenticatedUser.id,
|
||||
},
|
||||
})
|
||||
authenticatedUser = await groupOwner.toJson()
|
||||
await mutate({
|
||||
mutation: removeUserFromGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'closed-group',
|
||||
userId: 'you',
|
||||
},
|
||||
})
|
||||
authenticatedUser = await notifiedUser.toJson()
|
||||
})
|
||||
|
||||
it('has notification in database', async () => {
|
||||
await expect(
|
||||
query({
|
||||
query: notificationQuery,
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
data: {
|
||||
notifications: [
|
||||
{
|
||||
read: false,
|
||||
reason: 'removed_user_from_group',
|
||||
createdAt: expect.any(String),
|
||||
from: {
|
||||
__typename: 'Group',
|
||||
id: 'closed-group',
|
||||
},
|
||||
relatedUser: {
|
||||
id: 'group-owner',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -25,6 +25,7 @@ enum NotificationReason {
|
||||
user_joined_group
|
||||
user_left_group
|
||||
changed_group_member_role
|
||||
removed_user_from_group
|
||||
}
|
||||
|
||||
type Query {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user