Make sure zoom participants are unique

to make sure we only create one contribution per participants
This commit is contained in:
bumi 2020-04-16 16:32:39 +02:00
parent 164782bd25
commit e7f8723f6e

View File

@ -11,8 +11,7 @@ module.exports = async function(robot, kredits) {
const walletTransactionCount = await kredits.provider.getTransactionCount(kredits.signer.address); const walletTransactionCount = await kredits.provider.getTransactionCount(kredits.signer.address);
let nonce = walletTransactionCount; let nonce = walletTransactionCount;
function createContributionFor(participant, meeting) { function createContributionFor(displayName, meeting) {
const displayName = participant.name;
return getContributorByZoomDisplayName(displayName) return getContributorByZoomDisplayName(displayName)
.then(contributor => { .then(contributor => {
@ -21,7 +20,7 @@ module.exports = async function(robot, kredits) {
contributorIpfsHash: contributor.ipfsHash, contributorIpfsHash: contributor.ipfsHash,
amount: kreditsContributionAmount, amount: kreditsContributionAmount,
kind: kreditsContributionKind, kind: kreditsContributionKind,
description: `Team meeting: ${meeting.topic}`, description: 'Team/Community Call',
date: meeting.end_time.split('T')[0], date: meeting.end_time.split('T')[0],
time: meeting.end_time.split('T')[1] time: meeting.end_time.split('T')[1]
} }
@ -63,12 +62,13 @@ module.exports = async function(robot, kredits) {
robot.logger.info(`[hubot-kredits] Ignoring zoom call ${data.uuid} (duration: ${meetingDetails.duration}, participants_count: ${meetingDetails.participants_count})`); robot.logger.info(`[hubot-kredits] Ignoring zoom call ${data.uuid} (duration: ${meetingDetails.duration}, participants_count: ${meetingDetails.participants_count})`);
return; return;
} }
participants.forEach(p => { const names = Array.from(new Set(participants.map(p => p.name)));
createContributionFor(p, meetingDetails) for(const displayName of names) {
await createContributionFor(displayName, meetingDetails)
.then(tx => { .then(tx => {
robot.logger.info(`[hubot-kredits] Contribution created: ${tx.hash}`); robot.logger.info(`[hubot-kredits] Contribution created: ${tx.hash}`);
})
}); });
};
} }
robot.router.post('/incoming/kredits/zoom/'+process.env.KREDITS_WEBHOOK_TOKEN, (req, res) => { robot.router.post('/incoming/kredits/zoom/'+process.env.KREDITS_WEBHOOK_TOKEN, (req, res) => {