forked from unimatrix/web
15 lines
2.5 KiB
JavaScript
15 lines
2.5 KiB
JavaScript
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<? AND c.created_at<=? ORDER BY c.created_at,c.request_id"+(lock?' FOR SHARE':''),[accountId,startsAt,endsAt,now]);
|
|
const authorities=new Map();
|
|
for(const row of rows){const metric='pol-faith-'+row.faith_key+'-conversions';if(!totals.has(metric)||row.current_faith!==row.faith_key||row.current_request!==row.request_id||row.office_key!==row.faith_key||row.offer_state!=='accepted'||row.consent_type!=='entity-state'||row.consent_issuer!==STAFF_OFFICE_ACCOUNT_ID||row.consent_scope!=='state:clan-faith:'+row.request_id||row.consent_revoked!==null||row.offer_type!=='entity-state'||row.offer_issuer!==STAFF_OFFICE_ACCOUNT_ID||row.offer_scope!=='state:faith-offer:'+row.offer_id||row.offer_revoked!==null||seen.has(row.clan_id))continue;
|
|
if(!authorities.has(row.office_key))authorities.set(row.office_key,await faithAuthority(db,row.office_key,{id:accountId},now,{lock}));const authority=authorities.get(row.office_key);if(!authority||authority.clanIds&&!authority.clanIds.includes(row.clan_id))continue;
|
|
seen.add(row.clan_id);totals.set(metric,totals.get(metric)+1);proofIds.push('faith:'+row.key_id+':'+row.offer_key);}
|
|
return{totals,proofIds};
|
|
}
|

Staff