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/event.dart b/lib/src/event.dart index f682dc7f..b19cafbb 100644 --- a/lib/src/event.dart +++ b/lib/src/event.dart @@ -792,7 +792,13 @@ class Event extends MatrixEvent { throw ('Unable to decrypt file'); } } - return MatrixFile(bytes: uint8list, name: body); + + final filename = content.tryGet('filename') ?? body; + return MatrixFile( + bytes: uint8list, + name: filename, + mimeType: attachmentMimetype, + ); } /// Returns if this is a known event type. diff --git a/lib/src/room.dart b/lib/src/room.dart index d41c42e3..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, @@ -1322,7 +1324,6 @@ class Room { ); if (onHistoryReceived != null) onHistoryReceived(); - this.prev_batch = resp.end; Future loadFn() async { if (!((resp.chunk.isNotEmpty) && resp.end != null)) return; @@ -1363,13 +1364,14 @@ class Room { : null, ), ), - direction: Direction.b, + direction: direction, ); } if (client.database != null) { await client.database?.transaction(() async { - if (storeInDatabase) { + if (storeInDatabase && direction == Direction.b) { + this.prev_batch = resp.end; await client.database?.setRoomPrevBatch(resp.end, id, client); } await loadFn(); 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