Skip to content

Commit

Permalink
Merge pull request #1870 from Bilb/fix-audio-msg-sending
Browse files Browse the repository at this point in the history
fix audio attachments sending blob
  • Loading branch information
Bilb authored Aug 19, 2021
2 parents d325626 + f48b57d commit cb0cead
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
13 changes: 9 additions & 4 deletions ts/components/session/conversation/SessionCompositionBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export interface StagedLinkPreviewData {

export interface StagedAttachmentType extends AttachmentType {
file: File;
path?: string; // a bit hacky, but this is the only way to make our sending audio message be playable, this must be used only for those message
}

export type SendMessageType = {
Expand Down Expand Up @@ -934,18 +935,22 @@ class SessionCompositionBoxInner extends React.Component<Props, State> {
return;
}

const file = new File([audioBlob], 'audio-blob');

const savedAudioFile = await window.Signal.Migrations.processNewAttachment({
data: await audioBlob.arrayBuffer(),
isRaw: true,
url: `session-audio-message-${Date.now()}`,
});
const audioAttachment: StagedAttachmentType = {
file,
file: { ...savedAudioFile, path: savedAudioFile.path },
contentType: MIME.AUDIO_MP3,
size: audioBlob.size,
fileSize: null,
screenshot: null,
fileName: 'audio-message',
fileName: 'session-audio-message',
thumbnail: null,
url: '',
isVoiceMessage: true,
path: savedAudioFile.path,
};

this.props.sendMessage({
Expand Down
5 changes: 1 addition & 4 deletions ts/data/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ function _cleanData(data: any): any {
// eslint-disable-next-line no-continue
continue;
}
// eslint-disable no-param-reassign

if (_.isFunction(value.toNumber)) {
// eslint-disable-next-line no-param-reassign
Expand All @@ -214,16 +215,12 @@ function _cleanData(data: any): any {
// tslint:disable-next-line: no-dynamic-delete
delete data[key];
} else if (Array.isArray(value)) {
// eslint-disable-next-line no-param-reassign
data[key] = value.map(_cleanData);
} else if (_.isObject(value) && value instanceof File) {
// eslint-disable-next-line no-param-reassign
data[key] = { name: value.name, path: value.path, size: value.size, type: value.type };
} else if (_.isObject(value)) {
// eslint-disable-next-line no-param-reassign
data[key] = _cleanData(value);
} else if (_.isBoolean(value)) {
// eslint-disable-next-line no-param-reassign
data[key] = value ? 1 : 0;
} else if (
typeof value !== 'string' &&
Expand Down

0 comments on commit cb0cead

Please sign in to comment.