diff --git a/lib/src/room.dart b/lib/src/room.dart index f46b8a8..4305218 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -549,6 +549,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 4ef6fa2..214bd9c 100644 --- a/test/room_test.dart +++ b/test/room_test.dart @@ -430,6 +430,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"));