0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-26 00:32:35 +01:00

ircd:Ⓜ️ Add room_alias -> room_id outsourcing; plug in modules/client/join.

This commit is contained in:
Jason Volk 2018-02-26 04:55:27 -08:00
parent e594063e0c
commit e67ce2b43e
5 changed files with 93 additions and 51 deletions

View file

@ -27,6 +27,9 @@ namespace ircd::m
// [GET] Util // [GET] Util
bool exists(const id::room &); bool exists(const id::room &);
id::room room_id(const mutable_buffer &, const id::room_alias &);
id::room::buf room_id(const id::room_alias &);
// [GET] Current Event suite (non-locking) (one) // [GET] Current Event suite (non-locking) (one)
id::event::buf head(std::nothrow_t, const id::room &, int64_t &); id::event::buf head(std::nothrow_t, const id::room &, int64_t &);
id::event::buf head(const id::room &, uint64_t &); id::event::buf head(const id::room &, uint64_t &);
@ -105,7 +108,6 @@ struct ircd::m::room
// misc // misc
bool membership(const m::id::user &, const string_view &membership = "join") const; bool membership(const m::id::user &, const string_view &membership = "join") const;
room(const alias &, const event::id &event_id = {});
room(const id &room_id, const event::id &event_id = {}) room(const id &room_id, const event::id &event_id = {})
:room_id{room_id} :room_id{room_id}
,event_id{event_id} ,event_id{event_id}

View file

@ -460,6 +460,28 @@ ircd::m::commit(const room &room,
return function(room, event, contents); return function(room, event, contents);
} }
ircd::m::id::room::buf
ircd::m::room_id(const id::room_alias &room_alias)
{
id::room::buf buf;
room_id(buf, room_alias);
return buf;
}
ircd::m::id::room
ircd::m::room_id(const mutable_buffer &out,
const id::room_alias &room_alias)
{
using prototype = id::room (const mutable_buffer &, const id::room_alias &);
static import<prototype> function
{
"client_directory_room", "room_id__room_alias"
};
return function(out, room_alias);
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// //
// m/hook.h // m/hook.h

View file

@ -104,14 +104,6 @@ ircd::m::my(const room &room)
// room // room
// //
ircd::m::room::room(const alias &alias,
const event::id &event_id)
:room_id{}
,event_id{event_id}
{
assert(0); //TODO: translate
}
bool bool
ircd::m::room::membership(const m::id::user &user_id, ircd::m::room::membership(const m::id::user &user_id,
const string_view &membership) const string_view &membership)

View file

@ -26,6 +26,10 @@ directory_room_resource
} }
}; };
extern "C" m::id::room
room_id__room_alias(const mutable_buffer &out,
const m::id::room_alias &);
resource::response resource::response
get__directory_room(client &client, get__directory_room(client &client,
const resource::request &request) const resource::request &request)
@ -35,49 +39,18 @@ get__directory_room(client &client,
url::decode(request.parv[0], room_alias) url::decode(request.parv[0], room_alias)
}; };
//TODO: XXX cache strat char buf[256];
const auto room_id
const unique_buffer<mutable_buffer> buf
{ {
16_KiB m::room_id(buf, room_alias)
}; };
m::v1::query::directory federation_request
{
room_alias, buf
};
//TODO: conf
if(federation_request.wait(seconds(8)) == ctx::future_status::timeout)
{
cancel(federation_request);
return resource::response
{
client, http::REQUEST_TIMEOUT
};
}
const http::code &code
{
federation_request.get()
};
const json::object &response
{
federation_request
};
if(empty(response["room_id"]))
throw m::NOT_FOUND{};
if(empty(response["servers"]))
throw m::NOT_FOUND{};
//TODO: XXX cache strat
return resource::response return resource::response
{ {
client, response client, json::members
{
{ "room_id", room_id }
}
}; };
} }
@ -120,3 +93,58 @@ directory_room_put
{ {
directory_room_resource, "PUT", put__directory_room directory_room_resource, "PUT", put__directory_room
}; };
m::id::room
room_id__room_alias(const mutable_buffer &out,
const m::id::room_alias &alias)
{
//TODO: XXX cache strat
const unique_buffer<mutable_buffer> buf
{
8_KiB //TODO: XXX
};
m::v1::query::directory federation_request
{
alias, buf
};
//TODO: conf
if(federation_request.wait(seconds(8)) == ctx::future_status::timeout)
throw http::error
{
http::REQUEST_TIMEOUT
};
const http::code &code
{
federation_request.get()
};
const json::object &response
{
federation_request
};
if(empty(response["room_id"]))
throw m::NOT_FOUND{};
if(empty(response["servers"]))
throw m::NOT_FOUND{};
const auto &room_id
{
unquote(response.at("room_id"))
};
//TODO: XXX cache strat
return m::room::id
{
string_view
{
data(out), copy(out, room_id)
}
};
}

View file

@ -81,11 +81,9 @@ _post__join(client &client,
const resource::request &request, const resource::request &request,
const m::room::alias &room_alias) const m::room::alias &room_alias)
{ {
throw m::NOT_FOUND{}; //TODO: X const m::room::id::buf room_id
const m::room::id room_id
{ {
m::room_id(room_alias)
}; };
return resource::response return resource::response