diff --git a/keyserver/src/updaters/viewer-acknowledgment-updater.js b/keyserver/src/updaters/viewer-acknowledgment-updater.js new file mode 100644 --- /dev/null +++ b/keyserver/src/updaters/viewer-acknowledgment-updater.js @@ -0,0 +1,23 @@ +// @flow + +import type { PolicyType } from 'lib/facts/policies.js'; + +import { dbQuery, SQL } from '../database/database.js'; +import type { Viewer } from '../session/viewer.js'; + +async function viewerAcknowledgmentUpdater(viewer: Viewer, policy: PolicyType) { + if (!viewer.loggedIn) { + return; + } + + const time = Date.now(); + await dbQuery(SQL` + INSERT INTO policy_acknowledgments (user, policy, date, confirmed) + VALUES (${viewer.data.id}, ${policy}, ${time}, 1) + ON DUPLICATE KEY UPDATE + date = IF (confirmed = 1, date, ${time}), + confirmed = 1 + `); +} + +export { viewerAcknowledgmentUpdater }; diff --git a/lib/facts/policies.js b/lib/facts/policies.js --- a/lib/facts/policies.js +++ b/lib/facts/policies.js @@ -7,3 +7,5 @@ }); export const policies: $ReadOnlyArray = values(policyTypes); + +export type PolicyType = $Values;