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.

fix(replay): match current replay comments in the comment text filter (#125457)

Tue Haulundb620190f687f
diff --git a/frontend/src/scenes/session-recordings/player/commenting/playerFrameCommentOverlayLogic.test.ts b/frontend/src/scenes/session-recordings/player/commenting/playerFrameCommentOverlayLogic.test.ts
index c758ec1c7194..37b50628cc25 100644
--- a/frontend/src/scenes/session-recordings/player/commenting/playerFrameCommentOverlayLogic.test.ts
+++ b/frontend/src/scenes/session-recordings/player/commenting/playerFrameCommentOverlayLogic.test.ts
@@ -94,6 +94,7 @@ describe('playerFrameCommentOverlayLogic', () => {
}).toDispatchActions([playerCommentModel.actionTypes.commentEdited, 'submitRecordingCommentSuccess'])
expect(createSpy).toHaveBeenCalledTimes(1)
+ expect(createSpy.mock.calls[0][0].content).toEqual('a comment')
expect(createSpy.mock.calls[0][0].item_context).toMatchObject({
milliseconds_into_recording: 0,
time_in_recording: dayjs(recordingMetaJson.start_time).toISOString(),
diff --git a/frontend/src/scenes/session-recordings/player/commenting/playerFrameCommentOverlayLogic.ts b/frontend/src/scenes/session-recordings/player/commenting/playerFrameCommentOverlayLogic.ts
index fa5e2ae6cbda..56ad5d5983a4 100644
--- a/frontend/src/scenes/session-recordings/player/commenting/playerFrameCommentOverlayLogic.ts
+++ b/frontend/src/scenes/session-recordings/player/commenting/playerFrameCommentOverlayLogic.ts
@@ -5,6 +5,7 @@ import { subscriptions } from 'kea-subscriptions'
import posthog from 'posthog-js'
import api from 'lib/api'
+import { getTextContent } from 'lib/components/Comments/utils'
import { JSONContent, RichContentEditorType } from 'lib/components/RichContentEditor/types'
import { Dayjs, dayjs } from 'lib/dayjs'
import { lemonToast } from 'lib/lemon-ui/LemonToast'
@@ -13,7 +14,7 @@ import { membersLogic } from 'scenes/organization/membersLogic'
import { playerCommentModel } from 'scenes/session-recordings/player/commenting/playerCommentModel'
import { isSingleEmoji } from 'scenes/session-recordings/utils'
-import { CommentType } from '~/types'
+import { CommentType, OrganizationMemberType } from '~/types'
import type { SessionPlayerData } from '../../../../types'
import { SessionRecordingPlayerLogicProps, sessionRecordingPlayerLogic } from '../sessionRecordingPlayerLogic'
@@ -38,6 +39,7 @@ export interface PlayerCommentOverlayLogicProps extends SessionRecordingPlayerLo
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface playerCommentOverlayLogicValues {
+ meFirstMembers: OrganizationMemberType[] // membersLogic
currentPlayerTime: number // sessionRecordingPlayerLogic
currentTimestamp: number | undefined // sessionRecordingPlayerLogic
sessionPlayerData: SessionPlayerData // sessionRecordingPlayerLogic
@@ -157,7 +159,12 @@ export const playerCommentOverlayLogic = kea<playerCommentOverlayLogicType>([
key((props) => props.recordingId ?? 'unknown'),
props({} as PlayerCommentOverlayLogicProps),
connect((props: PlayerCommentOverlayLogicProps) => ({
- values: [sessionRecordingPlayerLogic(props), ['currentPlayerTime', 'currentTimestamp', 'sessionPlayerData']],
+ values: [
+ sessionRecordingPlayerLogic(props),
+ ['currentPlayerTime', 'currentTimestamp', 'sessionPlayerData'],
+ membersLogic,
+ ['meFirstMembers'],
+ ],
actions: [
sessionRecordingPlayerLogic(props),
['setIsCommenting'],
@@ -344,7 +351,7 @@ export const playerCommentOverlayLogic = kea<playerCommentOverlayLogicType>([
}
const apiPayload = {
- content,
+ content: richContent ? getTextContent(richContent, values.meFirstMembers) : content,
rich_content: richContent,
scope: 'Replay',
item_id: props.recordingId,
diff --git a/posthog/session_recordings/session_recording_api.py b/posthog/session_recordings/session_recording_api.py
index 7acaaca00e0b..4cbb97e073c4 100644
--- a/posthog/session_recordings/session_recording_api.py
+++ b/posthog/session_recordings/session_recording_api.py
@@ -15,6 +15,7 @@ from urllib.parse import urlparse
from django.conf import settings
from django.contrib.auth.models import AnonymousUser
from django.core.cache import cache
+from django.db.models import Q
from django.http import HttpResponse, JsonResponse
from django.utils import timezone
@@ -242,18 +243,15 @@ def _get_session_ids_from_comment_search(
if not comment_filter:
return None
- base_query = Comment.objects.filter(
- team=team,
- # TODO: discussions created `Replay` and comments create `recording`
- # TODO: that's an unnecessary distinction but we'll ignore it for now
- scope__in=["recording"],
- ).exclude(deleted=True)
+ base_query = Comment.objects.filter(team=team, scope="Replay").exclude(deleted=True)
operator = comment_filter.operator
value = comment_filter.value
if operator == PropertyOperator.IS_SET:
- base_query = base_query.filter(content__isnull=False).exclude(content="")
+ # some replay comments keep their text only in rich_content
+ has_text = Q(content__isnull=False) & ~Q(content="")
+ base_query = base_query.filter(has_text | Q(rich_content__isnull=False))
elif operator == PropertyOperator.EXACT:
# do the check here to help mypy
if value is None or value == "":
diff --git a/posthog/session_recordings/test/test_session_recordings_comment_filters.py b/posthog/session_recordings/test/test_session_recordings_comment_filters.py
index 30b4c0d81164..fcfbef4b2f92 100644
--- a/posthog/session_recordings/test/test_session_recordings_comment_filters.py
+++ b/posthog/session_recordings/test/test_session_recordings_comment_filters.py
@@ -27,6 +27,7 @@ class TestSessionRecordingsCommentFiltering(APIBaseTest, ClickhouseTestMixin, Qu
session_with_bug = "session_with_bug"
session_with_emoji = "session_with_emoji"
session_with_need = "session_with_need"
+ session_with_rich_content = "session_with_rich_content"
base_time = now() - timedelta(hours=2)
@@ -37,52 +38,70 @@ class TestSessionRecordingsCommentFiltering(APIBaseTest, ClickhouseTestMixin, Qu
timestamp=base_time + timedelta(minutes=i * 10),
)
for i, x in enumerate(
- [session_no_comment, session_with_needle, session_with_bug, session_with_emoji, session_with_need]
+ [
+ session_no_comment,
+ session_with_needle,
+ session_with_bug,
+ session_with_emoji,
+ session_with_need,
+ session_with_rich_content,
+ ]
)
]
Comment.objects.create(
team=self.team,
content="This comment contains the word needle for searching",
- scope="recording",
+ scope="Replay",
item_id=session_with_needle,
created_by=self.user,
)
Comment.objects.create(
team=self.team,
content="This recording has two comments",
- scope="recording",
+ scope="Replay",
item_id=session_with_needle,
created_by=self.user,
)
Comment.objects.create(
team=self.team,
content="This comment contains the word need for searching",
- scope="recording",
+ scope="Replay",
item_id=session_with_need,
created_by=self.user,
)
Comment.objects.create(
team=self.team,
content="Fixed the bug fix issue in the login form",
- scope="recording",
+ scope="Replay",
item_id=session_with_bug,
created_by=self.user,
)
Comment.objects.create(
team=self.team,
content="Some unrelated content here",
- scope="recording",
+ scope="Replay",
item_id=str(uuid7()),
created_by=self.user,
)
Comment.objects.create(
team=self.team,
content="heart eyes 💖",
- scope="recording",
+ scope="Replay",
item_id=session_with_emoji,
created_by=self.user,
)
+ Comment.objects.create(
+ team=self.team,
+ content="",
+ rich_content={
+ "type": "doc",
+ "content": [{"type": "paragraph", "content": [{"type": "text", "text": "hi"}]}],
+ },
+ scope="Replay",
+ item_id=session_with_rich_content,
+ created_by=self.user,
+ )
def produce_replay_summary(
self,
@@ -127,7 +146,13 @@ class TestSessionRecordingsCommentFiltering(APIBaseTest, ClickhouseTestMixin, Qu
"comments is set",
"",
PropertyOperator.IS_SET,
- ["session_with_needle", "session_with_bug", "session_with_emoji", "session_with_need"],
+ [
+ "session_with_needle",
+ "session_with_bug",
+ "session_with_emoji",
+ "session_with_need",
+ "session_with_rich_content",
+ ],
),
]
)