Merge branch 'room-enhance-file-upload' into 'master'

[Room] Dont wait for send event while sending files

See merge request famedly/famedlysdk!237
This commit is contained in:
Christian Pauly 2020-03-17 07:55:25 +00:00
commit f93828c461
3 changed files with 22 additions and 28 deletions

View file

@ -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<String> 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<String> 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<String> 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<String> 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<String> 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<String> sendEvent(Map<String, dynamic> content,
{String txid, Event inReplyTo}) async {
final String type = "m.room.message";

View file

@ -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:

View file

@ -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 {