[Room] Add method to get an event by the ID.
This commit is contained in:
parent
09b860ca0b
commit
23bcc1acde
|
@ -468,4 +468,17 @@ class Room {
|
||||||
|
|
||||||
return participants;
|
return participants;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Searches for the event in the store. If it isn't found, try to request it
|
||||||
|
/// from the server. Returns null if not found.
|
||||||
|
Future<Event> getEventById(String eventID) async {
|
||||||
|
if (client.store != null) {
|
||||||
|
final Event storeEvent = await client.store.getEventById(eventID, this);
|
||||||
|
if (storeEvent != null) return storeEvent;
|
||||||
|
}
|
||||||
|
final dynamic resp = await client.connection.jsonRequest(
|
||||||
|
type: "GET", action: "/client/r0/rooms/$id/event/$eventID");
|
||||||
|
if (resp is ErrorResponse) return null;
|
||||||
|
return Event.fromJson(resp, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -597,6 +597,14 @@ class Store {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Searches for the event in the store.
|
||||||
|
Future<Event> getEventById(String eventID, Room room) async {
|
||||||
|
List<Map<String, dynamic>> res = await db.rawQuery(
|
||||||
|
"SELECT * FROM Events WHERE id=? AND chat_id=?", [eventID, room.id]);
|
||||||
|
if (res.length == 0) return null;
|
||||||
|
return Event.fromJson(res[0], room);
|
||||||
|
}
|
||||||
|
|
||||||
/// The database sheme for the Client class.
|
/// The database sheme for the Client class.
|
||||||
static final String ClientsScheme = 'CREATE TABLE IF NOT EXISTS Clients(' +
|
static final String ClientsScheme = 'CREATE TABLE IF NOT EXISTS Clients(' +
|
||||||
'client TEXT PRIMARY KEY, ' +
|
'client TEXT PRIMARY KEY, ' +
|
||||||
|
|
|
@ -62,6 +62,20 @@ class FakeMatrixApi extends MockClient {
|
||||||
|
|
||||||
static final Map<String, Map<String, dynamic>> api = {
|
static final Map<String, Map<String, dynamic>> api = {
|
||||||
"GET": {
|
"GET": {
|
||||||
|
"/client/r0/rooms/!localpart:server.abc/event/1234": (var req) => {
|
||||||
|
"content": {
|
||||||
|
"body": "This is an example text message",
|
||||||
|
"msgtype": "m.text",
|
||||||
|
"format": "org.matrix.custom.html",
|
||||||
|
"formatted_body": "<b>This is an example text message</b>"
|
||||||
|
},
|
||||||
|
"type": "m.room.message",
|
||||||
|
"event_id": "143273582443PhrSn:example.org",
|
||||||
|
"room_id": "!localpart:server.abc",
|
||||||
|
"sender": "@example:example.org",
|
||||||
|
"origin_server_ts": 1432735824653,
|
||||||
|
"unsigned": {"age": 1234}
|
||||||
|
},
|
||||||
"/client/r0/rooms/!1234:example.com/messages": (var req) => {
|
"/client/r0/rooms/!1234:example.com/messages": (var req) => {
|
||||||
"start": "t47429-4392820_219380_26003_2265",
|
"start": "t47429-4392820_219380_26003_2265",
|
||||||
"end": "t47409-4357353_219380_26003_2265",
|
"end": "t47409-4357353_219380_26003_2265",
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:famedlysdk/src/Room.dart';
|
import 'package:famedlysdk/src/Room.dart';
|
||||||
import 'package:famedlysdk/src/Client.dart';
|
import 'package:famedlysdk/src/Client.dart';
|
||||||
|
import 'package:famedlysdk/src/Event.dart';
|
||||||
import 'package:famedlysdk/src/User.dart';
|
import 'package:famedlysdk/src/User.dart';
|
||||||
import 'FakeMatrixApi.dart';
|
import 'FakeMatrixApi.dart';
|
||||||
|
|
||||||
|
@ -140,5 +141,10 @@ void main() {
|
||||||
expect(user.avatarUrl.mxc, "mxc://example.org/SEsfnsuifSDFSSEF");
|
expect(user.avatarUrl.mxc, "mxc://example.org/SEsfnsuifSDFSSEF");
|
||||||
expect(user.room.id, "!localpart:server.abc");
|
expect(user.room.id, "!localpart:server.abc");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("getEventByID", () async {
|
||||||
|
final Event event = await room.getEventById("1234");
|
||||||
|
expect(event.id, "143273582443PhrSn:example.org");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue