Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(today): show unread sessions in the space hover card like desktop (#110074)

Shy Alter2f512b2328ad
diff --git a/frontend/src/layout/today/TodaySpaceHoverCard.tsx b/frontend/src/layout/today/TodaySpaceHoverCard.tsx
index 3dae34733d14..ffc4e36dd0fa 100644
--- a/frontend/src/layout/today/TodaySpaceHoverCard.tsx
+++ b/frontend/src/layout/today/TodaySpaceHoverCard.tsx
@@ -45,6 +45,9 @@ export function TodaySpaceHoverCard({
<TodaySpaceGlyph locked={preview.spaceKind !== 'public'} />
</span>
<span className="min-w-0 font-semibold">{preview.name}</span>
+ {preview.unreadSessions > 0 && (
+ <span aria-hidden className="size-2 shrink-0 rounded-full bg-primary" />
+ )}
</ItemTitle>
<ItemDescription className="pl-5.5">
<span className="block">{KIND_LABELS[preview.spaceKind]}</span>
@@ -60,27 +63,35 @@ export function TodaySpaceHoverCard({
/>
</ItemActions>
</Item>
- {preview.repositories.length > 0 && (
+ {(preview.unreadSessions > 0 || preview.repositories.length > 0) && (
<>
<ItemSeparator className="my-0" />
<Item size="xs">
- <ItemContent className="min-w-0">
- <div className="flex flex-wrap items-center gap-x-3 gap-y-1">
- {preview.repositories.map((repository) => (
- <span
- key={repository}
- className="flex min-w-0 items-center gap-1 text-xs text-muted-foreground"
- >
- <IconGitRepository className="size-3 shrink-0" />
- <span className="truncate">{repository}</span>
- </span>
- ))}
- {preview.hiddenRepositoryCount > 0 && (
- <Text size="xs" variant="muted" render={<span />}>
- {`+${preview.hiddenRepositoryCount} more`}
- </Text>
- )}
- </div>
+ <ItemContent className="min-w-0 gap-1.5">
+ {preview.unreadSessions > 0 && (
+ <span className="flex items-center gap-1 text-xs text-muted-foreground">
+ <span aria-hidden className="size-2 shrink-0 rounded-full bg-primary" />
+ {`${preview.unreadSessions} unread`}
+ </span>
+ )}
+ {preview.repositories.length > 0 && (
+ <div className="flex flex-wrap items-center gap-x-3 gap-y-1">
+ {preview.repositories.map((repository) => (
+ <span
+ key={repository}
+ className="flex min-w-0 items-center gap-1 text-xs text-muted-foreground"
+ >
+ <IconGitRepository className="size-3 shrink-0" />
+ <span className="truncate">{repository}</span>
+ </span>
+ ))}
+ {preview.hiddenRepositoryCount > 0 && (
+ <Text size="xs" variant="muted" render={<span />}>
+ {`+${preview.hiddenRepositoryCount} more`}
+ </Text>
+ )}
+ </div>
+ )}
</ItemContent>
</Item>
</>
diff --git a/frontend/src/layout/today/todayPreviewCards.ts b/frontend/src/layout/today/todayPreviewCards.ts
index 7a848f8eacba..afbff28992b8 100644
--- a/frontend/src/layout/today/todayPreviewCards.ts
+++ b/frontend/src/layout/today/todayPreviewCards.ts
@@ -42,6 +42,7 @@ export interface TodaySpacePreview {
liveUuids: string[]
creatorUuid: string | null
lastActivityAt: string | null
+ unreadSessions: number
repositories: string[]
hiddenRepositoryCount: number
}
@@ -115,7 +116,8 @@ export function spacePreview(
space: ChannelDTOApi,
name: string,
presence: SpacePresence | undefined,
- lastActivityAt: string | undefined
+ lastActivityAt: string | undefined,
+ unreadSessions: number = 0
): TodaySpacePreview {
return {
kind: 'space',
@@ -126,6 +128,7 @@ export function spacePreview(
liveUuids: presence?.liveUuids ?? [],
creatorUuid: space.created_by?.uuid ?? null,
lastActivityAt: lastActivityAt ?? null,
+ unreadSessions,
repositories: space.repositories.slice(0, SPACE_PREVIEW_REPOSITORY_LIMIT),
hiddenRepositoryCount: Math.max(0, space.repositories.length - SPACE_PREVIEW_REPOSITORY_LIMIT),
}
diff --git a/frontend/src/layout/today/todaySpacesLogic.ts b/frontend/src/layout/today/todaySpacesLogic.ts
index 88b368a82302..55ae7cb80772 100644
--- a/frontend/src/layout/today/todaySpacesLogic.ts
+++ b/frontend/src/layout/today/todaySpacesLogic.ts
@@ -60,6 +60,7 @@ import {
sessionItem,
sessionReadRequest,
setActivityUnread,
+ unreadSessionCountsBySpace,
unreadSessionIds,
unreadSpaceIds,
} from './todayWorkItems'
@@ -164,6 +165,7 @@ export interface todaySpacesLogicValues {
storedRecentFilters: Partial<TodayRecentFilters>
taskActivity: TaskActivityDTOApi[]
taskActivityLoading: boolean
+ unreadSessionCounts: Record<string, number>
unreadSessionIds: Set<string>
unreadSpaceIds: Set<string>
visibleSpaces: ChannelDTOApi[]
@@ -372,10 +374,12 @@ export interface todaySpacesLogicMeta {
) => TodayRecentSection[]
recentLoading: (recentTasksLoading: boolean, conversationHistoryLoading: boolean) => boolean
unreadSpaceIds: (taskActivity: TaskActivityDTOApi[]) => Set<string>
+ unreadSessionCounts: (taskActivity: TaskActivityDTOApi[]) => Record<string, number>
spacePresence: (spaceActivity: SpaceActivity) => Record<string, SpacePresence>
spacePreviews: (
visibleSpaces: ChannelDTOApi[],
- spaceActivity: SpaceActivity
+ spaceActivity: SpaceActivity,
+ unreadSessionCounts: Record<string, number>
) => Record<string, TodaySpacePreview>
}
}
@@ -664,14 +668,22 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([
(s) => [s.taskActivity],
(taskActivity: TaskActivityDTOApi[]): Set<string> => unreadSpaceIds(taskActivity),
],
+ unreadSessionCounts: [
+ (s) => [s.taskActivity],
+ (taskActivity: TaskActivityDTOApi[]): Record<string, number> => unreadSessionCountsBySpace(taskActivity),
+ ],
spacePresence: [
(s) => [s.spaceActivity],
(spaceActivity: SpaceActivity): Record<string, SpacePresence> => spaceActivity.presence,
],
// One object per space that changes only when its inputs do, so the hover card's payload stays stable.
spacePreviews: [
- (s) => [s.visibleSpaces, s.spaceActivity],
- (visibleSpaces: ChannelDTOApi[], spaceActivity: SpaceActivity): Record<string, TodaySpacePreview> =>
+ (s) => [s.visibleSpaces, s.spaceActivity, s.unreadSessionCounts],
+ (
+ visibleSpaces: ChannelDTOApi[],
+ spaceActivity: SpaceActivity,
+ unreadSessionCounts: Record<string, number>
+ ): Record<string, TodaySpacePreview> =>
Object.fromEntries(
visibleSpaces.map((space) => [
space.id,
@@ -679,7 +691,8 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([
space,
spaceLabel(space),
spaceActivity.presence[space.id],
- spaceActivity.lastActivityAt[space.id]
+ spaceActivity.lastActivityAt[space.id],
+ unreadSessionCounts[space.id] ?? 0
),
])
),
diff --git a/frontend/src/layout/today/todayWorkItems.test.ts b/frontend/src/layout/today/todayWorkItems.test.ts
index 6cd62fdfcd71..8f6389910f33 100644
--- a/frontend/src/layout/today/todayWorkItems.test.ts
+++ b/frontend/src/layout/today/todayWorkItems.test.ts
@@ -2,7 +2,7 @@ import { dayjs } from 'lib/dayjs'
import { ConversationDetail } from '~/types'
-import { TaskListItemApi } from 'products/tasks/frontend/generated/api.schemas'
+import { TaskActivityDTOApi, TaskListItemApi } from 'products/tasks/frontend/generated/api.schemas'
import { TodayListItemField } from './todayListAppearance'
import {
@@ -23,6 +23,7 @@ import {
sessionDetails,
sessionItem,
shortTimeAgo,
+ unreadSessionCountsBySpace,
} from './todayWorkItems'
const session = (id: string, lastActivityAt: string, archived = false): TaskListItemApi =>
@@ -31,6 +32,19 @@ const session = (id: string, lastActivityAt: string, archived = false): TaskList
const chat = (id: string, updatedAt: string): ConversationDetail =>
({ id, title: `Chat ${id}`, updated_at: updatedAt, created_at: updatedAt }) as ConversationDetail
+const activity = (
+ taskId: string | null,
+ channelId: string | null,
+ overrides: Partial<TaskActivityDTOApi> = {}
+): TaskActivityDTOApi =>
+ ({
+ id: `${taskId}-${overrides.latest_comment_id ?? 'run'}`,
+ task_id: taskId,
+ channel_id: channelId,
+ is_unread: true,
+ ...overrides,
+ }) as TaskActivityDTOApi
+
const ME = 7
const mixedItems = [
@@ -253,6 +267,31 @@ describe('todayWorkItems', () => {
expect(item.finalMessage).toBe(message)
})
+ it.each<[string, TaskActivityDTOApi[], Record<string, number>]>([
+ [
+ 'counts each unread session once per space',
+ [
+ activity('s1', 'space-a'),
+ activity('s1', 'space-a'),
+ activity('s2', 'space-a'),
+ activity('s3', 'space-b'),
+ ],
+ { 'space-a': 2, 'space-b': 1 },
+ ],
+ [
+ 'skips read sessions, comment notifications and sessions outside a space',
+ [
+ activity('s1', 'space-a', { is_unread: false }),
+ activity('s2', 'space-a', { latest_comment_id: 'comment-1' }),
+ activity('s3', null),
+ activity(null, 'space-a'),
+ ],
+ {},
+ ],
+ ])('unread session counts %s', (_name, rows, expected) => {
+ expect(unreadSessionCountsBySpace(rows)).toEqual(expected)
+ })
+
it.each<[string, Partial<TaskListItemApi>, TodayListItemField[], string[]]>([
[
'the chosen details in the chosen order',
diff --git a/frontend/src/layout/today/todayWorkItems.ts b/frontend/src/layout/today/todayWorkItems.ts
index 73c5c7f0fc9d..b6f34e7866ec 100644
--- a/frontend/src/layout/today/todayWorkItems.ts
+++ b/frontend/src/layout/today/todayWorkItems.ts
@@ -247,6 +247,17 @@ export function unreadSpaceIds(activity: TaskActivityDTOApi[]): Set<string> {
return new Set(unreadSessionActivity(activity).flatMap((row) => (row.channel_id ? [row.channel_id] : [])))
}
+export function unreadSessionCountsBySpace(activity: TaskActivityDTOApi[]): Record<string, number> {
+ const sessionsBySpace: Record<string, Set<string>> = {}
+ for (const row of unreadSessionActivity(activity)) {
+ if (row.channel_id) {
+ sessionsBySpace[row.channel_id] ??= new Set()
+ sessionsBySpace[row.channel_id].add(row.task_id as string)
+ }
+ }
+ return Object.fromEntries(Object.entries(sessionsBySpace).map(([spaceId, sessions]) => [spaceId, sessions.size]))
+}
+
/**
* What to send to mark a session read, or null when it has nothing unread.
* `seen_before` is never earlier than the newest activity shown, so a client clock behind the server's still clears it.