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): keep comment rows pointing at the comment after they are read (#6917)

gbirmand393b142dd9b
diff --git a/apps/web/src/features/inbox-view/components/HomeListEntity.tsx b/apps/web/src/features/inbox-view/components/HomeListEntity.tsx
index c4f97b96bc..105732abf9 100644
--- a/apps/web/src/features/inbox-view/components/HomeListEntity.tsx
+++ b/apps/web/src/features/inbox-view/components/HomeListEntity.tsx
@@ -24,7 +24,7 @@ type HomeListEntityProps = BaseListEntityProps & {
export function HomeListEntity(props: HomeListEntityProps) {
const threadEntity = () =>
props.entity.type === 'channel_thread' ? props.entity : undefined;
- // A document announcing an unread comment reads like a thread row: the
+ // A document announcing a comment reads like a thread row: the
// comment glyph, who did what, and where. Opening it lands on the comment.
const commentNotification = () =>
getDocumentCommentNotification(props.entity);
diff --git a/apps/web/src/features/inbox-view/components/home-press.test.tsx b/apps/web/src/features/inbox-view/components/home-press.test.tsx
index 65e36e3be0..76227ec12d 100644
--- a/apps/web/src/features/inbox-view/components/home-press.test.tsx
+++ b/apps/web/src/features/inbox-view/components/home-press.test.tsx
@@ -86,7 +86,7 @@ describe.each(['recent', 'new chat'] as const)('Home %s press', (kind) => {
});
describe('Home document comment row', () => {
- const commentNotification = (state: 'unseen' | 'seen') => ({
+ const commentNotification = (state: 'unseen' | 'seen' | 'done') => ({
id: 'n1',
entity_id: 'doc-1',
entity_type: 'document',
@@ -99,7 +99,7 @@ describe('Home document comment row', () => {
},
});
- const renderRow = (state: 'unseen' | 'seen') =>
+ const renderRow = (state: 'unseen' | 'seen' | 'done') =>
render(() => (
<HomeListEntity
entity={
@@ -116,13 +116,16 @@ describe('Home document comment row', () => {
/>
)).container.querySelector<HTMLElement>('[data-home-item]')!;
- it('announces an unread comment mention', () => {
- expect(renderRow('unseen').textContent).toContain(
- 'Peter mentioned you on Recent chat'
- );
- });
+ it.each(['unseen', 'seen'] as const)(
+ 'announces the comment mention while %s',
+ (state) => {
+ expect(renderRow(state).textContent).toContain(
+ 'Peter mentioned you on Recent chat'
+ );
+ }
+ );
- it('reads as the plain document once the comment is read', () => {
- expect(renderRow('seen').textContent).not.toContain('mentioned you');
+ it('reads as the plain document once the notification is done', () => {
+ expect(renderRow('done').textContent).not.toContain('mentioned you');
});
});
diff --git a/apps/web/src/features/next-soup/utils.test.ts b/apps/web/src/features/next-soup/utils.test.ts
index 27eddb9540..def94125ca 100644
--- a/apps/web/src/features/next-soup/utils.test.ts
+++ b/apps/web/src/features/next-soup/utils.test.ts
@@ -988,7 +988,7 @@ const documentRow = (notifications: UnifiedNotification[]) =>
}) as unknown as EntityData;
describe('getDocumentCommentTarget', () => {
- it('targets the newest unread comment notification', () => {
+ it('targets the newest comment notification that is not done, read or not', () => {
expect(
getDocumentCommentTarget(
documentRow([
@@ -1008,13 +1008,13 @@ describe('getDocumentCommentTarget', () => {
}),
])
)?.params
- ).toEqual({ comment_id: 'comment-newest' });
+ ).toEqual({ comment_id: 'comment-read' });
});
- it('opens a document normally once its comment notifications are read', () => {
+ it('opens a document normally once its comment notifications are done', () => {
expect(
getDocumentCommentTarget(
- documentRow([commentNotification('n1', 'comment-1', { state: 'seen' })])
+ documentRow([commentNotification('n1', 'comment-1', { state: 'done' })])
)
).toBeUndefined();
});
diff --git a/apps/web/src/features/next-soup/utils.ts b/apps/web/src/features/next-soup/utils.ts
index 7169a83b3d..e2dc261eb1 100644
--- a/apps/web/src/features/next-soup/utils.ts
+++ b/apps/web/src/features/next-soup/utils.ts
@@ -529,11 +529,9 @@ export function getChannelEntityTarget(
/**
* Resolve the comment a document row opens at. A stamped `commentTarget` (the
* Inbox preview route carries one, since it keeps no notifications) wins;
- * otherwise it is the row's newest unread comment notification, the one the
- * row announces, so opening it lands on that comment exactly like a copied
- * comment link. Read ones are skipped for the same reason as on a
- * whole-`channel` row: once the document looks caught up it should open
- * normally rather than scroll to an old comment.
+ * otherwise it is the comment notification the row stands for (see
+ * `getDocumentCommentNotification`), read or not, so opening it lands on that
+ * comment exactly like a copied comment link.
*/
export function getDocumentCommentTarget(entity: {
type: string;
diff --git a/apps/web/src/features/notifications/document-comment-notification.ts b/apps/web/src/features/notifications/document-comment-notification.ts
index 27dac33bff..d0e3b10b6c 100644
--- a/apps/web/src/features/notifications/document-comment-notification.ts
+++ b/apps/web/src/features/notifications/document-comment-notification.ts
@@ -10,7 +10,11 @@ export const DOCUMENT_COMMENT_EVENT_TYPES = [
const isDocumentCommentTag = (tag: string) =>
(DOCUMENT_COMMENT_EVENT_TYPES as readonly string[]).includes(tag);
-/** The newest unread comment notification a document row announces. */
+/**
+ * The comment notification a document row stands for: its newest one that is
+ * not done. Like a channel thread row, the row keeps pointing at that comment
+ * after it is read; marking it done is what returns the row to the document.
+ */
export function getDocumentCommentNotification(entity: {
type: string;
notifications?: () => UnifiedNotification[];
@@ -19,8 +23,7 @@ export function getDocumentCommentNotification(entity: {
return (entity.notifications?.() ?? [])
.filter(
(n) =>
- n.state === 'unseen' &&
- isDocumentCommentTag(n.notification_metadata.tag)
+ n.state !== 'done' && isDocumentCommentTag(n.notification_metadata.tag)
)
.sort((a, b) => compareDateDesc(a.created_at, b.created_at))[0];
}