Add previous username to notification

This commit is contained in:
Chi Vinh Le
2018-01-18 20:09:47 +01:00
parent ddf3816f5a
commit 544ef081dc
4 changed files with 24 additions and 7 deletions
+2 -1
View File
@@ -57,7 +57,8 @@ const stopIgnoringUser = ({ user }, userToStopIgnoring) => {
const changeUsername = async (ctx, id, username) => {
const user = await UsersService.changeUsername(id, username, ctx.user.id);
ctx.pubsub.publish('usernameChanged', user);
const previousUsername = ctx.user.username;
ctx.pubsub.publish('usernameChanged', { previousUsername, user });
return user;
};
+1 -1
View File
@@ -129,7 +129,7 @@ const setupFunctions = {
}
return !args.user_id || user.id === args.user_id;
},
usernameChanged: (options, args, user, context) => {
usernameChanged: (options, args, { user }, context) => {
if (
!context.user ||
(args.user_id !== user.id &&
+6 -1
View File
@@ -1465,6 +1465,11 @@ type RootMutation {
stopIgnoringUser(id: ID!): StopIgnoringUserResponse
}
type UsernameChangedPayload {
previousUsername: String
user: User
}
################################################################################
## Subscriptions
################################################################################
@@ -1522,7 +1527,7 @@ type Subscription {
# Get an update whenever a username has been changed. `user_id` must match id
# of current user except for users with the `ADMIN` or `MODERATOR` role.
usernameChanged(user_id: ID): User
usernameChanged(user_id: ID): UsernameChangedPayload
}
################################################################################