diff --git a/keyserver/src/updaters/viewer-acknowledgment-updater.js b/keyserver/src/updaters/viewer-acknowledgment-updater.js new file mode 100644 index 000000000..506245668 --- /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 index b49c25498..20f4be30a 100644 --- a/lib/facts/policies.js +++ b/lib/facts/policies.js @@ -1,9 +1,11 @@ // @flow import { values } from '../utils/objects.js'; export const policyTypes = Object.freeze({ tosAndPrivacyPolicy: 'TERMS_OF_USE_AND_PRIVACY_POLICY', }); export const policies: $ReadOnlyArray = values(policyTypes); + +export type PolicyType = $Values;