Skip to content

Commit f590b99

Browse files
authored
fix: use file name instead of 'a voice message' for non-voice audio (#651)
<!-- Please read https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before submitting your pull request --> ### Description Only labels audio files as "a voice message" when they actually are voice messages (have waveform data). Regular audio files (music, podcasts) now use the file name as the body text instead. Fixes #543 #### Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ### Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings ### AI disclosure: - [x] Partially AI assisted (clarify which code was AI assisted and briefly explain what it does). - [ ] Fully AI generated (explain what all the generated code does in moderate detail). The `isVoice` check logic was written alongside an AI tool. It checks whether the audio message event contains `waveform` data in `content.info` to distinguish voice messages from regular audio file uploads. If waveform data is absent, the message body falls back to the file name from `content.body` instead of the hardcoded "a voice message" string.
2 parents 72da551 + ea59ca2 commit f590b99

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
default: patch
3+
---
4+
5+
Use file name instead of "a voice message" for non-voice audio files.

src/app/features/room/msgContent.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,12 @@ export type AudioMsgContent = IContent & {
147147
export const getAudioMsgContent = (item: TUploadItem, mxc: string): AudioMsgContent => {
148148
const { file, encInfo, metadata } = item;
149149
const { waveform, audioDuration, markedAsSpoiler } = metadata;
150+
const isVoice = waveform !== undefined && waveform.length > 0;
151+
const fallbackBody = isVoice ? 'a voice message' : file.name;
150152
let content: IContent = {
151153
msgtype: MsgType.Audio,
152154
filename: file.name,
153-
body: item.body && item.body.length > 0 ? item.body : 'a voice message',
155+
body: item.body && item.body.length > 0 ? item.body : fallbackBody,
154156
info: {
155157
mimetype: file.type,
156158
size: file.size,
@@ -162,7 +164,7 @@ export const getAudioMsgContent = (item: TUploadItem, mxc: string): AudioMsgCont
162164
waveform: waveform?.map((v) => Math.round(v * 1024)),
163165
duration: markedAsSpoiler || !audioDuration ? 0 : audioDuration * 1000,
164166
},
165-
'org.matrix.msc1767.text': item.body && item.body.length > 0 ? item.body : 'a voice message',
167+
'org.matrix.msc1767.text': item.body && item.body.length > 0 ? item.body : fallbackBody,
166168
'org.matrix.msc3245.voice.v2': {
167169
duration: markedAsSpoiler || !audioDuration ? 0 : audioDuration,
168170
waveform: waveform?.map((v) => Math.round(v * 1024)),

0 commit comments

Comments
 (0)