repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

notifications: id-keyed store with replace-in-place + selfTest IPC

f0320ea6789975d95530e1f0775cb82bc6de973b

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Adds mergeRow(list, row) which deduplicates by id (replace in place,
preserving the read flag) or appends. ingest(row) calls mergeRow and
recomputes unreadCount by full scan instead of the brittle += 1.
acceptNativeNotification now routes through ingest instead of concat,
fixing the append-duplicate bug for any code path that emits the same
native id twice (e.g. persistence reload).

selfTest() exercises the three mergeRow invariants (dedup, content
update, distinct ids) and is exposed as the notificationsSelfTest IPC.

Empirical replace-by-id observation: Quickshell mutates the native
notification QML object in-place and does NOT re-emit onNotification
for a freedesktop replace-by-id request. activeCount stays at 1 after
notify-send -r (no duplicate card), but the normalized rows snapshot
retains the original body since acceptNativeNotification only fires on
first delivery. The UI binds to the live native object so it reflects
the update; IPC snapshots do not.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Changed files (2)

quickshell/nuguland/Notifications.qml

Modified
122 + function mergeRow(list, row) {
123 + const next = (list || []).slice();
124 + for (let i = 0; i < next.length; i++) {
125 + if (next[i].id === row.id) {
126 + next[i] = Object.assign({}, next[i], row, {
127 + "read": next[i].read
128 + });
129 + return next;
132 + next.push(row);
133 + return next;
136 + function ingest(row) {
137 + notifications = mergeRow(notifications, row);
138 + let unread = 0;
139 + for (let i = 0; i < notifications.length; i++)
140 + if (!notifications[i].closed && !notifications[i].read)
141 + unread += 1;
142 + unreadCount = unread;
145 + function selfTest() {
146 + const failures = [];
147 + function expect(cond, msg) {
148 + if (!cond)
149 + failures.push(msg);
151 + // replace-by-id: same id updates in place, no duplicate
152 + let list = [];
153 + list = mergeRow(list, {"id": "7", "summary": "10%", "closed": false, "read": false});
154 + list = mergeRow(list, {"id": "7", "summary": "50%", "closed": false, "read": false});
155 + expect(list.length === 1, "replace-by-id should not duplicate");
156 + expect(list[0].summary === "50%", "replace-by-id should update content");
157 + // distinct ids stay separate
158 + list = mergeRow(list, {"id": "8", "summary": "other", "closed": false, "read": false});
159 + expect(list.length === 2, "distinct ids should be separate rows");
160 + return {
161 + "pass": failures.length === 0,
162 + "failures": failures
163 + };
122 166 function acceptNativeNotification(notification) {
123 167 if (!notification)
124 168 return ;
141 185 "urgency": notification.urgency,
142 186 "actions": notification.actions || []
144 - notifications = notifications.concat([row]);
145 - unreadCount += 1;
188 + ingest(row);
146 189 lastAction = {
147 190 "kind": "native-notification",
148 191 "id": id,

quickshell/nuguland/shell.qml

Modified
524 524 return notifications.discardAllNotifications();
527 + function notificationsSelfTest() : string {
528 + return JSON.stringify(notifications.selfTest());
527 531 function trayWidgetState(attention: bool, active: bool) : string {
528 532 return tray.widgetState(attention, active);