import {STAFF_OFFICE_ACCOUNT_ID} from './organisation-keys.mjs'; import {currentActivityPlayer} from './quest-activity-events.mjs'; import {faithAuthority} from './clan-faith.mjs'; // Count distinct current communities, not invitations, repeated consents or // arbitrary browser counters. Claiming re-reads these same sealed records. export async function faithQuestEvidence(db,{accountId,minecraftUuid,startsAt,endsAt,now,lock=false}){ if(!await currentActivityPlayer(db,accountId,minecraftUuid,{lock}))throw Error('Current faith quest identity required'); const totals=new Map([['pol-faith-muad_dib-conversions',0],['pol-faith-veiled_concord-conversions',0]]),proofIds=[],seen=new Set(); const rows=await db.query("SELECT c.*,o.key_id offer_key,o.office_key,o.state offer_state,f.faith_key current_faith,f.request_id current_request,ck.key_type consent_type,ck.account_id consent_issuer,ck.scope_id consent_scope,ck.revoked_at consent_revoked,ok.key_type offer_type,ok.account_id offer_issuer,ok.scope_id offer_scope,ok.revoked_at offer_revoked FROM jarvis_faith_consents c JOIN jarvis_faith_offers o ON o.request_id=c.offer_id JOIN jarvis_clan_faith f ON f.clan_id=c.clan_id JOIN site_clans clan ON clan.id=c.clan_id AND clan.active=1 JOIN organisation_keys ck ON ck.id=c.key_id JOIN organisation_keys ok ON ok.id=o.key_id WHERE o.actor_id=? AND c.choice='accept' AND c.created_at>=? AND c.created_at