From f7b03f56683865294c87a1ca25ce7df28e69c14d Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Tue, 17 Mar 2020 07:55:25 +0000 Subject: [PATCH] [Room] Dont wait for send event while sending files --- lib/src/room.dart | 23 +++++++++++++++++++---- pubspec.lock | 25 ++----------------------- test/room_test.dart | 2 +- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/lib/src/room.dart b/lib/src/room.dart index 9b061cb..8787ebd 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -37,6 +37,7 @@ import 'package:famedlysdk/src/utils/session_key.dart'; import 'package:matrix_file_e2ee/matrix_file_e2ee.dart'; import 'package:mime_type/mime_type.dart'; import 'package:olm/olm.dart' as olm; +import 'package:pedantic/pedantic.dart'; import './user.dart'; import 'timeline.dart'; @@ -454,6 +455,8 @@ class Room { return resp["event_id"]; } + /// Sends a normal text message to this room. Returns the event ID generated + /// by the server for this message. Future sendTextEvent(String message, {String txid, Event inReplyTo}) { String type = "m.text"; if (message.startsWith("/me ")) { @@ -465,7 +468,8 @@ class Room { } /// Sends a [file] to this room after uploading it. The [msgType] is optional - /// and will be detected by the mimetype of the file. + /// and will be detected by the mimetype of the file. Returns the mxc uri of + /// the uploaded file. Future sendFileEvent(MatrixFile file, {String msgType = "m.file", String txid, @@ -507,15 +511,18 @@ class Room { "size": file.size, } }; - return await sendEvent(content, txid: txid, inReplyTo: inReplyTo); + unawaited(sendEvent(content, txid: txid, inReplyTo: inReplyTo)); + return uploadResp; } + /// Sends an audio file to this room and returns the mxc uri. Future sendAudioEvent(MatrixFile file, {String txid, Event inReplyTo}) async { return await sendFileEvent(file, msgType: "m.audio", txid: txid, inReplyTo: inReplyTo); } + /// Sends an image to this room and returns the mxc uri. Future sendImageEvent(MatrixFile file, {String txid, int width, int height, Event inReplyTo}) async { return await sendFileEvent(file, @@ -530,6 +537,7 @@ class Room { }); } + /// Sends an video to this room and returns the mxc uri. Future sendVideoEvent(MatrixFile file, {String txid, int videoWidth, @@ -569,10 +577,17 @@ class Room { } } - return await sendFileEvent(file, - msgType: "m.video", txid: txid, inReplyTo: inReplyTo, info: info); + return await sendFileEvent( + file, + msgType: "m.video", + txid: txid, + inReplyTo: inReplyTo, + info: info, + ); } + /// Sends an event to this room with this json as a content. Returns the + /// event ID generated from the server. Future sendEvent(Map content, {String txid, Event inReplyTo}) async { final String type = "m.room.message"; diff --git a/pubspec.lock b/pubspec.lock index 89e440f..0b20c5d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -15,13 +15,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.5.2" - asn1lib: - dependency: transitive - description: - name: asn1lib - url: "https://pub.dartlang.org" - source: hosted - version: "0.5.15" async: dependency: transitive description: @@ -106,13 +99,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.2" - clock: - dependency: transitive - description: - name: clock - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.1" code_builder: dependency: transitive description: @@ -162,13 +148,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.2.7" - encrypt: - dependency: transitive - description: - name: encrypt - url: "https://pub.dartlang.org" - source: hosted - version: "4.0.0" ffi: dependency: transitive description: @@ -279,10 +258,10 @@ packages: description: path: "." ref: "1.x.y" - resolved-ref: "2ca458afed599e1421229460d7c9e9248bb86140" + resolved-ref: b043fcc29031979dc65e5b08e10ebb9b8d2fae30 url: "https://gitlab.com/famedly/libraries/matrix_file_e2ee.git" source: git - version: "1.0.1" + version: "1.0.2" meta: dependency: transitive description: diff --git a/test/room_test.dart b/test/room_test.dart index 03807b0..df94a7e 100644 --- a/test/room_test.dart +++ b/test/room_test.dart @@ -355,7 +355,7 @@ void main() { MatrixFile(bytes: Uint8List(0), path: "fake/path/file.jpeg"); final dynamic resp = await room.sendFileEvent(testFile, msgType: "m.file", txid: "testtxid"); - expect(resp, "42"); + expect(resp, "mxc://example.com/AQwafuaFswefuhsfAFAgsw"); }); test('pushRuleState', () async {