Skip to content

Commit

Permalink
fix: bugs in setting notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
ignazio-bovo committed Jul 4, 2023
1 parent c21d415 commit 8862b89
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 56 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/auth-server/handlers/createAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const createAccount: (
}


const notificationPreferences = defaultNotificationPreferences()
const account = new Account({
id: idStringFromNumber(nextAccountId),
email,
Expand All @@ -87,8 +88,8 @@ export const createAccount: (
userId: authContext.user.id,
joystreamAccount: joystreamAccountId,
membershipId: memberId.toString(),
...notificationPreferences,
})
setNotificationPreferences(account, defaultNotificationPreferences())

await em.save([
account,
Expand Down
7 changes: 4 additions & 3 deletions src/auth-server/integration-tests/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ curl --request POST \

echo "*********************************************************************** " >&2
echo "Preferences update: mutate" >&2
curl --request POST \
--url http://localhost:4350/graphql \
curl -i \
--request POST \
--url 'http://localhost:4350/graphql?=' \
--header 'Content-Type: application/json' \
--header "Cookie: session_id=${LOGIN_SESSION_ID}" \
--data '{"query":"mutation SetNotificationPreferences {\n\tsetAccountNotificatioPreferences(\n\t\tauctionBidCanceledInAppNotificationEnabled: false\n\t\tauctionBidCanceledMailNotificationEnabled: false\n\t\tauctionBidMadeInAppNotificationEnabled: false\n\t\tauctionBidMadeMailNotificationEnabled: false\n\t\tauctionCanceledInAppNotificationEnabled: false\n\t\tauctionCanceledMailNotificationEnabled: false\n\t\tbidMadeCompletingAuctionInAppNotificationEnabled: false\n\t\tbidMadeCompletingAuctionMailNotificationEnabled: false\n\t\tbuyNowCanceledInAppNotificationEnabled: false\n\t\tbuyNowCanceledMailNotificationEnabled: false\n\t\tbuyNowPriceUpdatedInAppNotificationEnabled: false\n\t\tbuyNowPriceUpdatedMailNotificationEnabled: false\n\t\tchannelCreatedInAppNotificationEnabled: false\n\t\tchannelCreatedMailNotificationEnabled: false\n\t\tchannelFundsWithdrawnInAppNotificationEnabled: false\n\t\tchannelFundsWithdrawnMailNotificationEnabled: false\n\t\tchannelPaymentMadeInAppNotificationEnabled: false\n\t\tchannelPaymentMadeMailNotificationEnabled: false\n\t\tchannelPayoutsUpdatedInAppNotificationEnabled: false\n\t\tchannelPayoutsUpdatedMailNotificationEnabled: false\n\t\tchannelRewardClaimedAndWithdrawnInAppNotificationEnabled: false\n\t\tchannelRewardClaimedAndWithdrawnMailNotificationEnabled: false\n\t\tchannelRewardClaimedInAppNotificationEnabled: false\n\t\tchannelRewardClaimedMailNotificationEnabled: false\n\t\tcommentCreatedInAppNotificationEnabled: false\n\t\tcommentCreatedMailNotificationEnabled: false\n\t\tcommentTextUpdatedInAppNotificationEnabled: false\n\t\tcommentTextUpdatedMailNotificationEnabled: false\n\t\tenglishAuctionSettledInAppNotificationEnabled: false\n\t\tenglishAuctionSettledMailNotificationEnabled: false\n\t\tenglishAuctionStartedInAppNotificationEnabled: false\n\t\tenglishAuctionStartedMailNotificationEnabled: false\n\t\tmemberBannedFromChannelInAppNotificationEnabled: false\n\t\tmemberBannedFromChannelMailNotificationEnabled: false\n\t\tmetaprotocolTransactionStatusMailNotificationEnabled: false\n\t\tnftBoughtInAppNotificationEnabled: false\n\t\tnftBoughtMailNotificationEnabled: false\n\t\tnftIssuedInAppNotificationEnabled: false\n\t\tnftIssuedMailNotificationEnabled: false\n\t\tnftSellOrderMadeInAppNotificationEnabled: false\n\t\tnftSellOrderMadeMailNotificationEnabled: false\n\t\topenAuctionBidAcceptedInAppNotificationEnabled: false\n\t\topenAuctionBidAcceptedMailNotificationEnabled: false\n\t\topenAuctionStartedInAppNotificationEnabled: false\n\t\topenAuctionStartedMailNotificationEnabled: false\n\t\tmetaprotocolTransactionStatusInAppNotificationEnabled: false\n\t)\n}\n","operationName":"SetNotificationPreferences"}'
--data '{"query":"mutation SetAccountNotificationPrefences {\n\tsetAccountNotificationPreferences(\n\t\tauctionBidCanceledInAppNotificationEnabled: false\n\t\tauctionBidCanceledMailNotificationEnabled: false\n\t\tauctionBidMadeInAppNotificationEnabled: false\n\t\tauctionBidMadeMailNotificationEnabled: false\n\t\tauctionCanceledInAppNotificationEnabled: false\n\t\tauctionCanceledMailNotificationEnabled: false\n\t\tbidMadeCompletingAuctionInAppNotificationEnabled: false\n\t\tbidMadeCompletingAuctionMailNotificationEnabled: false\n\t\tbuyNowCanceledMailNotificationEnabled: false\n\t\tbuyNowPriceUpdatedInAppNotificationEnabled: false\n\t\tbuyNowPriceUpdatedMailNotificationEnabled: false\n\t\tchannelCreatedInAppNotificationEnabled: false\n\t\tchannelCreatedMailNotificationEnabled: false\n\t\tchannelFundsWithdrawnInAppNotificationEnabled: false\n\t\tchannelFundsWithdrawnMailNotificationEnabled: false\n\t\tchannelPaymentMadeInAppNotificationEnabled: false\n\t\tchannelPaymentMadeMailNotificationEnabled: false\n\t\tchannelPayoutsUpdatedInAppNotificationEnabled: false\n\t\tchannelPayoutsUpdatedMailNotificationEnabled: false\n\t\tchannelRewardClaimedAndWithdrawnInAppNotificationEnabled: false\n\t\tchannelRewardClaimedAndWithdrawnMailNotificationEnabled: false\n\t\tchannelRewardClaimedInAppNotificationEnabled: false\n\t\tchannelRewardClaimedMailNotificationEnabled: false\n\t\tcommentCreatedInAppNotificationEnabled: false\n\t\tcommentCreatedMailNotificationEnabled: false\n\t\tcommentTextUpdatedInAppNotificationEnabled: false\n\t\tcommentTextUpdatedMailNotificationEnabled: false\n\t\tenglishAuctionSettledInAppNotificationEnabled: false\n\t\tenglishAuctionSettledMailNotificationEnabled: false\n\t\tenglishAuctionStartedInAppNotificationEnabled: false\n\t\tenglishAuctionStartedMailNotificationEnabled: false\n\t\tmemberBannedFromChannelInAppNotificationEnabled: false\n\t\tmemberBannedFromChannelMailNotificationEnabled: false\n\t\tmetaprotocolTransactionStatusInAppNotificationEnabled: false\n\t\tmetaprotocolTransactionStatusMailNotificationEnabled: false\n\t\tnewChannelFollowerInAppNotificationPreferences: false\n\t\tnewChannelFollowerMailNotificationPreferences: false\n\t\tnftBoughtInAppNotificationEnabled: false\n\t\tnftBoughtMailNotificationEnabled: false\n\t\tnftIssuedMailNotificationEnabled: false\n\t\tnftSellOrderMadeInAppNotificationEnabled: false\n\t\tnftSellOrderMadeMailNotificationEnabled: false\n\t\topenAuctionBidAcceptedInAppNotificationEnabled: false\n\t\topenAuctionBidAcceptedMailNotificationEnabled: false\n\t\topenAuctionStartedInAppNotificationEnabled: false\n\t\topenAuctionStartedMailNotificationEnabled: false\n\t)\n}\n","operationName":"SetAccountNotificationPrefences"}'

echo "*********************************************************************** " >&2
echo "Notification visibility as an anon user" >&2
Expand Down
9 changes: 8 additions & 1 deletion src/mappings/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ export async function addNotificationForRuntimeData(
const notificationAlreadyProcessedInThePast = await overlay
.getRepository(RuntimeNotificationProcessed)
.getOneByRelation('runtimeNotificationId', newNotificationId)

console.log("account", JSON.stringify(account))
console.log("notificationId", newNotificationId)
console.log("event", event.id)
console.log("type", JSON.stringify(type))

repository.new({
id: newNotificationId,
accountId: account.id,
Expand All @@ -118,9 +124,10 @@ export async function addNotificationForRuntimeData(
})
if (!notificationAlreadyProcessedInThePast) {
const notificationProcessed = overlay.getRepository(RuntimeNotificationProcessed).new({
id: newNotificationId,
id: overlay.getRepository(RuntimeNotificationProcessed).getNewEntityId(),
inAppRead: false,
mailSent: false,
runtimeNotificationId: newNotificationId,
})
if (shouldSendMail) {
mailNotifier.setReciever(account.email)
Expand Down
6 changes: 3 additions & 3 deletions src/server-extension/resolvers/NotificationResolver/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { NotificationArgs, SetNotificationPreferencesArgs } from './types'
@Resolver()
export class NotificationResolver {
// Set by depenency injection
constructor(private em: () => Promise<EntityManager>) {}
constructor(private em: () => Promise<EntityManager>) { }

@Mutation(() => Boolean)
@UseMiddleware(AccountOnly)
Expand Down Expand Up @@ -124,7 +124,7 @@ export class NotificationResolver {

@Mutation(() => Boolean)
@UseMiddleware(AccountOnly)
async setAccountNotificatioPreferences(
async setAccountNotificationPreferences(
@Args() notificationPreferences: SetNotificationPreferencesArgs,
@Ctx() ctx: Context
): Promise<Boolean> {
Expand Down Expand Up @@ -263,7 +263,7 @@ export class NotificationResolver {
memberBannedFromChannelMailNotificationEnabled
account.channelCreatedMailNotificationEnabled = channelCreatedMailNotificationEnabled

await em.save(notificationPreferences)
await em.save(account)
return true
}
return false
Expand Down
94 changes: 48 additions & 46 deletions src/server-extension/resolvers/NotificationResolver/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,95 +8,97 @@ export class NotificationArgs {
@ArgsType()
export class SetNotificationPreferencesArgs {
@Field(() => Boolean, { nullable: false })
commentCreatedInAppNotificationEnabled!: boolean
commentCreatedInAppNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
commentTextUpdatedInAppNotificationEnabled!: boolean
commentTextUpdatedInAppNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
openAuctionStartedInAppNotificationEnabled!: boolean
openAuctionStartedInAppNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
englishAuctionStartedInAppNotificationEnabled!: boolean
englishAuctionStartedInAppNotificationEnabled: boolean
nftIssuedInAppNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
nftIssuedInAppNotificationEnabled!: boolean
auctionBidMadeInAppNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
auctionBidMadeInAppNotificationEnabled!: boolean
auctionBidCanceledInAppNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
auctionBidCanceledInAppNotificationEnabled!: boolean
auctionCanceledInAppNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
auctionCanceledInAppNotificationEnabled!: boolean
englishAuctionSettledInAppNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
englishAuctionSettledInAppNotificationEnabled!: boolean
bidMadeCompletingAuctionInAppNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
bidMadeCompletingAuctionInAppNotificationEnabled!: boolean
openAuctionBidAcceptedInAppNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
openAuctionBidAcceptedInAppNotificationEnabled!: boolean
nftSellOrderMadeInAppNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
nftSellOrderMadeInAppNotificationEnabled!: boolean
nftBoughtInAppNotificationEnabled: boolean
buyNowCanceledInAppNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
nftBoughtInAppNotificationEnabled!: boolean
buyNowPriceUpdatedInAppNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
buyNowCanceledInAppNotificationEnabled!: boolean
metaprotocolTransactionStatusInAppNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
buyNowPriceUpdatedInAppNotificationEnabled!: boolean
channelRewardClaimedInAppNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
metaprotocolTransactionStatusInAppNotificationEnabled!: boolean
channelRewardClaimedAndWithdrawnInAppNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
channelRewardClaimedInAppNotificationEnabled!: boolean
channelFundsWithdrawnInAppNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
channelRewardClaimedAndWithdrawnInAppNotificationEnabled!: boolean
channelPayoutsUpdatedInAppNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
channelFundsWithdrawnInAppNotificationEnabled!: boolean
channelPaymentMadeInAppNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
channelPayoutsUpdatedInAppNotificationEnabled!: boolean
memberBannedFromChannelInAppNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
channelPaymentMadeInAppNotificationEnabled!: boolean
channelCreatedInAppNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
memberBannedFromChannelInAppNotificationEnabled!: boolean
commentCreatedMailNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
channelCreatedInAppNotificationEnabled!: boolean
commentTextUpdatedMailNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
commentCreatedMailNotificationEnabled!: boolean
openAuctionStartedMailNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
commentTextUpdatedMailNotificationEnabled!: boolean
englishAuctionStartedMailNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
openAuctionStartedMailNotificationEnabled!: boolean
nftIssuedMailNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
englishAuctionStartedMailNotificationEnabled!: boolean
auctionBidMadeMailNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
nftIssuedMailNotificationEnabled!: boolean
auctionBidCanceledMailNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
auctionBidMadeMailNotificationEnabled!: boolean
auctionCanceledMailNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
auctionBidCanceledMailNotificationEnabled!: boolean
englishAuctionSettledMailNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
auctionCanceledMailNotificationEnabled!: boolean
bidMadeCompletingAuctionMailNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
englishAuctionSettledMailNotificationEnabled!: boolean
openAuctionBidAcceptedMailNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
bidMadeCompletingAuctionMailNotificationEnabled!: boolean
nftSellOrderMadeMailNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
openAuctionBidAcceptedMailNotificationEnabled!: boolean
nftBoughtMailNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
nftSellOrderMadeMailNotificationEnabled!: boolean
buyNowCanceledMailNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
nftBoughtMailNotificationEnabled!: boolean
buyNowPriceUpdatedMailNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
buyNowCanceledMailNotificationEnabled!: boolean
metaprotocolTransactionStatusMailNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
buyNowPriceUpdatedMailNotificationEnabled!: boolean
channelRewardClaimedMailNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
metaprotocolTransactionStatusMailNotificationEnabled!: boolean
channelRewardClaimedAndWithdrawnMailNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
channelRewardClaimedMailNotificationEnabled!: boolean
channelFundsWithdrawnMailNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
channelRewardClaimedAndWithdrawnMailNotificationEnabled!: boolean
channelPayoutsUpdatedMailNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
channelFundsWithdrawnMailNotificationEnabled!: boolean
channelPaymentMadeMailNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
channelPayoutsUpdatedMailNotificationEnabled!: boolean
memberBannedFromChannelMailNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
channelPaymentMadeMailNotificationEnabled!: boolean
channelCreatedMailNotificationEnabled: boolean
@Field(() => Boolean, { nullable: false })
memberBannedFromChannelMailNotificationEnabled!: boolean
newChannelFollowerInAppNotificationPreferences: boolean
@Field(() => Boolean, { nullable: false })
channelCreatedMailNotificationEnabled!: boolean
newChannelFollowerMailNotificationPreferences: boolean
}

0 comments on commit 8862b89

Please sign in to comment.