[Client] createRoom method with optional params
This commit is contained in:
parent
acc3573e63
commit
4015f36440
|
@ -297,16 +297,26 @@ class Client {
|
||||||
return contacts;
|
return contacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated('Please use [createRoom] instead!')
|
||||||
|
Future<String> createGroup(List<User> users) => createRoom(invite: users);
|
||||||
|
|
||||||
/// Creates a new group chat and invites the given Users and returns the new
|
/// Creates a new group chat and invites the given Users and returns the new
|
||||||
/// created room ID.
|
/// created room ID. If [params] are provided, invite will be ignored. For the
|
||||||
Future<String> createGroup(List<User> users) async {
|
/// moment please look at https://matrix.org/docs/spec/client_server/r0.5.0#post-matrix-client-r0-createroom
|
||||||
|
/// to configure [params].
|
||||||
|
Future<String> createRoom(
|
||||||
|
{List<User> invite, Map<String, dynamic> params}) async {
|
||||||
List<String> inviteIDs = [];
|
List<String> inviteIDs = [];
|
||||||
for (int i = 0; i < users.length; i++) inviteIDs.add(users[i].id);
|
for (int i = 0; i < invite.length; i++) inviteIDs.add(invite[i].id);
|
||||||
|
|
||||||
final dynamic resp = await connection.jsonRequest(
|
final dynamic resp = await connection.jsonRequest(
|
||||||
type: HTTPType.POST,
|
type: HTTPType.POST,
|
||||||
action: "/client/r0/createRoom",
|
action: "/client/r0/createRoom",
|
||||||
data: {"invite": inviteIDs, "preset": "private_chat"});
|
data: params == null
|
||||||
|
? {
|
||||||
|
"invite": inviteIDs,
|
||||||
|
}
|
||||||
|
: params);
|
||||||
|
|
||||||
if (resp is ErrorResponse) {
|
if (resp is ErrorResponse) {
|
||||||
connection.onError.add(resp);
|
connection.onError.add(resp);
|
||||||
|
|
|
@ -262,12 +262,12 @@ void main() {
|
||||||
expect(loginResp, true);
|
expect(loginResp, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('createGroup', () async {
|
test('createRoom', () async {
|
||||||
final List<User> users = [
|
final List<User> users = [
|
||||||
User("@alice:fakeServer.notExisting"),
|
User("@alice:fakeServer.notExisting"),
|
||||||
User("@bob:fakeServer.notExisting")
|
User("@bob:fakeServer.notExisting")
|
||||||
];
|
];
|
||||||
final String newID = await matrix.createGroup(users);
|
final String newID = await matrix.createRoom(invite: users);
|
||||||
expect(newID, "!1234:fakeServer.notExisting");
|
expect(newID, "!1234:fakeServer.notExisting");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue