From ede4fd1416549f0ff649e7194757926f362b4096 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Tue, 4 Aug 2020 22:20:22 +0200 Subject: [PATCH] Implement function to send m.location event Allows to share the location with a room. --- lib/src/room.dart | 11 +++++++++++ test/room_test.dart | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/src/room.dart b/lib/src/room.dart index 234ad39..d5decb8 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -539,6 +539,17 @@ class Room { }, type: EventTypes.Reaction, txid: txid); } + /// Sends the location with description [body] and geo URI [geoUri] into a room. + /// Returns the event ID generated by the server for this message. + Future sendLocation(String body, String geoUri, {String txid}) { + final event = { + 'msgtype': 'm.location', + 'body': body, + 'geo_uri': geoUri, + }; + return sendEvent(event, txid: txid); + } + /// Sends a [file] to this room after uploading it. Returns the mxc uri of /// the uploaded file. If [waitUntilSent] is true, the future will wait until /// the message event has received the server. Otherwise the future will only diff --git a/test/room_test.dart b/test/room_test.dart index 5bad302..df27b80 100644 --- a/test/room_test.dart +++ b/test/room_test.dart @@ -434,6 +434,25 @@ void main() { }); }); + test('send location', () async { + FakeMatrixApi.calledEndpoints.clear(); + + final body = 'Middle of the ocean'; + final geoUri = 'geo:0.0,0.0'; + final dynamic resp = + await room.sendLocation(body, geoUri, txid: 'testtxid'); + expect(resp.startsWith('\$event'), true); + + final entry = FakeMatrixApi.calledEndpoints.entries + .firstWhere((p) => p.key.contains('/send/m.room.message/')); + final content = json.decode(entry.value.first); + expect(content, { + 'msgtype': 'm.location', + 'body': body, + 'geo_uri': geoUri, + }); + }); + // Not working because there is no real file to test it... /*test('sendImageEvent', () async { final File testFile = File.fromUri(Uri.parse("fake/path/file.jpeg"));