Moar await

This commit is contained in:
Basti 2020-04-16 17:33:53 +02:00
parent 60ed697460
commit 960dcb55de
No known key found for this signature in database
GPG Key ID: BE4634D632D39B67

View File

@ -16,15 +16,15 @@ 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(displayName, meeting) { async function createContributionFor (displayName, meeting) {
const contributor = await getContributorByZoomDisplayName(displayName);
return getContributorByZoomDisplayName(displayName)
.then(contributor => {
if (!contributor) { if (!contributor) {
robot.logger.error(`[hubot-kredits] Contributor not found: Zoom display name: ${displayName}`); robot.logger.info(`[hubot-kredits] Contributor not found: Zoom display name: ${displayName}`);
messageRoom(`I tried to add a contribution for zoom user ${displayName}, but did not find a matching contributor profile.`); messageRoom(`I tried to add a contribution for zoom user ${displayName}, but did not find a matching contributor profile.`);
return; return Promise.resolve();
} }
const contribution = { const contribution = {
contributorId: contributor.id, contributorId: contributor.id,
contributorIpfsHash: contributor.ipfsHash, contributorIpfsHash: contributor.ipfsHash,
@ -36,10 +36,12 @@ module.exports = async function(robot, kredits) {
} }
return Contribution.add(contribution, { nonce: nonce++ }) return Contribution.add(contribution, { nonce: nonce++ })
.catch(error => { .then(tx => {
robot.logger.error(`[hubot-kredits] Adding contribution failed:`, error); robot.logger.info(`[hubot-kredits] Contribution created: ${tx.hash}`);
});
}) })
.catch(error => {
robot.logger.error(`[hubot-kredits] Adding contribution for Zoom call failed:`, error);
});
} }
function getContributorByZoomDisplayName(displayName) { function getContributorByZoomDisplayName(displayName) {
@ -72,13 +74,11 @@ 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;
} }
const names = Array.from(new Set(participants.map(p => p.name))); const names = Array.from(new Set(participants.map(p => p.name)));
for (const displayName of names) { for (const displayName of names) {
const tx = createContributionFor(displayName, meetingDetails) await createContributionFor(displayName, meetingDetails);
// if the contributor is not found we do not get a transaction object here
if (tx) {
robot.logger.info(`[hubot-kredits] Contribution created: ${tx.hash}`);
}
}; };
} }