Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix audio attachments sending blob #1870

Merged
merged 1 commit into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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