Skip to content

Commit

Permalink
send notification based on user notification settings
Browse files Browse the repository at this point in the history
  • Loading branch information
vhcsilva committed Jul 22, 2024
1 parent eb377db commit d4894b6
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 72 deletions.
30 changes: 1 addition & 29 deletions src/actions/get-bounty-closed-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,6 @@ export async function action(block: DecodedLog, query?: EventsQuery): Promise<Ev

const {tokenAmount, fundingAmount, rewardAmount, rewardToken, transactional} = bounty;

const targets = [(await dbBounty.getUser({
attributes: ["email", "id"],
include: [{association: "user_settings"}]
})).get()]

const AnalyticsEvent = {
name: AnalyticEventName.BOUNTY_CLOSED,
params: {
Expand All @@ -197,30 +192,7 @@ export async function action(block: DecodedLog, query?: EventsQuery): Promise<Ev
}
};

const NotificationEvent = {
name: AnalyticEventName.NOTIF_TASK_CLOSED,
params: {
targets,
task: {
title: dbBounty.title,
id: dbBounty.id,
createdAt: dbBounty.createdAt,
network: dbBounty.network.name,
link: `${dbBounty.network.name}/task/${dbBounty.id}`
},
proposal: {
id: dbProposal.id,
link: `${dbBounty.network.name}/task/${dbBounty.id}/proposal/${dbProposal.id}`,
},
deliverable: {
title: deliverable.title,
id: deliverable.id,
link: `${dbBounty.network.name}/task/${dbBounty.id}/deliverable/${dbProposal.id}`
},
}
}

Push.events([AnalyticsEvent, NotificationEvent]);
Push.events([AnalyticsEvent]);

return eventsProcessed;
}
1 change: 1 addition & 0 deletions src/actions/get-bounty-created-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export async function action(block: DecodedLog<BountyCreatedEvent['returnValues'
? AnalyticEventName.NOTIF_TASK_FUNDING_CREATED
: AnalyticEventName.NOTIF_TASK_CREATED,
params: {
bountyId: dbBounty.id,
creator: {
address: dbBounty.user?.address,
username: dbBounty.user?.handle,
Expand Down
1 change: 1 addition & 0 deletions src/actions/get-proposal-created-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export async function action(block: DecodedLog<BountyProposalCreatedEvent['retur
const NotificationEvent = {
name: AnalyticEventName.NOTIF_PROPOSAL_OPEN,
params: {
bountyId: dbBounty.id,
creator: {
address: createProposal.creator,
username: createProposal.handle,
Expand Down
27 changes: 1 addition & 26 deletions src/actions/get-pullrequest-created-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ export async function action(block: DecodedLog<BountyPullRequestCreatedEvent['re
};

sendMessageToTelegramChannels(DELIVERABLE_OPEN(dbBounty, dbDeliverable, dbDeliverable.id));

const targets = [(await dbBounty.getUser({attributes: ["email", "id"], include:[{ association: "user_settings" }] })).get()]

const AnalyticEvent = {
name: AnalyticEventName.PULL_REQUEST_OPEN,
Expand All @@ -82,30 +80,7 @@ export async function action(block: DecodedLog<BountyPullRequestCreatedEvent['re
}
}

const NotificationEvent = {
name: AnalyticEventName.NOTIF_DELIVERABLE_CREATED,
params: {
targets,
creator: {
address: dbDeliverable.user.address,
id: dbDeliverable.user.id,
username: dbDeliverable.user.handle,
},
task: {
id: dbDeliverable.bountyId,
title: dbBounty.title,
network: dbBounty.network.name,
},
deliverable: {
title: dbDeliverable.title,
id: dbDeliverable.id,
createdAt: dbDeliverable.createdAt,
link: `${dbBounty.network.name}/task/${dbBounty.id}/deliverable/${dbDeliverable.id}`
}
}
}

Push.events([AnalyticEvent, NotificationEvent])
Push.events([AnalyticEvent])

return eventsProcessed;
}
45 changes: 30 additions & 15 deletions src/actions/get-pullrequest-ready-for-review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {BOUNTY_STATE_CHANGED} from "../integrations/telegram/messages";
import {Push} from "../services/analytics/push";
import {AnalyticEventName} from "../services/analytics/types/events";
import updateSeoCardBounty from "src/modules/handle-seo-card";
import {Op} from "sequelize";
import {Op, Sequelize} from "sequelize";

export const name = "getBountyPullRequestReadyForReviewEvents";
export const schedule = "*/12 * * * *";
Expand All @@ -22,7 +22,6 @@ export async function action(block: DecodedLog<BountyPullRequestReadyForReviewEv

const {returnValues: {bountyId, pullRequestId}, connection, address, chainId} = block;


const bounty = await getBountyFromChain(connection, address, bountyId, name);
if (!bounty)
return eventsProcessed;
Expand All @@ -42,25 +41,23 @@ export async function action(block: DecodedLog<BountyPullRequestReadyForReviewEv
return eventsProcessed;
}


const pullRequest = bounty.pullRequests[pullRequestId];

const dbDeliverable = await db.deliverables.findOne({
where: {id: pullRequest.cid},
where: {id: pullRequest.cid, markedReadyForReview: false},
include: {association: 'user'}
})
});

if (!dbDeliverable) {
logger.warn(`${name} No deliverable found with "draft" and id ${pullRequest.cid}, maybe it was already parsed?`);
return eventsProcessed;
}

dbDeliverable.canceled = pullRequest.canceled
dbDeliverable.markedReadyForReview = pullRequest?.ready
dbDeliverable.canceled = pullRequest.canceled;
dbDeliverable.markedReadyForReview = pullRequest?.ready;

await dbDeliverable.save();


if (!["canceled", "closed", "proposal"].includes(dbBounty.state!)) {
dbBounty.state = "ready";
await dbBounty.save();
Expand All @@ -77,12 +74,29 @@ export async function action(block: DecodedLog<BountyPullRequestReadyForReviewEv
(async () => {
const owner = await dbBounty!.getUser({attributes: ["email", "id"], include:[{ association: "user_settings" }] });

const curators = await dbBounty!.network.getCurators({
include: [{association: "user", attributes: ["email", "id"], include:[{association: "user_settings"}]}],
where: {userId: {[Op.not]: owner.id }, isCurrentlyCurator: true}
const curators = await db.curators.findAll({
include: [
{
association: "user",
required: true,
attributes: ["email", "id"],
where: {
id: {
[Op.not]: owner.id
},
},
on: Sequelize.where(Sequelize.fn("lower", Sequelize.col("curators.address")),
"=",
Sequelize.fn("lower", Sequelize.col("user.address"))),
}
],
where: {
networkId: dbBounty.network_id,
isCurrentlyCurator: true
}
});

const targets = curators.map(curators => curators.user.get())
const targets = curators.map(curators => curators.user);

const AnalyticEvent = {
name: AnalyticEventName.PULL_REQUEST_READY,
Expand All @@ -92,12 +106,13 @@ export async function action(block: DecodedLog<BountyPullRequestReadyForReviewEv
deliverableId: dbDeliverable.id, deliverableContractId: pullRequestId,
actor: pullRequest.creator,
}
}
};

const NotificationEvent = {
name: AnalyticEventName.NOTIF_DELIVERABLE_READY,
params: {
targets: [...targets, owner],
bountyId: dbBounty.id,
creator: {
address: dbDeliverable.user.address,
id: dbDeliverable.user.id,
Expand All @@ -114,9 +129,9 @@ export async function action(block: DecodedLog<BountyPullRequestReadyForReviewEv
link: `${dbBounty.network.name}/task/${dbBounty.id}/deliverable/${dbDeliverable.id}`
}
}
}
};

Push.events([AnalyticEvent, NotificationEvent])
Push.events([AnalyticEvent, NotificationEvent]);
})()


Expand Down
3 changes: 3 additions & 0 deletions src/modules/dispute-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export async function disputeProcessor(block: DecodedLog<BountyProposalDisputedE
if (curator)
await updateCuratorProposalParams(curator, "disputedProposals", "add");

await dbProposal.reload();

const AnalyticalEvent = {
name: AnalyticEventName.MERGE_PROPOSAL_DISPUTED,
params: {
Expand All @@ -78,6 +80,7 @@ export async function disputeProcessor(block: DecodedLog<BountyProposalDisputedE
const NotificationEvent = {
name: AnalyticEventName.NOTIF_PROPOSAL_DISPUTED,
params: {
bountyId: dbBounty.id,
creator: {
address: actorAddress,
},
Expand Down
4 changes: 2 additions & 2 deletions src/services/analytics/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const AnalyticsEvents: AnalyticEventPool = {
[AnalyticEventName.LOCK_UNLOCK_NETWORK]: [analytic(AnalyticTypes.ElasticSearch)],
[AnalyticEventName.DELEGATE_UNDELEGATE]: [analytic(AnalyticTypes.ElasticSearch)],
[AnalyticEventName.LOCK_UNLOCK_REGISTRY]: [analytic(AnalyticTypes.ElasticSearch)],
[AnalyticEventName.PULL_REQUEST_OPEN]: [analytic(AnalyticTypes.ElasticSearch), analytic(AnalyticTypes.EmailNotification)],
[AnalyticEventName.PULL_REQUEST_OPEN]: [analytic(AnalyticTypes.ElasticSearch)],
[AnalyticEventName.PULL_REQUEST_READY]: [analytic(AnalyticTypes.ElasticSearch), analytic(AnalyticTypes.EmailNotification)],
[AnalyticEventName.PULL_REQUEST_CANCELED]: [analytic(AnalyticTypes.ElasticSearch)],
[AnalyticEventName.PULL_REQUEST_MERGED]: [analytic(AnalyticTypes.ElasticSearch)],
Expand All @@ -25,7 +25,7 @@ export const AnalyticsEvents: AnalyticEventPool = {
[AnalyticEventName.REGISTRY_UPDATED]: [analytic(AnalyticTypes.ElasticSearch)],
[AnalyticEventName.NOTIF_TASK_CREATED]: [analytic(AnalyticTypes.CreateNotification)],
[AnalyticEventName.NOTIF_TASK_FUNDING_CREATED]: [analytic(AnalyticTypes.CreateNotification)],
[AnalyticEventName.NOTIF_DELIVERABLE_CREATED]: [analytic(AnalyticTypes.CreateNotification)],
[AnalyticEventName.NOTIF_DELIVERABLE_CREATED]: [],
[AnalyticEventName.NOTIF_DELIVERABLE_READY]: [analytic(AnalyticTypes.CreateNotification)],
[AnalyticEventName.NOTIF_PROPOSAL_OPEN]: [analytic(AnalyticTypes.CreateNotification)],
[AnalyticEventName.NOTIF_PROPOSAL_DISPUTED]: [analytic(AnalyticTypes.CreateNotification)],
Expand Down

0 comments on commit d4894b6

Please sign in to comment.