Skip to content

Commit c417f4a

Browse files
authored
fix: missing edited indicator for thread parent message (RocketChat#40063)
Signed-off-by: Abhinav Kumar <abhinav@avitechlab.com>
1 parent 987728a commit c417f4a

3 files changed

Lines changed: 74 additions & 16 deletions

File tree

.changeset/dry-squids-wonder.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@rocket.chat/meteor': patch
3+
---
4+
5+
Fixes the missing edited indicator for the main parent message in the thread panel to ensure visual consistency with the main channel view.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { mapMessageFromApi } from './mapMessageFromApi';
2+
3+
it('should convert all date fields to Date objects', () => {
4+
const now = new Date();
5+
const iso = now.toISOString();
6+
const input = {
7+
_id: 'id',
8+
ts: iso,
9+
_updatedAt: iso,
10+
pinnedAt: iso,
11+
tlm: iso,
12+
webRtcCallEndTs: iso,
13+
editedAt: iso,
14+
dlm: iso,
15+
msg: 'hi',
16+
u: { _id: 'u', username: 'user' },
17+
rid: 'r',
18+
attachments: [{ ts: iso, title: 'attach' }],
19+
};
20+
const result = mapMessageFromApi(input);
21+
expect(result.ts).toBeInstanceOf(Date);
22+
expect(result._updatedAt).toBeInstanceOf(Date);
23+
expect(result.pinnedAt).toBeInstanceOf(Date);
24+
expect(result.tlm).toBeInstanceOf(Date);
25+
expect(result.webRtcCallEndTs).toBeInstanceOf(Date);
26+
expect(result.editedAt).toBeInstanceOf(Date);
27+
expect(result.dlm).toBeInstanceOf(Date);
28+
expect(result.attachments?.[0].ts).toBeInstanceOf(Date);
29+
});
30+
31+
it('should not set missing optional dates', () => {
32+
const input = {
33+
_id: 'id',
34+
ts: new Date().toISOString(),
35+
_updatedAt: new Date().toISOString(),
36+
msg: 'hi',
37+
u: { _id: 'u', username: 'user' },
38+
rid: 'r',
39+
};
40+
const result = mapMessageFromApi(input);
41+
expect(result.pinnedAt).toBeUndefined();
42+
expect(result.tlm).toBeUndefined();
43+
expect(result.webRtcCallEndTs).toBeUndefined();
44+
expect(result.editedAt).toBeUndefined();
45+
expect(result.dlm).toBeUndefined();
46+
});
Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
1-
import type { IMessage, Serialized } from '@rocket.chat/core-typings';
1+
import type { IDiscussionMessage, IEditedMessage, IMessage, Serialized } from '@rocket.chat/core-typings';
22

3-
export const mapMessageFromApi = ({
3+
type MappableMessage = IMessage & Partial<Pick<IEditedMessage, 'editedAt' | 'editedBy'>> & Partial<Pick<IDiscussionMessage, 'dlm'>>;
4+
5+
export const mapMessageFromApi = <T extends MappableMessage = IMessage>({
46
attachments,
57
tlm,
68
ts,
79
_updatedAt,
810
pinnedAt,
911
webRtcCallEndTs,
12+
editedAt,
13+
dlm,
1014
...message
11-
}: Serialized<IMessage>): IMessage => ({
12-
...message,
13-
ts: new Date(ts),
14-
...(tlm && { tlm: new Date(tlm) }),
15-
_updatedAt: new Date(_updatedAt),
16-
...(pinnedAt && { pinnedAt: new Date(pinnedAt) }),
17-
...(webRtcCallEndTs && { webRtcCallEndTs: new Date(webRtcCallEndTs) }),
18-
...(attachments && {
19-
attachments: attachments.map(({ ts, ...attachment }) => ({
20-
...(ts && { ts: new Date(ts) }),
21-
...(attachment as any),
22-
})),
23-
}),
24-
});
15+
}: Serialized<T>): T =>
16+
({
17+
...message,
18+
ts: new Date(ts),
19+
...(tlm && { tlm: new Date(tlm) }),
20+
_updatedAt: new Date(_updatedAt),
21+
...(pinnedAt && { pinnedAt: new Date(pinnedAt) }),
22+
...(webRtcCallEndTs && { webRtcCallEndTs: new Date(webRtcCallEndTs) }),
23+
...(attachments && {
24+
attachments: attachments.map(({ ts, ...attachment }) => ({
25+
...(ts && { ts: new Date(ts) }),
26+
...attachment,
27+
})),
28+
}),
29+
...(editedAt && { editedAt: new Date(editedAt) }),
30+
...(dlm && { dlm: new Date(dlm) }),
31+
}) as unknown as T;

0 commit comments

Comments
 (0)