0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-27 16:04:15 +01:00

ircd:Ⓜ️ Move room create() definition to modules/client/createroom.

This commit is contained in:
Jason Volk 2018-02-22 14:29:01 -08:00
parent c8091284a1
commit 09519174e2
3 changed files with 143 additions and 68 deletions

View file

@ -264,3 +264,55 @@ ircd::m::leave_ircd_room()
{ {
leave(my_room, me.user_id); leave(my_room, me.user_id);
} }
///////////////////////////////////////////////////////////////////////////////
//
// m/room.h
//
ircd::m::room
ircd::m::create(const id::room &room_id,
const id::user &creator,
const string_view &type)
{
static const auto modname
{
"client_createroom.so"
};
static const auto symname
{
"createroom__type"
};
using prototype = room (const id::room &, const id::user &, const string_view &);
static mods::import<prototype> function;
if(unlikely(!function))
function = { modules.at(modname), symname };
return function(room_id, creator, type);
}
ircd::m::room
ircd::m::create(const id::room &room_id,
const id::user &creator,
const id::room &parent,
const string_view &type)
{
static const auto modname
{
"client_createroom.so"
};
static const auto symname
{
"createroom__parent_type"
};
using prototype = room (const id::room &, const id::user &, const id::room &, const string_view &);
static mods::import<prototype> function;
if(unlikely(!function))
function = { modules.at(modname), symname };
return function(room_id, creator, parent, type);
}

View file

@ -10,66 +10,6 @@
#include <ircd/m/m.h> #include <ircd/m/m.h>
const ircd::m::room::id::buf
init_room_id
{
"init", ircd::my_host()
};
ircd::m::room
ircd::m::create(const id::room &room_id,
const id::user &creator,
const string_view &type)
{
return create(room_id, creator, init_room_id, type);
}
ircd::m::room
ircd::m::create(const id::room &room_id,
const id::user &creator,
const id::room &parent,
const string_view &type)
{
json::iov event;
json::iov content;
const json::iov::push push[]
{
{ event, { "sender", creator }},
{ content, { "creator", creator }},
};
const json::iov::add_if _parent
{
content, !parent.empty() && parent.local() != "init",
{
"parent", parent
}
};
const json::iov::add_if _type
{
content, !type.empty() && type != "room",
{
"type", type
}
};
json::iov::set _set[]
{
{ event, { "depth", 0L }},
{ event, { "type", "m.room.create" }},
{ event, { "state_key", "" }},
};
room room
{
room_id
};
commit(room, event, content);
return room;
}
ircd::m::event::id::buf ircd::m::event::id::buf
ircd::m::join(const room &room, ircd::m::join(const room &room,
const m::id::user &user_id) const m::id::user &user_id)

View file

@ -8,8 +8,30 @@
// copyright notice and this permission notice is present in all copies. The // copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file. // full license for this software is available in the LICENSE file.
using namespace ircd::m;
using namespace ircd; using namespace ircd;
const room::id::buf
init_room_id
{
"init", ircd::my_host()
};
extern "C" room
createroom__parent_type(const id::room &room_id,
const id::user &creator,
const id::room &parent,
const string_view &type);
extern "C" room
createroom__type(const id::room &room_id,
const id::user &creator,
const string_view &type);
extern "C" room
createroom(const id::room &room_id,
const id::user &creator);
mapi::header mapi::header
IRCD_MODULE IRCD_MODULE
{ {
@ -17,7 +39,7 @@ IRCD_MODULE
}; };
resource resource
createroom createroom_resource
{ {
"/_matrix/client/r0/createRoom", "/_matrix/client/r0/createRoom",
{ {
@ -39,22 +61,22 @@ try
unquote(request["visibility"]) unquote(request["visibility"])
}; };
const m::id::user sender_id const id::user sender_id
{ {
request.user_id request.user_id
}; };
const m::id::room::buf room_id const id::room::buf room_id
{ {
m::id::generate, my_host() id::generate, my_host()
}; };
const m::room room const room room
{ {
create(room_id, sender_id) createroom(room_id, sender_id)
}; };
const m::event::id::buf join_event_id const event::id::buf join_event_id
{ {
join(room, sender_id) join(room, sender_id)
}; };
@ -83,8 +105,69 @@ catch(const db::not_found &e)
resource::method resource::method
post_method post_method
{ {
createroom, "POST", post__createroom, createroom_resource, "POST", post__createroom,
{ {
post_method.REQUIRES_AUTH post_method.REQUIRES_AUTH
} }
}; };
room
createroom(const id::room &room_id,
const id::user &creator)
{
return createroom__type(room_id, creator, string_view{});
}
room
createroom__type(const id::room &room_id,
const id::user &creator,
const string_view &type)
{
return createroom__parent_type(room_id, creator, init_room_id, type);
}
room
createroom__parent_type(const id::room &room_id,
const id::user &creator,
const id::room &parent,
const string_view &type)
{
json::iov event;
json::iov content;
const json::iov::push push[]
{
{ event, { "sender", creator }},
{ content, { "creator", creator }},
};
const json::iov::add_if _parent
{
content, !parent.empty() && parent.local() != "init",
{
"parent", parent
}
};
const json::iov::add_if _type
{
content, !type.empty() && type != "room",
{
"type", type
}
};
const json::iov::push _push[]
{
{ event, { "depth", 0L }},
{ event, { "type", "m.room.create" }},
{ event, { "state_key", "" }},
};
room room
{
room_id
};
commit(room, event, content);
return room;
}