Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(notifications-inbox): list a group once when two pages hold it (#9884)

teo0b04bca9fc87
diff --git a/apps/web/src/features/notifications-inbox/queries/notification-inbox-groups.test.ts b/apps/web/src/features/notifications-inbox/queries/notification-inbox-groups.test.ts
index baf7794a91..7e8555342d 100644
--- a/apps/web/src/features/notifications-inbox/queries/notification-inbox-groups.test.ts
+++ b/apps/web/src/features/notifications-inbox/queries/notification-inbox-groups.test.ts
@@ -79,4 +79,20 @@ describe('orderInboxRows', () => {
'document:a#task',
]);
});
+
+ it('lists a group caught on two refetched pages once, as its newer copy', () => {
+ const fresh = row('foreign_entity:p#pull_request', 60);
+ const stale = row('foreign_entity:p#pull_request', 20);
+ const groups = [
+ group('foreign_entity:p', 60, [fresh]),
+ group('document:b', 40, [row('document:b#task', 40)]),
+ group('foreign_entity:p', 20, [stale]),
+ ];
+ const rows = orderInboxRows(groups, true);
+ expect(ids(rows)).toEqual([
+ 'foreign_entity:p#pull_request',
+ 'document:b#task',
+ ]);
+ expect(rows[0]).toBe(fresh);
+ });
});
diff --git a/apps/web/src/features/notifications-inbox/queries/notification-inbox-groups.ts b/apps/web/src/features/notifications-inbox/queries/notification-inbox-groups.ts
index 632c8438c6..fc85fbea80 100644
--- a/apps/web/src/features/notifications-inbox/queries/notification-inbox-groups.ts
+++ b/apps/web/src/features/notifications-inbox/queries/notification-inbox-groups.ts
@@ -10,6 +10,22 @@ export type NotificationInboxGroup = {
rows: NotificationInboxRow[];
};
+/**
+ * Each group once. Pages refetched one at a time can catch a group on two of
+ * them when it moves between pages in the meantime; its newer copy is the
+ * current one.
+ */
+function newestCopies(
+ groups: readonly NotificationInboxGroup[]
+): NotificationInboxGroup[] {
+ const newest = new Map<string, NotificationInboxGroup>();
+ for (const group of groups) {
+ const seen = newest.get(group.groupId);
+ if (!seen || group.sortAt > seen.sortAt) newest.set(group.groupId, group);
+ }
+ return [...newest.values()];
+}
+
/**
* The rows of the loaded groups, newest first. The inbox pages by group, and
* no row is newer than its group's place, so a row older than the last
@@ -23,7 +39,7 @@ export function orderInboxRows(
const boundary = exhausted
? Number.NEGATIVE_INFINITY
: (groups.at(-1)?.sortAt ?? Number.POSITIVE_INFINITY);
- return groups
+ return newestCopies(groups)
.flatMap((group) => group.rows)
.filter((row) => row.latestAt >= boundary)
.sort(compareInboxRows);