···1616 #stmt_delete_push_sub;
1717 #stmt_get_push_info;
1818 #stmt_set_role;
1919+ #stmt_get_notify_account_globals;
2020+ #stmt_set_notify_account_globals;
2121+1922 #stmt_admin_add_secret;
2023 #stmt_admin_expire_secret;
2124 #stmt_admin_get_secrets;
···111114 where did = :did
112115 and :secret_password in (select password
113116 from top_secret_passwords)`);
117117+118118+ this.#stmt_get_notify_account_globals = db.prepare(
119119+ `select notify_enabled,
120120+ notify_self
121121+ from accounts
122122+ where did = :did`);
123123+124124+ this.#stmt_set_notify_account_globals = db.prepare(
125125+ `update accounts
126126+ set notify_enabled = :notify_enabled,
127127+ notify_self = :notify_self
128128+ where did = :did`);
129129+114130115131 this.#stmt_admin_add_secret = db.prepare(
116132 `insert into top_secret_passwords (password)
···204220 let res = this.#stmt_set_role.run(params);
205221 return res.changes > 0;
206222 }
223223+224224+ getNotifyAccountGlobals(did) {
225225+ return this.#stmt_get_notify_account_globals.get({ did });
226226+ }
227227+228228+ setNotifyAccountGlobals(did, globals) {
229229+ this.#transactionally(() => {
230230+ const update = this.getNotifyAccountGlobals(did);
231231+ if (globals.notify_enabled !== undefined) update.notify_enabled = +globals.notify_enabled;
232232+ if (globals.notify_self !== undefined) update.notify_self = +globals.notify_self;
233233+ update.did = did;
234234+ this.#stmt_set_notify_account_globals.run(update);
235235+ });
236236+ }
237237+207238208239 addTopSecret(secretPassword) {
209240 this.#stmt_admin_add_secret.run(secretPassword);
+38-6
server/notifications.js
···8484 }
8585};
86868787+const extractUriDid = at_uri => {
8888+ if (!at_uri.startsWith('at://')) {
8989+ console.warn(`ignoring non-at-uri: ${at_uri}`);
9090+ return null;
9191+ }
9292+ const [id, ..._] = at_uri.slice('at://'.length).split('/');
9393+ if (!id) {
9494+ console.warn(`ignoring at-uri with missing id segment: ${at_uri}`);
9595+ return null;
9696+ }
9797+ if (id.startsWith('@')) {
9898+ console.warn(`ignoring @handle at-uri: ${at_uri}`);
9999+ return null;
100100+ }
101101+ if (!id.startsWith('did:')) {
102102+ console.warn(`ignoring non-did at-uri: ${at_uri}`);
103103+ return null;
104104+ }
105105+ return id;
106106+};
107107+87108const handleDust = db => async event => {
88109 console.log('got', event.data);
89110 let data;
···100121 }
101122 const timestamp = +new Date();
102123103103- let did;
104104- if (subject.startsWith('did:')) did = subject;
105105- else if (subject.startsWith('at://')) {
106106- const [id, ..._] = subject.slice('at://'.length).split('/');
107107- if (id.startsWith('did:')) did = id;
108108- }
124124+ const did = subject.startsWith('did:') ? subject : extractUriDid(subject);
109125 if (!did) {
110126 console.warn(`ignoring link with non-DID subject: ${subject}`)
111127 return;
128128+ }
129129+130130+ // this works for now since only the account owner is assumed to be a notification target
131131+ // but for "replies on post" etc that won't hold
132132+ const { notify_enabled, notify_self } = db.getNotifyAccountGlobals(did);
133133+ if (!notify_enabled) console.warn('would drop this since notifies are not enabled (ui todo)');
134134+ if (!notify_self) {
135135+ const source_did = extractUriDid(source_record);
136136+ if (!source_did) {
137137+ console.warn(`ignoring link with non-DID source_record: ${source_record}`)
138138+ return;
139139+ }
140140+ if (source_did === did) {
141141+ console.warn(`ignoring self-notification`);
142142+ return;
143143+ }
112144 }
113145114146 const subs = db.getSubsByDid(did);
+2
server/schema.sql
···33 first_seen text not null default CURRENT_TIMESTAMP,
44 role text null,
55 secret_password text null,
66+ notify_enabled integer not null default false,
77+ notify_self integer not null default false,
6879 check(did like 'did:%')
810) strict;