From 563629142d560c7654a18472395c76b7533cae26 Mon Sep 17 00:00:00 2001 From: Karthikeyan S Date: Tue, 11 Mar 2025 17:00:12 +0530 Subject: [PATCH 1/5] fix: incorrect mimeType for files when downloading --- lib/src/event.dart | 6 +++++- lib/src/utils/matrix_file.dart | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/src/event.dart b/lib/src/event.dart index f682dc7f..d45176fd 100644 --- a/lib/src/event.dart +++ b/lib/src/event.dart @@ -792,7 +792,11 @@ class Event extends MatrixEvent { throw ('Unable to decrypt file'); } } - return MatrixFile(bytes: uint8list, name: body); + return MatrixFile( + bytes: uint8list, + name: body, + mimeType: attachmentMimetype, + ); } /// Returns if this is a known event type. diff --git a/lib/src/utils/matrix_file.dart b/lib/src/utils/matrix_file.dart index 288eec01..b82adbbd 100644 --- a/lib/src/utils/matrix_file.dart +++ b/lib/src/utils/matrix_file.dart @@ -41,9 +41,10 @@ class MatrixFile { } MatrixFile({required this.bytes, required String name, String? mimeType}) - : mimeType = mimeType ?? - lookupMimeType(name, headerBytes: bytes) ?? - 'application/octet-stream', + : mimeType = mimeType != null && mimeType.isNotEmpty + ? mimeType + : lookupMimeType(name, headerBytes: bytes) ?? + 'application/octet-stream', name = name.split('/').last; /// derivatives the MIME type from the [bytes] and correspondingly creates a From e11878eef6b78b9609b57d7d3fb1ff4ec7d6f7da Mon Sep 17 00:00:00 2001 From: Karthikeyan S Date: Tue, 11 Mar 2025 17:32:43 +0530 Subject: [PATCH 2/5] fix: room prev_batch set incorrectly --- lib/src/room.dart | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/src/room.dart b/lib/src/room.dart index d41c42e3..77338324 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -1322,7 +1322,7 @@ class Room { ); if (onHistoryReceived != null) onHistoryReceived(); - this.prev_batch = resp.end; + final newPrevBatch = direction == Direction.b ? resp.end : resp.start; Future loadFn() async { if (!((resp.chunk.isNotEmpty) && resp.end != null)) return; @@ -1340,8 +1340,7 @@ class Room { events: direction == Direction.b ? resp.chunk : resp.chunk.reversed.toList(), - prevBatch: - direction == Direction.b ? resp.end : resp.start, + prevBatch: newPrevBatch, ), ), } @@ -1355,8 +1354,7 @@ class Room { events: direction == Direction.b ? resp.chunk : resp.chunk.reversed.toList(), - prevBatch: - direction == Direction.b ? resp.end : resp.start, + prevBatch: newPrevBatch, ), ), } @@ -1370,7 +1368,7 @@ class Room { if (client.database != null) { await client.database?.transaction(() async { if (storeInDatabase) { - await client.database?.setRoomPrevBatch(resp.end, id, client); + await client.database?.setRoomPrevBatch(newPrevBatch, id, client); } await loadFn(); }); From 27c8e43dca3878a6a93f31e34796616b91632272 Mon Sep 17 00:00:00 2001 From: Karthikeyan S Date: Wed, 12 Mar 2025 08:21:01 +0530 Subject: [PATCH 3/5] fix: incorrect filename when caption is used in body of event --- lib/src/event.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/event.dart b/lib/src/event.dart index d45176fd..b19cafbb 100644 --- a/lib/src/event.dart +++ b/lib/src/event.dart @@ -792,9 +792,11 @@ class Event extends MatrixEvent { throw ('Unable to decrypt file'); } } + + final filename = content.tryGet('filename') ?? body; return MatrixFile( bytes: uint8list, - name: body, + name: filename, mimeType: attachmentMimetype, ); } From 0d084d8824b256d127409ae6d3d336184612530c Mon Sep 17 00:00:00 2001 From: Karthikeyan S Date: Thu, 13 Mar 2025 10:05:05 +0530 Subject: [PATCH 4/5] fix: room prev_batch set incorrectly follow-up --- lib/src/client.dart | 3 --- lib/src/room.dart | 14 ++++++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index 3be0d26e..6d304717 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -2988,9 +2988,6 @@ class Client extends MatrixApi { chatUpdate.unreadNotifications?.notificationCount ?? 0; rooms[roomIndex].highlightCount = chatUpdate.unreadNotifications?.highlightCount ?? 0; - if (chatUpdate.timeline?.prevBatch != null) { - rooms[roomIndex].prev_batch = chatUpdate.timeline?.prevBatch; - } final summary = chatUpdate.summary; if (summary != null) { diff --git a/lib/src/room.dart b/lib/src/room.dart index 77338324..51b4165f 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -1322,7 +1322,6 @@ class Room { ); if (onHistoryReceived != null) onHistoryReceived(); - final newPrevBatch = direction == Direction.b ? resp.end : resp.start; Future loadFn() async { if (!((resp.chunk.isNotEmpty) && resp.end != null)) return; @@ -1340,7 +1339,8 @@ class Room { events: direction == Direction.b ? resp.chunk : resp.chunk.reversed.toList(), - prevBatch: newPrevBatch, + prevBatch: + direction == Direction.b ? resp.end : resp.start, ), ), } @@ -1354,21 +1354,23 @@ class Room { events: direction == Direction.b ? resp.chunk : resp.chunk.reversed.toList(), - prevBatch: newPrevBatch, + prevBatch: + direction == Direction.b ? resp.end : resp.start, ), ), } : null, ), ), - direction: Direction.b, + direction: direction, ); } if (client.database != null) { await client.database?.transaction(() async { - if (storeInDatabase) { - await client.database?.setRoomPrevBatch(newPrevBatch, id, client); + if (storeInDatabase && direction == Direction.b) { + this.prev_batch = resp.end; + await client.database?.setRoomPrevBatch(resp.end, id, client); } await loadFn(); }); From f89e9f575b9070ccabd7dbe26bffc06d134d5622 Mon Sep 17 00:00:00 2001 From: Krille Date: Thu, 13 Mar 2025 08:15:39 +0100 Subject: [PATCH 5/5] refactor: Add file info to placeholder before sending file event --- lib/src/room.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/src/room.dart b/lib/src/room.dart index 51b4165f..09425c30 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -744,6 +744,8 @@ class Room { 'msgtype': file.msgType, 'body': file.name, 'filename': file.name, + 'info': file.info, + if (extraContent != null) ...extraContent, }, type: EventTypes.Message, eventId: txid,