Implement function to send m.location event
Allows to share the location with a room.
This commit is contained in:
parent
bbd5749aec
commit
ede4fd1416
|
@ -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<String> sendLocation(String body, String geoUri, {String txid}) {
|
||||
final event = <String, dynamic>{
|
||||
'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
|
||||
|
|
|
@ -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"));
|
||||
|
|
Loading…
Reference in a new issue