2018-02-04 03:22:01 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
2017-08-23 23:10:28 +02:00
|
|
|
|
|
|
|
using namespace ircd;
|
|
|
|
|
2019-03-06 21:00:47 +01:00
|
|
|
static resource::response
|
|
|
|
post__createroom(client &client,
|
|
|
|
const resource::request::object<m::createroom> &request);
|
|
|
|
|
2018-02-26 10:12:46 +01:00
|
|
|
mapi::header
|
|
|
|
IRCD_MODULE
|
2018-02-22 23:29:01 +01:00
|
|
|
{
|
2018-02-26 10:12:46 +01:00
|
|
|
"Client 7.1.1 :Create Room"
|
|
|
|
};
|
|
|
|
|
2018-02-15 22:06:49 +01:00
|
|
|
resource
|
2018-02-22 23:29:01 +01:00
|
|
|
createroom_resource
|
2017-12-12 21:26:39 +01:00
|
|
|
{
|
2018-02-15 22:06:49 +01:00
|
|
|
"/_matrix/client/r0/createRoom",
|
|
|
|
{
|
|
|
|
"(7.1.1) Create a new room with various configuration options."
|
|
|
|
}
|
2017-08-23 23:10:28 +02:00
|
|
|
};
|
|
|
|
|
2019-03-06 21:00:47 +01:00
|
|
|
resource::method
|
|
|
|
post_method
|
|
|
|
{
|
|
|
|
createroom_resource, "POST", post__createroom,
|
|
|
|
{
|
|
|
|
post_method.REQUIRES_AUTH
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-08-23 23:10:28 +02:00
|
|
|
resource::response
|
2018-02-26 10:12:46 +01:00
|
|
|
post__createroom(client &client,
|
2018-03-05 12:05:59 +01:00
|
|
|
const resource::request::object<m::createroom> &request)
|
2017-08-23 23:10:28 +02:00
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
m::createroom c
|
2017-09-08 11:32:49 +02:00
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
request
|
2017-09-08 11:32:49 +02:00
|
|
|
};
|
|
|
|
|
2019-08-16 07:36:14 +02:00
|
|
|
// unconditionally set/override the room_version here
|
|
|
|
json::get<"room_version"_>(c) = string_view
|
|
|
|
{
|
|
|
|
m::createroom::version_default
|
|
|
|
};
|
|
|
|
|
2019-08-16 07:38:20 +02:00
|
|
|
// unconditionally set the creator
|
2019-03-06 21:00:47 +01:00
|
|
|
json::get<"creator"_>(c) = request.user_id;
|
2017-09-08 11:32:49 +02:00
|
|
|
|
2019-08-16 07:38:20 +02:00
|
|
|
// unconditionally generate a room_id
|
2019-03-06 21:00:47 +01:00
|
|
|
const m::id::room::buf room_id
|
2017-09-08 11:32:49 +02:00
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
m::id::generate, my_host()
|
2017-09-08 11:32:49 +02:00
|
|
|
};
|
|
|
|
|
2019-03-06 21:00:47 +01:00
|
|
|
json::get<"room_id"_>(c) = room_id;
|
|
|
|
|
2019-08-16 07:38:20 +02:00
|
|
|
// conditionally override any preset string that isn't
|
|
|
|
// allowed from this client.
|
2019-08-26 04:11:29 +02:00
|
|
|
if(!m::createroom::spec_preset(json::get<"preset"_>(c)))
|
2019-03-06 21:00:47 +01:00
|
|
|
json::get<"preset"_>(c) = string_view{};
|
|
|
|
|
2019-08-16 07:38:20 +02:00
|
|
|
// the response only contains a room mxid, but we leave some extra buffer
|
|
|
|
// to collect any non-fatal error messages accumulated during the process
|
2019-03-06 21:00:47 +01:00
|
|
|
const unique_buffer<mutable_buffer> buf
|
2019-03-05 21:42:53 +01:00
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
4_KiB
|
2019-03-05 21:42:53 +01:00
|
|
|
};
|
|
|
|
|
2019-03-06 21:00:47 +01:00
|
|
|
json::stack out{buf};
|
2019-03-05 21:42:53 +01:00
|
|
|
json::stack::object top
|
|
|
|
{
|
|
|
|
out
|
|
|
|
};
|
|
|
|
|
2019-08-16 07:38:20 +02:00
|
|
|
// note the room_id is already known (and output buffered) before the
|
|
|
|
// room creation process has even started
|
2019-03-05 21:42:53 +01:00
|
|
|
json::stack::member
|
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
top, "room_id", room_id
|
2019-03-05 21:42:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
json::stack::array errors
|
|
|
|
{
|
|
|
|
top, "errors"
|
|
|
|
};
|
|
|
|
|
2019-03-06 21:00:47 +01:00
|
|
|
const m::room room
|
|
|
|
{
|
|
|
|
m::create(c, &errors)
|
|
|
|
};
|
|
|
|
|
|
|
|
errors.~array();
|
|
|
|
top.~object();
|
|
|
|
return resource::response
|
|
|
|
{
|
2019-08-16 07:38:20 +02:00
|
|
|
client, http::CREATED, json::object
|
|
|
|
{
|
|
|
|
out.completed()
|
|
|
|
}
|
2019-03-06 21:00:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|