0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +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);
}
///////////////////////////////////////////////////////////////////////////////
//
// 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>
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::join(const room &room,
const m::id::user &user_id)

View file

@ -8,8 +8,30 @@
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
using namespace ircd::m;
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
IRCD_MODULE
{
@ -17,7 +39,7 @@ IRCD_MODULE
};
resource
createroom
createroom_resource
{
"/_matrix/client/r0/createRoom",
{
@ -39,22 +61,22 @@ try
unquote(request["visibility"])
};
const m::id::user sender_id
const id::user sender_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)
};
@ -83,8 +105,69 @@ catch(const db::not_found &e)
resource::method
post_method
{
createroom, "POST", post__createroom,
createroom_resource, "POST", post__createroom,
{
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;
}