✨ Chat message uploading file progress
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:island/models/chat.dart';
|
||||
import 'package:island/models/file.dart';
|
||||
|
||||
class ChatMessages extends Table {
|
||||
TextColumn get id => text()();
|
||||
@ -23,6 +24,7 @@ class LocalChatMessage {
|
||||
final DateTime createdAt;
|
||||
MessageStatus status;
|
||||
final String? nonce;
|
||||
List<UniversalFile>? localAttachments;
|
||||
|
||||
LocalChatMessage({
|
||||
required this.id,
|
||||
@ -30,8 +32,9 @@ class LocalChatMessage {
|
||||
required this.senderId,
|
||||
required this.data,
|
||||
required this.createdAt,
|
||||
required this.nonce,
|
||||
required this.status,
|
||||
this.nonce,
|
||||
this.localAttachments,
|
||||
});
|
||||
|
||||
SnChatMessage toRemoteMessage() {
|
||||
|
@ -14,6 +14,7 @@ class MessageRepository {
|
||||
final AppDatabase _database;
|
||||
|
||||
final Map<String, LocalChatMessage> pendingMessages = {};
|
||||
final Map<String, Map<int, double>> fileUploadProgress = {};
|
||||
|
||||
MessageRepository(this.room, this.identity, this._apiClient, this._database);
|
||||
|
||||
@ -181,6 +182,7 @@ class MessageRepository {
|
||||
SnChatMessage? forwardingTo,
|
||||
SnChatMessage? editingTo,
|
||||
Function(LocalChatMessage)? onPending,
|
||||
Function(String, Map<int, double>)? onProgress,
|
||||
}) async {
|
||||
// Generate a unique nonce for this message
|
||||
final nonce = const Uuid().v4();
|
||||
@ -204,6 +206,7 @@ class MessageRepository {
|
||||
|
||||
// Store in memory and database
|
||||
pendingMessages[localMessage.id] = localMessage;
|
||||
fileUploadProgress[localMessage.id] = {};
|
||||
await _database.saveMessage(_database.messageToCompanion(localMessage));
|
||||
onPending?.call(localMessage);
|
||||
|
||||
@ -225,6 +228,13 @@ class MessageRepository {
|
||||
UniversalFileType.audio => 'audio/unknown',
|
||||
UniversalFileType.file => 'application/octet-stream',
|
||||
},
|
||||
onProgress: (progress, _) {
|
||||
fileUploadProgress[localMessage.id]?[idx] = progress;
|
||||
onProgress?.call(
|
||||
localMessage.id,
|
||||
fileUploadProgress[localMessage.id] ?? {},
|
||||
);
|
||||
},
|
||||
).future;
|
||||
if (cloudFile == null) {
|
||||
throw ArgumentError('Failed to upload the file...');
|
||||
|
Reference in New Issue
Block a user