1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2025-06-19 00:05:16 +00:00

Simplify conversation files appearance

This commit is contained in:
2021-03-11 00:13:05 +01:00
parent 1f1ed0cda4
commit 52d217a89c
5 changed files with 3 additions and 194 deletions

View File

@ -1,46 +0,0 @@
import 'dart:io';
import 'package:comunic/models/conversation_message.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart';
/// Conversation files helper
///
/// @author Pierre Hubert
class ConversationFilesHelper {
/// Get the path for chat file
static Future<File> getPathForChatFile(
int msgID, ConversationMessageFile fileInfo) async {
Directory basePath = await getTemporaryDirectory();
final storageDir = path.join(basePath.absolute.path, "conversation-files");
final fileName = "$msgID";
return File(path.join(storageDir, fileName));
}
/// Download chat file
static Future<void> download({
@required int msgID,
@required ConversationMessageFile fileInfo,
@required Function(double) onProgress,
@required CancelToken cancelToken,
}) async {
final target = await getPathForChatFile(msgID, fileInfo);
// Create parent directory if required
if (!await target.parent.exists()) {
await target.parent.create(recursive: true);
}
await Dio().download(
fileInfo.url,
target.path,
cancelToken: cancelToken,
onReceiveProgress: (p, t) => onProgress(p / fileInfo.size.toDouble()),
);
}
}