Skip to content

Commit bbb8d2a

Browse files
committed
feat(notifications): add mark all as done and unify bulk actions
Add a toolbar Done action for the unread notifications already loaded when an operation starts, including notifications hidden by filters. Background processing: - share the loaded-notification batch processor between repository and global Done actions, with at most three requests in flight per batch - preserve successful removals on partial failure, retain notifications loaded afterward, and reuse repeated in-flight global requests - prevent global Done from overlapping other Read or Done mutations while preserving concurrent operations on different repositories - isolate operation counts and global request locks by authentication session so old requests cannot block or unlock a new account - allow notification, latest-comment, and desktop navigation during global Done while keeping their Read and local-removal side effects guarded Popup behavior: - share repository and global Read/Done animation, result refresh, failure recovery, and focus handling instead of maintaining separate bulk flows - keep global actions disabled during conflicting operations and enable global Done when only filtered unread notifications remain - show toolbar loading feedback, collapse rows after the stagger finishes, and restore incomplete items from the actual background results - clear retained filtered-list animation markers before unlocking to avoid leaving global actions disabled after a successful operation - align toolbar, repository, and notification action centers; tighten the button gaps and reduce the space between author avatars and actions - document global Done, its loaded-notification scope, and retry behavior Validation: - npm run ci: syntax, lint, formatting, and all 630 tests pass - npm run dev: prepare the Firefox development extension successfully - npm run all: build Chrome and Firefox release packages successfully - reproduce the closed-filter-list lock regression before the fix and cover all four repository/global Read/Done paths with real DOM rendering - verify pending requests, partial failures, new notification retention, filtered-only actions, 400-800px layouts, and scrollbar alignment in a local popup preview without changing real GitHub notifications
1 parent 20df8e8 commit bbb8d2a

13 files changed

Lines changed: 854 additions & 226 deletions

‎README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
- 🔔 Real-time unread count badge and desktop notifications
1414
- 📋 Issues, PRs, Releases, and all types with rich details
1515
- ✅ Mark as read per notification, per repository, or all at once
16-
- ☑️ Mark as done per notification or per repository
16+
- ☑️ Mark as done per notification, per repository, or all at once
1717
- 🔐 OAuth Device Flow or Personal Access Token authentication
1818
- ✨ Clean, minimal UI — feature-rich without the clutter
1919
- 🎨 Light / Dark / System theme with adjustable popup width
@@ -28,6 +28,8 @@
2828
1. **OAuth (recommended)** — Click "Sign in with GitHub", enter the code on GitHub
2929
2. **Personal Access Token** — Generate a token with `repo` and `notifications` scopes at [GitHub Settings](https://github.com/settings/tokens)
3030

31+
Use **Mark as done** on a notification, repository, or the toolbar to move notifications to GitHub's Done inbox. Repository and all-at-once Done actions process the unread notifications loaded when the action starts, including those hidden by filters. Failed items remain available for retry.
32+
3133
## Development
3234

3335
See [DEVELOPMENT.md](DEVELOPMENT.md) for installation, building, and setup.

‎src/background/service-worker.js‎

Lines changed: 94 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ async function handleMessage(message) {
263263
case MESSAGE_TYPES.MARK_AS_DONE:
264264
return await markNotification(message.notificationId, message.action);
265265

266+
case MESSAGE_TYPES.MARK_ALL_AS_DONE:
267+
return await markAllAsDone();
268+
266269
case MESSAGE_TYPES.MARK_ALL_AS_READ:
267270
return await markAllAsRead();
268271

@@ -568,26 +571,54 @@ function removeStoredNotifications(predicate, { all = false, isCurrent = () => t
568571
return mutation;
569572
}
570573

571-
async function markNotification(notificationId, action = MESSAGE_TYPES.MARK_AS_READ) {
572-
const isDone = action === MESSAGE_TYPES.MARK_AS_DONE;
574+
let notificationMutationSession = null;
575+
576+
function getNotificationMutationSession() {
577+
if (notificationMutationSession?.generation !== authGeneration) {
578+
notificationMutationSession = { generation: authGeneration, active: 0, allDone: null };
579+
}
580+
return notificationMutationSession;
581+
}
582+
583+
function mutationConflict() {
584+
return { success: false, error: "Another notification action is in progress. Please try again." };
585+
}
586+
587+
async function runNotificationMutation(operation) {
588+
const session = getNotificationMutationSession();
589+
if (session.allDone) return mutationConflict();
590+
session.active++;
573591
try {
574-
if (isDone) {
575-
const notification = (await storage.getNotifications()).find((n) => n.id === notificationId);
576-
if (!notification) return { success: false, error: "Notification not found" };
577-
await github.markAsDone(notificationId);
578-
github.lastModified = null;
579-
github.lastModifiedAt = null;
580-
} else {
581-
await github.markAsRead(notificationId);
582-
}
583-
await removeStoredNotifications((n) => n.id === notificationId);
584-
return { success: true };
585-
} catch (error) {
586-
console.error(`Failed to mark as ${isDone ? "done" : "read"}:`, error);
587-
return { success: false, error: error.message };
592+
return await operation();
593+
} finally {
594+
session.active--;
588595
}
589596
}
590597

598+
function markNotification(notificationId, action = MESSAGE_TYPES.MARK_AS_READ) {
599+
return runNotificationMutation(async () => {
600+
const isDone = action === MESSAGE_TYPES.MARK_AS_DONE;
601+
try {
602+
if (isDone) {
603+
const notification = (await storage.getNotifications()).find(
604+
(n) => n.id === notificationId,
605+
);
606+
if (!notification) return { success: false, error: "Notification not found" };
607+
await github.markAsDone(notificationId);
608+
github.lastModified = null;
609+
github.lastModifiedAt = null;
610+
} else {
611+
await github.markAsRead(notificationId);
612+
}
613+
await removeStoredNotifications((n) => n.id === notificationId);
614+
return { success: true };
615+
} catch (error) {
616+
console.error(`Failed to mark as ${isDone ? "done" : "read"}:`, error);
617+
return { success: false, error: error.message };
618+
}
619+
});
620+
}
621+
591622
async function recalcFilterStats(notifs) {
592623
const rules = await storage.getNotificationFilter();
593624
if (rules.length === 0) {
@@ -598,28 +629,32 @@ async function recalcFilterStats(notifs) {
598629
await storage.setNotificationFilterStats(stats);
599630
}
600631

601-
async function markAllAsRead() {
602-
try {
603-
await github.markAllAsRead();
604-
await removeStoredNotifications(() => true, { all: true });
605-
return { success: true };
606-
} catch (error) {
607-
console.error("Failed to mark all as read:", error);
608-
return { success: false, error: error.message };
609-
}
632+
function markAllAsRead() {
633+
return runNotificationMutation(async () => {
634+
try {
635+
await github.markAllAsRead();
636+
await removeStoredNotifications(() => true, { all: true });
637+
return { success: true };
638+
} catch (error) {
639+
console.error("Failed to mark all as read:", error);
640+
return { success: false, error: error.message };
641+
}
642+
});
610643
}
611644

612-
async function markRepoAsRead(owner, repo) {
613-
try {
614-
await github.markRepoAsRead(owner, repo);
615-
const { updated } = await removeStoredNotifications(
616-
(n) => n.repository.full_name === `${owner}/${repo}`,
617-
);
618-
return { success: true, notifications: updated };
619-
} catch (error) {
620-
console.error("Failed to mark repo as read:", error);
621-
return { success: false, error: error.message };
622-
}
645+
function markRepoAsRead(owner, repo) {
646+
return runNotificationMutation(async () => {
647+
try {
648+
await github.markRepoAsRead(owner, repo);
649+
const { updated } = await removeStoredNotifications(
650+
(n) => n.repository.full_name === `${owner}/${repo}`,
651+
);
652+
return { success: true, notifications: updated };
653+
} catch (error) {
654+
console.error("Failed to mark repo as read:", error);
655+
return { success: false, error: error.message };
656+
}
657+
});
623658
}
624659

625660
// Share an in-flight repository operation to avoid duplicate DELETE requests.
@@ -628,14 +663,28 @@ const repoDoneOperations = new Map();
628663
function markRepoAsDone(owner, repo) {
629664
const key = `${authGeneration}:${owner}/${repo}`;
630665
if (repoDoneOperations.has(key)) return repoDoneOperations.get(key);
631-
const operation = completeRepoNotifications(owner, repo).finally(() => {
666+
const operation = runNotificationMutation(async () => {
667+
if (!owner || !repo) return { success: false, error: "Repository is required" };
668+
return await completeLoadedNotifications((n) => n.repository?.full_name === `${owner}/${repo}`);
669+
}).finally(() => {
632670
repoDoneOperations.delete(key);
633671
});
634672
repoDoneOperations.set(key, operation);
635673
return operation;
636674
}
637675

638-
async function completeRepoNotifications(owner, repo) {
676+
function markAllAsDone() {
677+
const session = getNotificationMutationSession();
678+
if (session.allDone) return session.allDone;
679+
if (session.active) return Promise.resolve(mutationConflict());
680+
const operation = completeLoadedNotifications(() => true).finally(() => {
681+
session.allDone = null;
682+
});
683+
session.allDone = operation;
684+
return operation;
685+
}
686+
687+
async function completeLoadedNotifications(matches) {
639688
const token = github.token;
640689
const generation = authGeneration;
641690
const isCurrent = () => !!token && github.token === token && authGeneration === generation;
@@ -644,15 +693,8 @@ async function completeRepoNotifications(owner, repo) {
644693
let error;
645694
try {
646695
if (!isCurrent()) throw new Error("Not authenticated");
647-
if (!owner || !repo) throw new Error("Repository is required");
648696
const loaded = await storage.getNotifications();
649-
ids = [
650-
...new Set(
651-
loaded
652-
.filter((n) => n.repository?.full_name === `${owner}/${repo}` && n.unread !== false)
653-
.map((n) => n.id),
654-
),
655-
];
697+
ids = [...new Set(loaded.filter((n) => matches(n) && n.unread !== false).map((n) => n.id))];
656698
if (!isCurrent()) throw new Error("Authentication changed. Please try again.");
657699
for (let offset = 0; offset < ids.length; offset += CONCURRENCY.BACKGROUND) {
658700
if (!isCurrent()) throw new Error("Authentication changed. Please try again.");
@@ -664,7 +706,7 @@ async function completeRepoNotifications(owner, repo) {
664706
if (result.status === "fulfilled") {
665707
batchCompleted.push(batch[index]);
666708
} else {
667-
error ||= result.reason?.message || "Failed to mark repository notifications as done";
709+
error ||= result.reason?.message || "Failed to mark notifications as done";
668710
const status = result.reason?.response?.status;
669711
if ([401, 403, 429].includes(status)) stop = true;
670712
}
@@ -723,15 +765,15 @@ notifications.onClicked.addListener(async (notificationId) => {
723765
}
724766
const githubNotifId = notificationId.slice(NOTIFICATION_ID_PREFIX.length);
725767

726-
const { removed } = await removeStoredNotifications((n) => n.id === githubNotifId);
727-
const notification = removed[0];
728-
768+
const notification = (await storage.getNotifications()).find((n) => n.id === githubNotifId);
729769
await safeClearNotification(notificationId);
730-
731770
if (notification) {
732771
const url = buildNotificationUrl(notification);
733772
await tabs.create({ url });
734-
await github.markAsRead(githubNotifId);
773+
await runNotificationMutation(async () => {
774+
await removeStoredNotifications((n) => n.id === githubNotifId);
775+
await github.markAsRead(githubNotifId);
776+
});
735777
}
736778
} catch (error) {
737779
console.error("Failed to handle notification click:", error);

‎src/lib/constants.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export const MESSAGE_TYPES = {
8181
MARK_AS_READ: "markAsRead",
8282
MARK_AS_DONE: "markAsDone",
8383
MARK_ALL_AS_READ: "markAllAsRead",
84+
MARK_ALL_AS_DONE: "markAllAsDone",
8485
MARK_REPO_AS_READ: "markRepoAsRead",
8586
MARK_REPO_AS_DONE: "markRepoAsDone",
8687
REFRESH: "refresh",

‎src/popup/filter.js‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
renderNotifications,
1919
renderNotificationsInto,
2020
groupByRepo,
21+
updateMarkAllButtons,
2122
} from "./notification-renderer.js";
2223

2324
const DELETE_CONFIRMATION_TIMEOUT_MS = 5000;
@@ -598,10 +599,12 @@ export function createFilter(deps) {
598599
}
599600
renderNotifications(visible, shouldResort);
600601
updateFilteredBadge(filtered.length);
602+
updateMarkAllButtons(notifications);
601603
}
602604

603605
async function refreshFilteredBadge() {
604606
const stored = await storage.getNotifications();
607+
updateMarkAllButtons(stored);
605608
const filtered = stored.filter((n) => !isVisible(n));
606609
updateFilteredBadge(filtered.length);
607610
return filtered;
@@ -692,11 +695,6 @@ export function createFilter(deps) {
692695
}
693696
}
694697

695-
// ─── Mark-all-as-read cleanup hook ────────────────────────────────────
696-
function clearFilteredAfterMarkAll() {
697-
updateFilteredBadge(0);
698-
}
699-
700698
// ─── Event wiring ─────────────────────────────────────────────────────
701699
filterIconBtn?.addEventListener("click", show);
702700
filterCountBadge?.addEventListener("click", toggleFilteredInFilterView);
@@ -727,7 +725,6 @@ export function createFilter(deps) {
727725
renderFilteredInFilterView,
728726
updateFilterIndicator,
729727
handleStorageChange,
730-
clearFilteredAfterMarkAll,
731728
async applyPulledFilter(rules) {
732729
currentFilterRules = rules;
733730
try {

0 commit comments

Comments
 (0)