From 8346630969f42ca42556adedded55838aa014547 Mon Sep 17 00:00:00 2001 From: Raymond Jacobson Date: Fri, 13 Oct 2023 17:48:35 -0700 Subject: [PATCH] Fix verified check because of identity time drift (#6306) Co-authored-by: Alec Savvy --- .../verified-uploads/src/handlers/users.js | 90 ++++++++++++------- 1 file changed, 59 insertions(+), 31 deletions(-) diff --git a/packages/discovery-provider/plugins/verified-uploads/src/handlers/users.js b/packages/discovery-provider/plugins/verified-uploads/src/handlers/users.js index d361335853b..9e5ed235f0e 100644 --- a/packages/discovery-provider/plugins/verified-uploads/src/handlers/users.js +++ b/packages/discovery-provider/plugins/verified-uploads/src/handlers/users.js @@ -29,43 +29,71 @@ export default async ({ user_id, blocknumber }) => { db: dp_db }) - const user_became_verified = current.is_verified !== old.is_verified - const new_user_is_verified = old === undefined && current.is_verified + console.log({ current, old, user_id, blocknumber }) - if (user_became_verified || new_user_is_verified) { + if (current === undefined) { + console.warn( + { user_id, blocknumber }, + 'user does not have a current record' + ) + return + } + + const is_new_user = old === undefined + const new_user_is_verified = is_new_user && current.is_verified + const is_existing_user = !is_new_user + const existing_user_previously_unverified = + is_existing_user && old.is_verified === false + const user_currently_verified = current.is_verified === true + const existing_user_became_verified = + user_currently_verified && existing_user_previously_unverified + + console.log({ + user_id, + existing_user_became_verified, + new_user_is_verified, + is_new_user, + is_existing_user + }) + + if (existing_user_became_verified || new_user_is_verified) { const is_verified = current.is_verified const handle = current.handle - const data = await retry( - async (_) => { - const { data } = await axios - .get(social_handle_url(handle)) - .catch(console.error) - - if (Object.keys(data).length === 0) { - // wait for identity to load - await new Promise((resolve) => { - setTimeout(resolve, 1000) - }) - throw new Error('social handles not in identity yet') - } + let source + try { + const data = await retry( + async (_) => { + const { data } = await axios + .get(social_handle_url(handle)) + .catch(console.error) - return data - }, - { retries: 5 } - ) + if (Object.keys(data).length === 0) { + // wait for identity to load + await new Promise((resolve) => { + setTimeout(resolve, 5000) + }) + throw new Error('social handles not in identity yet') + } - const { twitterVerified, instagramVerified, tikTokVerified } = data + return data + }, + { retries: 100 } + ) + const { twitterVerified, instagramVerified, tikTokVerified } = data - let source = 'unknown' - if (twitterVerified) { - source = 'twitter' - } - if (instagramVerified) { - source = 'instagram' - } - if (tikTokVerified) { - source = 'tiktok' + if (twitterVerified) { + source = 'twitter' + } + if (instagramVerified) { + source = 'instagram' + } + if (tikTokVerified) { + source = 'tiktok' + } + } catch (e) { + source = 'could not figure out source!' + console.error(e) } const header = `User *${handle}* ${ @@ -79,7 +107,7 @@ export default async ({ user_id, blocknumber }) => { source } - console.log({ to_slack: body }, 'sending to slack') + console.log({ to_slack: body }, 'user verification') await slack.sendMsg(USERS_SLACK_CHANNEL, header, body).catch(console.error) } }