Skip to content

Commit 855177a

Browse files
committed
Add timestamps to plain-text chat transcript export, formatted in local timezone
1 parent 5fff8f2 commit 855177a

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

web/pages/messages/[channelId].tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {User} from 'common/user'
77
import {buildArray, filterDefined} from 'common/util/array'
88
import {cleanDoc, richTextToString} from 'common/util/parse'
99
import {DAY_MS, YEAR_MS} from 'common/util/time'
10+
import dayjs from 'dayjs'
1011
import {keyBy, uniq} from 'lodash'
1112
import {useRouter} from 'next/router'
1213
import {useCallback, useEffect, useState} from 'react'
@@ -116,10 +117,11 @@ export const getFirstName = (name: string) => {
116117

117118
/**
118119
* Renders the loaded messages as a plain-text transcript, oldest first:
119-
* Martin (me): hello
120+
* [2026-08-03 14:32] Martin (me): hello
120121
*
121-
* Liz: hi
122-
* System status messages (joined/left the chat) are left out.
122+
* [2026-08-03 14:35] Liz: hi
123+
* Timestamps are in the reader's local timezone. System status messages (joined/left the chat) are
124+
* left out.
123125
*/
124126
export const messagesToPlainText = (
125127
messages: ChatMessage[] | undefined,
@@ -141,7 +143,12 @@ export const messagesToPlainText = (
141143
.slice()
142144
.reverse()
143145
.filter((m) => m.visibility !== 'system_status')
144-
.map((m) => `${nameOf(m.userId)}: ${richTextToString(m.content).trim()}`)
146+
.map(
147+
(m) =>
148+
`[${dayjs(m.createdTime).format('YYYY-MM-DD HH:mm')}] ${nameOf(m.userId)}: ${richTextToString(
149+
m.content,
150+
).trim()}`,
151+
)
145152
.join('\n\n')
146153
)
147154
}

0 commit comments

Comments
 (0)