fix: Always calc correct file extension for voice messages
This commit is contained in:
parent
03ffc51787
commit
2eb3d81dd1
3 changed files with 15 additions and 6 deletions
|
|
@ -34,6 +34,7 @@ import 'package:flutter/services.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:image_picker/image_picker.dart';
|
import 'package:image_picker/image_picker.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
import 'package:mime/mime.dart';
|
||||||
import 'package:scroll_to_index/scroll_to_index.dart';
|
import 'package:scroll_to_index/scroll_to_index.dart';
|
||||||
|
|
||||||
import '../../utils/account_bundles.dart';
|
import '../../utils/account_bundles.dart';
|
||||||
|
|
@ -700,7 +701,7 @@ class ChatController extends State<ChatPageWithRoom>
|
||||||
String path,
|
String path,
|
||||||
int duration,
|
int duration,
|
||||||
List<int> waveform,
|
List<int> waveform,
|
||||||
String? fileName,
|
String fileName,
|
||||||
) async {
|
) async {
|
||||||
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
||||||
final audioFile = XFile(path);
|
final audioFile = XFile(path);
|
||||||
|
|
@ -712,9 +713,17 @@ class ChatController extends State<ChatPageWithRoom>
|
||||||
final bytes = bytesResult.result;
|
final bytes = bytesResult.result;
|
||||||
if (bytes == null) return;
|
if (bytes == null) return;
|
||||||
|
|
||||||
|
final mimeType = lookupMimeType(fileName, headerBytes: bytes);
|
||||||
|
final extension = mimeType == null ? null : extensionFromMime(mimeType);
|
||||||
|
if (extension != null) {
|
||||||
|
fileName =
|
||||||
|
'voice_message_${DateTime.now().millisecondsSinceEpoch}.$extension';
|
||||||
|
}
|
||||||
|
|
||||||
final file = MatrixAudioFile(
|
final file = MatrixAudioFile(
|
||||||
bytes: bytes,
|
bytes: bytes,
|
||||||
name: fileName ?? audioFile.path,
|
name: fileName,
|
||||||
|
mimeType: mimeType,
|
||||||
);
|
);
|
||||||
|
|
||||||
room
|
room
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class RecordingInputRow extends StatelessWidget {
|
class RecordingInputRow extends StatelessWidget {
|
||||||
final RecordingViewModelState state;
|
final RecordingViewModelState state;
|
||||||
final Future<void> Function(String, int, List<int>, String?) onSend;
|
final Future<void> Function(String, int, List<int>, String) onSend;
|
||||||
const RecordingInputRow({
|
const RecordingInputRow({
|
||||||
required this.state,
|
required this.state,
|
||||||
required this.onSend,
|
required this.onSend,
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ class RecordingViewModelState extends State<RecordingViewModel> {
|
||||||
? AudioEncoder.opus
|
? AudioEncoder.opus
|
||||||
: AudioEncoder.aacLc;
|
: AudioEncoder.aacLc;
|
||||||
fileName =
|
fileName =
|
||||||
'recording${DateTime.now().microsecondsSinceEpoch}.${codec.fileExtension}';
|
'voice_message_${DateTime.now().millisecondsSinceEpoch}.${codec.fileExtension}';
|
||||||
String? path;
|
String? path;
|
||||||
if (!kIsWeb) {
|
if (!kIsWeb) {
|
||||||
final tempDir = await getTemporaryDirectory();
|
final tempDir = await getTemporaryDirectory();
|
||||||
|
|
@ -168,7 +168,7 @@ class RecordingViewModelState extends State<RecordingViewModel> {
|
||||||
String path,
|
String path,
|
||||||
int duration,
|
int duration,
|
||||||
List<int> waveform,
|
List<int> waveform,
|
||||||
String? fileName,
|
String fileName,
|
||||||
)
|
)
|
||||||
onSend,
|
onSend,
|
||||||
) async {
|
) async {
|
||||||
|
|
@ -189,7 +189,7 @@ class RecordingViewModelState extends State<RecordingViewModel> {
|
||||||
isSending = true;
|
isSending = true;
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await onSend(path, duration.inMilliseconds, waveform, fileName);
|
await onSend(path, duration.inMilliseconds, waveform, fileName!);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logs().e('Unable to send voice message', e, s);
|
Logs().e('Unable to send voice message', e, s);
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue