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"
|
|
|
|
};
|
|
|
|
|
2019-03-06 21:00:47 +01:00
|
|
|
const m::room::id::buf
|
2018-02-26 10:12:46 +01:00
|
|
|
init_room_id
|
2017-08-23 23:10:28 +02:00
|
|
|
{
|
2018-02-26 10:12:46 +01:00
|
|
|
"init", ircd::my_host()
|
2017-12-12 21:26:39 +01:00
|
|
|
};
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-03-05 23:20:44 +01:00
|
|
|
struct report_error
|
|
|
|
{
|
|
|
|
static thread_local char buf[512];
|
|
|
|
|
|
|
|
template<class... args>
|
2019-03-06 21:00:47 +01:00
|
|
|
report_error(json::stack::array *const &errors,
|
2019-03-05 23:20:44 +01:00
|
|
|
const string_view &room_id,
|
|
|
|
const string_view &user_id,
|
|
|
|
const string_view &fmt,
|
|
|
|
args&&... a);
|
|
|
|
};
|
|
|
|
|
2019-03-08 00:38:49 +01:00
|
|
|
const string_view
|
|
|
|
spec_presets[]
|
|
|
|
{
|
|
|
|
"private_chat",
|
|
|
|
"public_chat",
|
|
|
|
"trusted_private_chat"
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
spec_preset(const string_view &preset)
|
|
|
|
{
|
|
|
|
return std::find(begin(spec_presets), end(spec_presets), preset) != end(spec_presets);
|
|
|
|
}
|
|
|
|
|
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-03-06 21:00:47 +01:00
|
|
|
json::get<"creator"_>(c) = request.user_id;
|
2017-09-08 11:32:49 +02:00
|
|
|
|
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-03-08 00:38:49 +01:00
|
|
|
if(!spec_preset(json::get<"preset"_>(c)))
|
2019-03-06 21:00:47 +01:00
|
|
|
json::get<"preset"_>(c) = string_view{};
|
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
client, http::CREATED, json::object{out.completed()}
|
|
|
|
};
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace ircd::m
|
|
|
|
{
|
|
|
|
static room _create_event(const createroom &);
|
|
|
|
};
|
|
|
|
|
|
|
|
ircd::m::room
|
|
|
|
IRCD_MODULE_EXPORT
|
|
|
|
ircd::m::create(const createroom &c,
|
|
|
|
json::stack::array *const &errors)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const m::user::id &creator
|
|
|
|
{
|
|
|
|
at<"creator"_>(c)
|
|
|
|
};
|
|
|
|
|
|
|
|
// initial create event
|
|
|
|
|
|
|
|
const room room
|
|
|
|
{
|
|
|
|
_create_event(c)
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::room::id &room_id
|
|
|
|
{
|
|
|
|
room.room_id
|
|
|
|
};
|
|
|
|
|
2019-03-07 02:41:56 +01:00
|
|
|
const json::string preset
|
|
|
|
{
|
|
|
|
json::get<"preset"_>(c)
|
|
|
|
};
|
|
|
|
|
2019-03-06 21:00:47 +01:00
|
|
|
// creator join event
|
|
|
|
|
2019-03-07 02:41:56 +01:00
|
|
|
// user rooms don't have their user joined to them at this time otherwise
|
|
|
|
// they'll appear to clients.
|
2019-03-08 00:38:49 +01:00
|
|
|
if(!preset || spec_preset(preset))
|
2017-09-08 11:32:49 +02:00
|
|
|
{
|
2019-03-07 02:41:56 +01:00
|
|
|
const event::id::buf join_event_id
|
|
|
|
{
|
|
|
|
join(room, creator)
|
|
|
|
};
|
|
|
|
}
|
2017-08-23 23:10:28 +02:00
|
|
|
|
2019-03-06 21:00:47 +01:00
|
|
|
// initial power_levels
|
|
|
|
|
2019-03-07 02:41:56 +01:00
|
|
|
// initial power levels aren't set on internal user rooms for now.
|
2019-03-08 00:38:49 +01:00
|
|
|
if(!preset || spec_preset(preset)) try
|
2019-03-05 22:33:52 +01:00
|
|
|
{
|
2019-03-07 02:41:56 +01:00
|
|
|
thread_local char pl_content_buf[4_KiB];
|
2019-03-06 21:00:47 +01:00
|
|
|
send(room, creator, "m.room.power_levels", "",
|
2019-03-05 22:33:52 +01:00
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
json::get<"power_level_content_override"_>(c)?
|
|
|
|
json::get<"power_level_content_override"_>(c):
|
|
|
|
m::room::power::default_content(pl_content_buf, creator)
|
2019-03-05 22:33:52 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
2019-03-05 23:20:44 +01:00
|
|
|
report_error
|
2019-03-05 22:33:52 +01:00
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
errors, room_id, creator, "Failed to set power_levels: %s", e.what()
|
2019-03-05 23:20:44 +01:00
|
|
|
};
|
2019-03-05 22:33:52 +01:00
|
|
|
}
|
|
|
|
|
2019-03-06 21:00:47 +01:00
|
|
|
// initial join_rules
|
|
|
|
|
2019-03-05 22:36:20 +01:00
|
|
|
const string_view &join_rule
|
|
|
|
{
|
|
|
|
preset == "private_chat"? "invite":
|
|
|
|
preset == "trusted_private_chat"? "invite":
|
|
|
|
preset == "public_chat"? "public":
|
|
|
|
"invite"
|
|
|
|
};
|
|
|
|
|
|
|
|
if(join_rule != "invite") try
|
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
send(room, creator, "m.room.join_rules", "",
|
2019-03-05 22:36:20 +01:00
|
|
|
{
|
|
|
|
{ "join_rule", join_rule }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
2019-03-05 23:20:44 +01:00
|
|
|
report_error
|
2019-03-05 22:36:20 +01:00
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
errors, room_id, creator, "Failed to set join_rules: %s", e.what()
|
2019-03-05 23:20:44 +01:00
|
|
|
};
|
2019-03-05 22:36:20 +01:00
|
|
|
}
|
|
|
|
|
2019-03-06 21:00:47 +01:00
|
|
|
// initial history_visibility
|
|
|
|
|
2019-03-05 22:36:20 +01:00
|
|
|
const string_view &history_visibility
|
|
|
|
{
|
|
|
|
preset == "private_chat"? "shared":
|
|
|
|
preset == "trusted_private_chat"? "shared":
|
|
|
|
preset == "public_chat"? "shared":
|
|
|
|
"shared"
|
|
|
|
};
|
|
|
|
|
|
|
|
if(history_visibility != "shared") try
|
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
send(room, creator, "m.room.history_visibility", "",
|
2019-03-05 22:36:20 +01:00
|
|
|
{
|
|
|
|
{ "history_visibility", history_visibility }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
2019-03-05 23:20:44 +01:00
|
|
|
report_error
|
2019-03-05 22:36:20 +01:00
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
errors, room_id, creator, "Failed to set history_visibility: %s", e.what()
|
2019-03-05 23:20:44 +01:00
|
|
|
};
|
2019-03-05 22:36:20 +01:00
|
|
|
}
|
|
|
|
|
2019-03-06 21:00:47 +01:00
|
|
|
// initial guest_access
|
|
|
|
|
2019-03-05 22:36:20 +01:00
|
|
|
const string_view &guest_access
|
|
|
|
{
|
2019-03-05 23:26:45 +01:00
|
|
|
preset == "private_chat"? "forbidden":
|
|
|
|
preset == "trusted_private_chat"? "forbidden":
|
2019-03-05 22:36:20 +01:00
|
|
|
preset == "public_chat"? "forbidden":
|
|
|
|
"forbidden"
|
|
|
|
};
|
|
|
|
|
|
|
|
if(guest_access == "can_join") try
|
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
send(room, creator, "m.room.guest_access", "",
|
2019-03-05 22:36:20 +01:00
|
|
|
{
|
|
|
|
{ "guest_access", "can_join" }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
2019-03-05 23:20:44 +01:00
|
|
|
report_error
|
2019-03-05 22:36:20 +01:00
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
errors, room_id, creator, "Failed to set guest_access: %s", e.what()
|
2019-03-05 23:20:44 +01:00
|
|
|
};
|
2019-03-05 22:36:20 +01:00
|
|
|
}
|
|
|
|
|
2019-03-06 21:00:47 +01:00
|
|
|
// user's initial state vector
|
|
|
|
//
|
2019-03-05 21:04:09 +01:00
|
|
|
// Takes precedence over events set by preset, but gets overriden by name
|
|
|
|
// and topic keys.
|
2019-03-06 21:00:47 +01:00
|
|
|
|
2019-03-05 21:42:53 +01:00
|
|
|
size_t i(0);
|
2019-03-06 21:00:47 +01:00
|
|
|
for(const json::object &event : json::get<"initial_state"_>(c)) try
|
2019-03-05 21:04:09 +01:00
|
|
|
{
|
|
|
|
const json::string &type(event["type"]);
|
|
|
|
const json::string &state_key(event["state_key"]);
|
|
|
|
const json::object &content(event["content"]);
|
2019-03-06 21:00:47 +01:00
|
|
|
send(room, creator, type, state_key, content);
|
2019-03-05 21:42:53 +01:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
2019-03-05 23:20:44 +01:00
|
|
|
report_error
|
2019-03-05 21:42:53 +01:00
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
errors, room_id, creator, "Failed to set initial_state event @%zu: %s",
|
2019-03-05 23:20:44 +01:00
|
|
|
i++,
|
|
|
|
e.what()
|
|
|
|
};
|
2019-03-05 21:04:09 +01:00
|
|
|
}
|
|
|
|
|
2019-03-06 21:00:47 +01:00
|
|
|
// override room name
|
|
|
|
|
|
|
|
if(json::get<"name"_>(c)) try
|
2019-03-05 21:04:09 +01:00
|
|
|
{
|
|
|
|
static const size_t name_max_len
|
|
|
|
{
|
|
|
|
// 14.2.1.3: The name of the room. This MUST NOT exceed 255 bytes.
|
|
|
|
255
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto name
|
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
trunc(json::get<"name"_>(c), name_max_len)
|
2019-03-05 21:04:09 +01:00
|
|
|
};
|
|
|
|
|
2019-03-06 21:00:47 +01:00
|
|
|
send(room, creator, "m.room.name", "",
|
2019-03-05 21:04:09 +01:00
|
|
|
{
|
|
|
|
{ "name", name }
|
|
|
|
});
|
|
|
|
}
|
2019-03-05 21:42:53 +01:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
2019-03-05 23:20:44 +01:00
|
|
|
report_error
|
2019-03-05 21:42:53 +01:00
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
errors, room_id, creator, "Failed to set room name: %s", e.what()
|
2019-03-05 23:20:44 +01:00
|
|
|
};
|
2019-03-05 21:42:53 +01:00
|
|
|
}
|
2019-03-05 21:04:09 +01:00
|
|
|
|
2019-03-06 21:00:47 +01:00
|
|
|
// override topic
|
|
|
|
|
|
|
|
if(json::get<"topic"_>(c)) try
|
2019-03-05 21:04:09 +01:00
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
send(room, creator, "m.room.topic", "",
|
2019-03-05 21:04:09 +01:00
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
{ "topic", json::get<"topic"_>(c) }
|
2019-03-05 21:04:09 +01:00
|
|
|
});
|
|
|
|
}
|
2019-03-05 21:42:53 +01:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
2019-03-05 23:20:44 +01:00
|
|
|
report_error
|
2019-03-05 21:42:53 +01:00
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
errors, room_id, creator, "Failed to set room topic: %s", e.what()
|
2019-03-05 23:20:44 +01:00
|
|
|
};
|
2019-03-05 21:42:53 +01:00
|
|
|
}
|
2019-03-05 21:04:09 +01:00
|
|
|
|
2019-03-06 21:00:47 +01:00
|
|
|
for(const json::string &_user_id : json::get<"invite"_>(c)) try
|
2019-03-05 21:04:09 +01:00
|
|
|
{
|
2019-03-14 23:29:41 +01:00
|
|
|
json::iov content;
|
|
|
|
const json::iov::add is_direct // Conditionally add is_direct
|
|
|
|
{
|
|
|
|
content, json::get<"is_direct"_>(c),
|
|
|
|
{
|
|
|
|
"is_direct", []() -> json::value { return json::literal_true; }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-03-05 21:04:09 +01:00
|
|
|
const m::user::id &user_id{_user_id};
|
2019-03-14 23:29:41 +01:00
|
|
|
invite(room, user_id, creator, content);
|
2019-03-05 21:04:09 +01:00
|
|
|
}
|
2019-04-28 03:33:23 +02:00
|
|
|
catch(const m::error &e)
|
|
|
|
{
|
|
|
|
report_error
|
|
|
|
{
|
|
|
|
errors, room_id, creator, "Failed to invite user '%s' :%s :%s :%s",
|
|
|
|
_user_id,
|
|
|
|
e.what(),
|
|
|
|
e.errcode(),
|
|
|
|
e.errstr()
|
|
|
|
};
|
|
|
|
}
|
2019-03-05 21:42:53 +01:00
|
|
|
catch(const std::exception &e)
|
2017-08-23 23:10:28 +02:00
|
|
|
{
|
2019-03-05 23:20:44 +01:00
|
|
|
report_error
|
2017-08-23 23:10:28 +02:00
|
|
|
{
|
2019-04-28 03:33:23 +02:00
|
|
|
errors, room_id, creator, "Failed to invite user '%s' :%s",
|
2019-03-05 23:20:44 +01:00
|
|
|
_user_id,
|
|
|
|
e.what()
|
|
|
|
};
|
2019-03-05 21:42:53 +01:00
|
|
|
}
|
|
|
|
|
2019-03-06 21:00:47 +01:00
|
|
|
// override guest_access
|
|
|
|
|
|
|
|
if(json::get<"guest_can_join"_>(c) && guest_access != "can_join") try
|
2019-03-05 21:48:58 +01:00
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
send(room, creator, "m.room.guest_access", "",
|
2019-03-05 21:48:58 +01:00
|
|
|
{
|
|
|
|
{ "guest_access", "can_join" }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
2019-03-05 23:20:44 +01:00
|
|
|
report_error
|
2019-03-05 21:48:58 +01:00
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
errors, room_id, creator, "Failed to set guest_access: %s", e.what()
|
2019-03-05 23:20:44 +01:00
|
|
|
};
|
2019-03-05 21:48:58 +01:00
|
|
|
}
|
|
|
|
|
2019-03-06 21:00:47 +01:00
|
|
|
// room directory
|
|
|
|
|
|
|
|
if(json::get<"visibility"_>(c) == "public") try
|
2019-03-05 21:48:58 +01:00
|
|
|
{
|
|
|
|
// This call sends a message to the !public room to list this room in the
|
|
|
|
// public rooms list. We set an empty summary for this room because we
|
|
|
|
// already have its state on this server;
|
|
|
|
m::rooms::summary_set(room.room_id, json::object{});
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
2019-03-05 23:20:44 +01:00
|
|
|
report_error
|
2019-03-05 21:48:58 +01:00
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
errors, room_id, creator, "Failed to set public visibility: %s", e.what()
|
2019-03-05 23:20:44 +01:00
|
|
|
};
|
2019-03-05 21:48:58 +01:00
|
|
|
}
|
|
|
|
|
2019-03-06 21:00:47 +01:00
|
|
|
return room;
|
2017-08-23 23:10:28 +02:00
|
|
|
}
|
|
|
|
catch(const db::not_found &e)
|
|
|
|
{
|
|
|
|
throw m::error
|
|
|
|
{
|
|
|
|
http::CONFLICT, "M_ROOM_IN_USE", "The desired room name is in use."
|
|
|
|
};
|
|
|
|
|
|
|
|
throw m::error
|
|
|
|
{
|
|
|
|
http::CONFLICT, "M_ROOM_ALIAS_IN_USE", "An alias of the desired room is in use."
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-03-06 21:00:47 +01:00
|
|
|
ircd::m::room
|
|
|
|
ircd::m::_create_event(const createroom &c)
|
2017-08-23 23:10:28 +02:00
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
const m::user::id &creator
|
2017-08-23 23:10:28 +02:00
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
at<"creator"_>(c)
|
|
|
|
};
|
2018-02-22 23:29:01 +01:00
|
|
|
|
2019-03-06 21:00:47 +01:00
|
|
|
const auto &type
|
|
|
|
{
|
|
|
|
json::get<"preset"_>(c)
|
|
|
|
};
|
2018-02-22 23:29:01 +01:00
|
|
|
|
2019-03-06 21:00:47 +01:00
|
|
|
const auto &parent
|
|
|
|
{
|
|
|
|
json::get<"parent_room_id"_>(c)
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::object &user_content
|
|
|
|
{
|
|
|
|
json::get<"creation_content"_>(c)
|
|
|
|
};
|
|
|
|
|
|
|
|
const size_t user_content_count
|
|
|
|
{
|
|
|
|
std::min(size(user_content), 16UL) // cap the number of keys
|
|
|
|
};
|
2018-02-22 23:29:01 +01:00
|
|
|
|
|
|
|
json::iov event;
|
|
|
|
json::iov content;
|
2019-03-06 21:00:47 +01:00
|
|
|
json::iov::push _user_content[user_content_count];
|
|
|
|
make_iov(content, _user_content, user_content_count, user_content);
|
2018-02-22 23:29:01 +01:00
|
|
|
const json::iov::push push[]
|
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
{ event, { "depth", 0L }},
|
|
|
|
{ event, { "sender", creator }},
|
|
|
|
{ event, { "state_key", "" }},
|
|
|
|
{ event, { "type", "m.room.create" }},
|
|
|
|
{ content, { "creator", creator }},
|
2018-02-22 23:29:01 +01:00
|
|
|
};
|
|
|
|
|
2018-06-05 20:19:40 +02:00
|
|
|
const json::iov::add _parent
|
2018-02-22 23:29:01 +01:00
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
content, !parent.empty() && m::room::id(parent).local() != "init",
|
2018-02-22 23:29:01 +01:00
|
|
|
{
|
2018-06-05 20:19:40 +02:00
|
|
|
"parent", [&parent]() -> json::value
|
|
|
|
{
|
|
|
|
return parent;
|
|
|
|
}
|
2018-02-22 23:29:01 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-06-05 20:19:40 +02:00
|
|
|
const json::iov::add _type
|
2018-02-22 23:29:01 +01:00
|
|
|
{
|
|
|
|
content, !type.empty() && type != "room",
|
|
|
|
{
|
2018-06-05 20:19:40 +02:00
|
|
|
"type", [&type]() -> json::value
|
|
|
|
{
|
|
|
|
return type;
|
|
|
|
}
|
2018-02-22 23:29:01 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
room room
|
|
|
|
{
|
2019-03-06 21:00:47 +01:00
|
|
|
at<"room_id"_>(c)
|
2018-02-22 23:29:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
commit(room, event, content);
|
|
|
|
return room;
|
|
|
|
}
|
2019-03-05 23:20:44 +01:00
|
|
|
|
|
|
|
decltype(report_error::buf) thread_local
|
|
|
|
report_error::buf;
|
|
|
|
|
|
|
|
template<class... args>
|
2019-03-06 21:00:47 +01:00
|
|
|
report_error::report_error(json::stack::array *const &errors,
|
2019-03-05 23:20:44 +01:00
|
|
|
const string_view &room_id,
|
|
|
|
const string_view &user_id,
|
|
|
|
const string_view &fmt,
|
|
|
|
args&&... a)
|
|
|
|
{
|
|
|
|
const string_view msg{fmt::sprintf
|
|
|
|
{
|
|
|
|
buf, fmt, std::forward<args>(a)...
|
|
|
|
}};
|
|
|
|
|
|
|
|
log::derror
|
|
|
|
{
|
|
|
|
m::log, "Error when creating room %s for user %s :%s",
|
|
|
|
room_id,
|
|
|
|
user_id,
|
|
|
|
msg
|
|
|
|
};
|
|
|
|
|
2019-03-06 21:00:47 +01:00
|
|
|
if(errors)
|
|
|
|
errors->append(msg);
|
2019-03-05 23:20:44 +01:00
|
|
|
}
|