|
1 | | -import type { IMessage, Serialized } from '@rocket.chat/core-typings'; |
| 1 | +import type { IDiscussionMessage, IEditedMessage, IMessage, Serialized } from '@rocket.chat/core-typings'; |
2 | 2 |
|
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>({ |
4 | 6 | attachments, |
5 | 7 | tlm, |
6 | 8 | ts, |
7 | 9 | _updatedAt, |
8 | 10 | pinnedAt, |
9 | 11 | webRtcCallEndTs, |
| 12 | + editedAt, |
| 13 | + dlm, |
10 | 14 | ...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