Skip to content

Commit

Permalink
Merge pull request #1250 from Giveth/hotfix_disable_notification_center
Browse files Browse the repository at this point in the history
Release: Hotfix disable notification center
  • Loading branch information
CarlosQ96 authored Jan 17, 2024
2 parents 088f5ac + 0934dfd commit 26cb144
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 114 deletions.
10 changes: 10 additions & 0 deletions config/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,13 @@ DISABLE_SERVER_RATE_LIMITER=false
DISABLE_SERVER_CORS=false

SOLANA_NODE_RPC_URL=
SOLANA_MAINNET_NODE_RPC_URL=
SOLANA_DEVNET_NODE_RPC_URL=
SOLANA_TEST_NODE_RPC_URL=
ENABLE_IMPORT_LOST_DONATIONS=
IMPORT_LOST_DONATIONS_CRONJOB_EXPRESSION=
LOST_DONATIONS_TX_HASHES=
LOST_DONATIONS_QF_ROUND=
LOST_DONATIONS_NETWORK_ID=

DISABLE_NOTIFICATION_CENTER=
12 changes: 12 additions & 0 deletions config/test.env
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,15 @@ MATCHING_FUND_DONATIONS_FROM_ADDRESS=0x6e8873085530406995170Da467010565968C7C62
DISABLE_SERVER_RATE_LIMITER=false
DISABLE_SERVER_CORS=false
SOLANA_NODE_RPC_URL=

SOLANA_MAINNET_NODE_RPC_URL=
SOLANA_DEVNET_NODE_RPC_URL=
SOLANA_TEST_NODE_RPC_URL=

ENABLE_IMPORT_LOST_DONATIONS=false
IMPORT_LOST_DONATIONS_CRONJOB_EXPRESSION=
LOST_DONATIONS_TX_HASHES=0x4012421fbc2cecc85804f3b98bdd31bef04589dbac8292deca33e699868af01f,0x067e91368272dc73bc715a21a2af863a333cde20f410189fa53bceaa9cb8c86b
LOST_DONATIONS_QF_ROUND=
LOST_DONATIONS_NETWORK_ID=10

DISABLE_NOTIFICATION_CENTER=false
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "giveth-graphql-api",
"version": "1.18.0",
"version": "1.19.0",
"description": "Backend GraphQL server for Giveth originally forked from Topia",
"main": "./dist/index.js",
"dependencies": {
Expand Down
216 changes: 105 additions & 111 deletions src/adapters/notifications/NotificationCenterAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { buildProjectLink } from './NotificationCenterUtils';
const notificationCenterUsername = process.env.NOTIFICATION_CENTER_USERNAME;
const notificationCenterPassword = process.env.NOTIFICATION_CENTER_PASSWORD;
const notificationCenterBaseUrl = process.env.NOTIFICATION_CENTER_BASE_URL;
const disableNotificationCenter = process.env.DISABLE_NOTIFICATION_CENTER;

const numberOfSendNotificationsConcurrentJob =
Number(
Expand Down Expand Up @@ -85,6 +86,8 @@ export class NotificationCenterAdapter implements NotificationAdapterInterface {
donation: Donation;
project: Project;
}): Promise<void> {
if (params.donation.valueUsd <= 1) return;

const { project, donation } = params;
const user = project.adminUser as User;
await sendProjectRelatedNotificationsQueue.add({
Expand Down Expand Up @@ -113,36 +116,37 @@ export class NotificationCenterAdapter implements NotificationAdapterInterface {
project: Project;
donor: User;
}): Promise<void> {
const { project, donor, donation } = params;
await sendProjectRelatedNotificationsQueue.add({
project,
eventName: NOTIFICATIONS_EVENT_NAMES.MADE_DONATION,
user: {
email: donor.email,
walletAddress: donor.walletAddress as string,
},
sendEmail: true,
segment: {
analyticsUserId: donor.segmentUserId(),
anonymousId: donor.segmentUserId(),
payload: {
...getSegmentDonationAttributes({
donation,
project,
user: donor,
}),

// We just want this to be donation sent event not made donation, so don put it in getSegmentDonationAttributes()
// see https://github.com/Giveth/impact-graph/pull/716
fromWalletAddress: donation.fromWalletAddress.toLowerCase(),
},
},
trackId:
'donation-sent-' +
donation.transactionNetworkId +
'-' +
donation.transactionId,
});
return;
// const { project, donor, donation } = params;
// await sendProjectRelatedNotificationsQueue.add({
// project,
// eventName: projectEdited.MADE_DONATION,
// user: {
// email: donor.email,
// walletAddress: donor.walletAddress as string,
// },
// sendEmail: true,
// segment: {
// analyticsUserId: donor.segmentUserId(),
// anonymousId: donor.segmentUserId(),
// payload: {
// ...getSegmentDonationAttributes({
// donation,
// project,
// user: donor,
// }),

// // We just want this to be donation sent event not made donation, so don put it in getSegmentDonationAttributes()
// // see https://github.com/Giveth/impact-graph/pull/716
// fromWalletAddress: donation.fromWalletAddress.toLowerCase(),
// },
// },
// trackId:
// 'donation-sent-' +
// donation.transactionNetworkId +
// '-' +
// donation.transactionId,
// });
}

async projectVerified(params: { project: Project }): Promise<void> {
Expand Down Expand Up @@ -405,19 +409,20 @@ export class NotificationCenterAdapter implements NotificationAdapterInterface {
project: Project;
userId: number;
}): Promise<void> {
const { project } = params;
await sendProjectRelatedNotificationsQueue.add({
project,
eventName: NOTIFICATIONS_EVENT_NAMES.PROJECT_RECEIVED_HEART,

// With adding trackId to notification, notification-center would not create new notification
// If there is already a notification with this trackId in DB
trackId: generateTrackId({
userId: params.userId,
projectId: project?.id as number,
action: 'likeProject',
}),
});
return;
// const { project } = params;
// await sendProjectRelatedNotificationsQueue.add({
// project,
// eventName: NOTIFICATIONS_EVENT_NAMES.PROJECT_RECEIVED_HEART,

// // With adding trackId to notification, notification-center would not create new notification
// // If there is already a notification with this trackId in DB
// trackId: generateTrackId({
// userId: params.userId,
// projectId: project?.id as number,
// action: 'likeProject',
// }),
// });
}

ProfileIsCompleted(params: { user: User }): Promise<void> {
Expand Down Expand Up @@ -628,27 +633,29 @@ export class NotificationCenterAdapter implements NotificationAdapterInterface {
});
}

// commenting for now to test load of notification center.
async projectEdited(params: { project: Project }): Promise<void> {
const { project } = params;
const projectOwner = project?.adminUser as User;
const now = Date.now();

await sendProjectRelatedNotificationsQueue.add({
project,
eventName: NOTIFICATIONS_EVENT_NAMES.PROJECT_EDITED,

sendEmail: true,
segment: {
analyticsUserId: projectOwner.segmentUserId(),
anonymousId: projectOwner.segmentUserId(),
payload: getSegmentProjectAttributes({
project,
}),
},
trackId: `project-edited-${
project.id
}-${projectOwner.walletAddress?.toLowerCase()}-${now}`,
});
return;
// const { project } = params;
// const projectOwner = project?.adminUser as User;
// const now = Date.now();

// await sendProjectRelatedNotificationsQueue.add({
// project,
// eventName: NOTIFICATIONS_EVENT_NAMES.PROJECT_EDITED,

// sendEmail: true,
// segment: {
// analyticsUserId: projectOwner.segmentUserId(),
// anonymousId: projectOwner.segmentUserId(),
// payload: getSegmentProjectAttributes({
// project,
// }),
// },
// trackId: `project-edited-${
// project.id
// }-${projectOwner.walletAddress?.toLowerCase()}-${now}`,
// });
}
async projectGotDraftByAdmin(params: { project: Project }): Promise<void> {
const { project } = params;
Expand All @@ -673,31 +680,31 @@ export class NotificationCenterAdapter implements NotificationAdapterInterface {
}

async projectPublished(params: { project: Project }): Promise<void> {
const { project } = params;
const projectOwner = project?.adminUser as User;
const now = Date.now();

await sendProjectRelatedNotificationsQueue.add({
project,
eventName: NOTIFICATIONS_EVENT_NAMES.DRAFTED_PROJECT_ACTIVATED,

sendEmail: true,
segment: {
analyticsUserId: projectOwner.segmentUserId(),
anonymousId: projectOwner.segmentUserId(),
payload: getSegmentProjectAttributes({
project,
}),
},
trackId: `project-published-${
project.id
}-${projectOwner.walletAddress?.toLowerCase()}-${now}`,
});
return;
// const { project } = params;
// const projectOwner = project?.adminUser as User;
// const now = Date.now();

// await sendProjectRelatedNotificationsQueue.add({
// project,
// eventName: NOTIFICATIONS_EVENT_NAMES.DRAFTED_PROJECT_ACTIVATED,

// sendEmail: true,
// segment: {
// analyticsUserId: projectOwner.segmentUserId(),
// anonymousId: projectOwner.segmentUserId(),
// payload: getSegmentProjectAttributes({
// project,
// }),
// },
// trackId: `project-published-${
// project.id
// }-${projectOwner.walletAddress?.toLowerCase()}-${now}`,
// });
}

async projectReactivated(params: { project: Project }): Promise<void> {
const { project } = params;
const projectOwner = project?.adminUser as User;
const now = Date.now();
const supporters = await findUsersWhoSupportProject(project.id);
await sendProjectRelatedNotificationsQueue.addBulk(
Expand All @@ -713,23 +720,6 @@ export class NotificationCenterAdapter implements NotificationAdapterInterface {
},
})),
);

await sendProjectRelatedNotificationsQueue.add({
project,
eventName: NOTIFICATIONS_EVENT_NAMES.PROJECT_ACTIVATED,

sendEmail: true,
segment: {
analyticsUserId: projectOwner.segmentUserId(),
anonymousId: projectOwner.segmentUserId(),
payload: getSegmentProjectAttributes({
project,
}),
},
trackId: `project-reactivated-${
project.id
}-${projectOwner.walletAddress?.toLowerCase()}-${now}`,
});
}

async projectSavedAsDraft(params: { project: Project }): Promise<void> {
Expand Down Expand Up @@ -954,11 +944,13 @@ const callSendNotification = async (
data: SendNotificationBody,
): Promise<void> => {
try {
await axios.post(`${notificationCenterBaseUrl}/notifications`, data, {
headers: {
Authorization: authorizationHeader(),
},
});
if (disableNotificationCenter !== 'true') {
await axios.post(`${notificationCenterBaseUrl}/notifications`, data, {
headers: {
Authorization: authorizationHeader(),
},
});
}
} catch (e) {
logger.error('callSendNotification error', {
errorResponse: e?.response?.data,
Expand All @@ -973,11 +965,13 @@ const callBatchNotification = async (
data: SendBatchNotificationBody,
): Promise<void> => {
try {
await axios.post(`${notificationCenterBaseUrl}/notificationsBulk`, data, {
headers: {
Authorization: authorizationHeader(),
},
});
if (disableNotificationCenter !== 'true') {
await axios.post(`${notificationCenterBaseUrl}/notificationsBulk`, data, {
headers: {
Authorization: authorizationHeader(),
},
});
}
} catch (e) {
logger.error('callBatchNotification error', {
errorResponse: e?.response?.data,
Expand Down
1 change: 1 addition & 0 deletions src/resolvers/reactionResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export class ReactionResolver {
project,
userId: user.userId,
});

return reaction;
} catch (e) {
logger.error('like project error', e);
Expand Down

0 comments on commit 26cb144

Please sign in to comment.