Page MenuHomePhabricator

D5311.diff
No OneTemporary

D5311.diff

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<string> = values(policyTypes);
+
+export type PolicyType = $Values<typeof policyTypes>;

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 16, 1:55 AM (21 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2496070
Default Alt Text
D5311.diff (1 KB)

Event Timeline