-
Notifications
You must be signed in to change notification settings - Fork 38
Add team-level lastSeenAt to conversation headers #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -589,6 +589,7 @@ export async function listConversationsHeaders( | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const seenDataMap = new Map<string, ConversationSeen[]>(); | ||||||||||||||||||||||||||||||||||||||||||
| const userLastSeenMap = new Map<string, string | null>(); | ||||||||||||||||||||||||||||||||||||||||||
| const teamLastSeenMap = new Map<string, string | null>(); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| for (const seen of seenRows) { | ||||||||||||||||||||||||||||||||||||||||||
| const collection = seenDataMap.get(seen.conversationId) ?? []; | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -611,6 +612,19 @@ export async function listConversationsHeaders( | |||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if (seen.userId && seen.lastSeenAt) { | ||||||||||||||||||||||||||||||||||||||||||
| const currentTeamLastSeen = teamLastSeenMap.get(seen.conversationId); | ||||||||||||||||||||||||||||||||||||||||||
| if (!currentTeamLastSeen) { | ||||||||||||||||||||||||||||||||||||||||||
| teamLastSeenMap.set(seen.conversationId, seen.lastSeenAt); | ||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||
| const currentDate = new Date(currentTeamLastSeen); | ||||||||||||||||||||||||||||||||||||||||||
| const candidateDate = new Date(seen.lastSeenAt); | ||||||||||||||||||||||||||||||||||||||||||
| if (candidateDate > currentDate) { | ||||||||||||||||||||||||||||||||||||||||||
| teamLastSeenMap.set(seen.conversationId, seen.lastSeenAt); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const conversationsWithDetails = items.map((row) => { | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -652,6 +666,7 @@ export async function listConversationsHeaders( | |||||||||||||||||||||||||||||||||||||||||
| viewIds: viewIdsMap.get(conversationId) ?? [], | ||||||||||||||||||||||||||||||||||||||||||
| lastMessageAt, | ||||||||||||||||||||||||||||||||||||||||||
| lastSeenAt: userLastSeenMap.get(conversationId) ?? null, | ||||||||||||||||||||||||||||||||||||||||||
| teamLastSeenAt: teamLastSeenMap.get(conversationId) ?? null, | ||||||||||||||||||||||||||||||||||||||||||
| lastMessageTimelineItem, | ||||||||||||||||||||||||||||||||||||||||||
| lastTimelineItem, | ||||||||||||||||||||||||||||||||||||||||||
| activeClarification: | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -808,6 +823,18 @@ export async function getConversationHeader( | |||||||||||||||||||||||||||||||||||||||||
| }, null) | ||||||||||||||||||||||||||||||||||||||||||
| : null; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const teamLastSeenAt = seenRows.reduce<string | null>((acc, seen) => { | ||||||||||||||||||||||||||||||||||||||||||
| if (!seen.userId || !seen.lastSeenAt) { | ||||||||||||||||||||||||||||||||||||||||||
| return acc; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| if (!acc) { | ||||||||||||||||||||||||||||||||||||||||||
| return seen.lastSeenAt; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| return new Date(seen.lastSeenAt) > new Date(acc) | ||||||||||||||||||||||||||||||||||||||||||
| ? seen.lastSeenAt | ||||||||||||||||||||||||||||||||||||||||||
| : acc; | ||||||||||||||||||||||||||||||||||||||||||
| }, null); | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+826
to
+836
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Same repeated
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||
| ...row.conversation, | ||||||||||||||||||||||||||||||||||||||||||
| visitor: { | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -828,6 +855,7 @@ export async function getConversationHeader( | |||||||||||||||||||||||||||||||||||||||||
| viewIds, | ||||||||||||||||||||||||||||||||||||||||||
| lastMessageAt, | ||||||||||||||||||||||||||||||||||||||||||
| lastSeenAt: userLastSeenAt ?? null, | ||||||||||||||||||||||||||||||||||||||||||
| teamLastSeenAt: teamLastSeenAt ?? null, | ||||||||||||||||||||||||||||||||||||||||||
| lastMessageTimelineItem, | ||||||||||||||||||||||||||||||||||||||||||
| lastTimelineItem, | ||||||||||||||||||||||||||||||||||||||||||
| activeClarification: | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
elsebranch allocates twonew Date(...)objects per candidate, same pattern used foruserLastSeenMapabove. SinceseenRowsfor the bulk query is already ordereddesc(lastSeenAt), the firstuserIdrow encountered for each conversation is always the maximum, so this branch will never trigger in practice. If the ordering guarantee is ever relaxed, consider caching the parsed date alongside the string to avoid repeated parsing.ISO 8601 strings with the same timezone offset compare correctly as plain strings, so
>avoids the Date allocation entirely.