mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd:Ⓜ️ Add central linkage for join by alias; move bootstrap to rooms/join.
This commit is contained in:
parent
543a1988b9
commit
ff1fe4284d
4 changed files with 178 additions and 137 deletions
|
@ -62,6 +62,7 @@ namespace ircd::m
|
|||
event::id::buf notice(const room &, const string_view &body); // sender is @ircd
|
||||
event::id::buf leave(const room &, const m::id::user &);
|
||||
event::id::buf join(const room &, const m::id::user &);
|
||||
event::id::buf join(const id::room_alias &, const m::id::user &);
|
||||
|
||||
// [SET] Create new room
|
||||
room create(const id::room &, const id::user &creator, const id::room &parent, const string_view &type);
|
||||
|
|
14
ircd/m/m.cc
14
ircd/m/m.cc
|
@ -1085,6 +1085,20 @@ ircd::m::create(const id::room &room_id,
|
|||
return function(room_id, creator, parent, type);
|
||||
}
|
||||
|
||||
ircd::m::event::id::buf
|
||||
ircd::m::join(const id::room_alias &room_alias,
|
||||
const id::user &user_id)
|
||||
{
|
||||
using prototype = event::id::buf (const id::room_alias &, const id::user &);
|
||||
|
||||
static import<prototype> function
|
||||
{
|
||||
"client_rooms", "join__alias_user"
|
||||
};
|
||||
|
||||
return function(room_alias, user_id);
|
||||
}
|
||||
|
||||
ircd::m::event::id::buf
|
||||
ircd::m::join(const room &room,
|
||||
const id::user &user_id)
|
||||
|
|
|
@ -26,11 +26,6 @@ join_resource
|
|||
}
|
||||
};
|
||||
|
||||
static void
|
||||
bootstrap(const m::room::alias &,
|
||||
const m::room::id &,
|
||||
const m::user::id &);
|
||||
|
||||
static resource::response
|
||||
_post__join(client &client,
|
||||
const resource::request &request,
|
||||
|
@ -86,15 +81,15 @@ _post__join(client &client,
|
|||
const resource::request &request,
|
||||
const m::room::alias &room_alias)
|
||||
{
|
||||
const m::room::id::buf room_id
|
||||
m::join(room_alias, request.user_id);
|
||||
|
||||
return resource::response
|
||||
{
|
||||
m::room_id(room_alias)
|
||||
client, json::members
|
||||
{
|
||||
{ "room_id", m::room_id(room_alias) }
|
||||
}
|
||||
};
|
||||
|
||||
if(!exists(room_id))
|
||||
bootstrap(room_alias, room_id, request.user_id);
|
||||
|
||||
return _post__join(client, request, room_id);
|
||||
}
|
||||
|
||||
/// This function forwards the join request to the /rooms/{room_id}/join
|
||||
|
@ -105,7 +100,12 @@ _post__join(client &client,
|
|||
const resource::request &request,
|
||||
const m::room::id &room_id)
|
||||
{
|
||||
m::join(room_id, request.user_id);
|
||||
const m::room room
|
||||
{
|
||||
room_id
|
||||
};
|
||||
|
||||
m::join(room, request.user_id);
|
||||
|
||||
return resource::response
|
||||
{
|
||||
|
@ -115,127 +115,3 @@ _post__join(client &client,
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
static void
|
||||
bootstrap(const m::room::alias &room_alias,
|
||||
const m::room::id &room_id,
|
||||
const m::user::id &user_id)
|
||||
{
|
||||
const unique_buffer<mutable_buffer> buf
|
||||
{
|
||||
16_KiB
|
||||
};
|
||||
|
||||
m::v1::make_join request
|
||||
{
|
||||
room_id, user_id, buf, { room_alias.host() }
|
||||
};
|
||||
|
||||
request.wait(seconds(8)); //TODO: conf
|
||||
const auto code
|
||||
{
|
||||
request.get()
|
||||
};
|
||||
|
||||
const json::object &response
|
||||
{
|
||||
request.in.content
|
||||
};
|
||||
|
||||
const json::object &proto
|
||||
{
|
||||
response.at("event")
|
||||
};
|
||||
|
||||
const auto auth_events
|
||||
{
|
||||
replace(std::string{proto.get("auth_events")}, "\\/", "/")
|
||||
};
|
||||
|
||||
const auto prev_events
|
||||
{
|
||||
replace(std::string{proto.get("prev_events")}, "\\/", "/")
|
||||
};
|
||||
|
||||
json::iov event;
|
||||
json::iov content;
|
||||
const json::iov::push push[]
|
||||
{
|
||||
{ event, { "type", "m.room.member" }},
|
||||
{ event, { "sender", user_id }},
|
||||
{ event, { "state_key", user_id }},
|
||||
{ event, { "membership", "join" }},
|
||||
{ content, { "membership", "join" }},
|
||||
{ event, { "prev_events", prev_events }},
|
||||
{ event, { "auth_events", auth_events }},
|
||||
{ event, { "prev_state", "[]" }},
|
||||
{ event, { "depth", proto.get<long>("depth") }},
|
||||
{ event, { "room_id", room_id }},
|
||||
};
|
||||
|
||||
const m::user user
|
||||
{
|
||||
user_id
|
||||
};
|
||||
|
||||
char displayname_buf[256];
|
||||
const string_view displayname
|
||||
{
|
||||
user.profile(displayname_buf, "displayname")
|
||||
};
|
||||
|
||||
char avatar_url_buf[256];
|
||||
const string_view avatar_url
|
||||
{
|
||||
user.profile(avatar_url_buf, "avatar_url")
|
||||
};
|
||||
|
||||
const json::iov::add_if add_if[]
|
||||
{
|
||||
{ content, !empty(displayname), { "displayname", displayname }},
|
||||
{ content, !empty(avatar_url), { "avatar_url", avatar_url }},
|
||||
};
|
||||
|
||||
m::vm::opts opts;
|
||||
opts.non_conform.set(m::event::conforms::MISSING_MEMBERSHIP);
|
||||
opts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
|
||||
opts.prev_check_exists = false;
|
||||
opts.history = false;
|
||||
opts.infolog_accept = true;
|
||||
const auto event_id
|
||||
{
|
||||
m::vm::commit(event, content, opts)
|
||||
};
|
||||
|
||||
const unique_buffer<mutable_buffer> ebuf
|
||||
{
|
||||
64_KiB
|
||||
};
|
||||
|
||||
const m::event mevent
|
||||
{
|
||||
event_id, ebuf
|
||||
};
|
||||
|
||||
const string_view strung
|
||||
{
|
||||
data(ebuf), serialized(mevent)
|
||||
};
|
||||
|
||||
const unique_buffer<mutable_buffer> buf2
|
||||
{
|
||||
16_KiB
|
||||
};
|
||||
|
||||
m::v1::send_join sj
|
||||
{
|
||||
room_id, event_id, strung, buf2, { room_alias.host() }
|
||||
};
|
||||
|
||||
sj.wait(seconds(8)); //TODO: conf
|
||||
|
||||
const auto sjcode
|
||||
{
|
||||
sj.get()
|
||||
};
|
||||
}
|
||||
|
|
|
@ -13,10 +13,19 @@
|
|||
using namespace ircd::m;
|
||||
using namespace ircd;
|
||||
|
||||
static event::id::buf
|
||||
bootstrap(const m::room::alias &room_alias,
|
||||
const m::room::id &room_id,
|
||||
const m::user::id &user_id);
|
||||
|
||||
extern "C" event::id::buf
|
||||
join__room_user(const room &room,
|
||||
const id::user &user_id);
|
||||
|
||||
extern "C" event::id::buf
|
||||
join__alias_user(const m::room::alias &room_alias,
|
||||
const m::user::id &user_id);
|
||||
|
||||
resource::response
|
||||
post__join(client &client,
|
||||
const resource::request &request,
|
||||
|
@ -85,3 +94,144 @@ join__room_user(const room &room,
|
|||
|
||||
return commit(room, event, content);
|
||||
}
|
||||
|
||||
event::id::buf
|
||||
join__alias_user(const m::room::alias &room_alias,
|
||||
const m::user::id &user_id)
|
||||
{
|
||||
const room::id::buf room_id
|
||||
{
|
||||
m::room_id(room_alias)
|
||||
};
|
||||
|
||||
if(!exists(room_id))
|
||||
return bootstrap(room_alias, room_id, user_id);
|
||||
|
||||
return join__room_user(room_id, user_id);
|
||||
}
|
||||
|
||||
static event::id::buf
|
||||
bootstrap(const m::room::alias &room_alias,
|
||||
const m::room::id &room_id,
|
||||
const m::user::id &user_id)
|
||||
{
|
||||
const unique_buffer<mutable_buffer> buf
|
||||
{
|
||||
16_KiB
|
||||
};
|
||||
|
||||
m::v1::make_join request
|
||||
{
|
||||
room_id, user_id, buf, { room_alias.host() }
|
||||
};
|
||||
|
||||
request.wait(seconds(8)); //TODO: conf
|
||||
const auto code
|
||||
{
|
||||
request.get()
|
||||
};
|
||||
|
||||
const json::object &response
|
||||
{
|
||||
request.in.content
|
||||
};
|
||||
|
||||
const json::object &proto
|
||||
{
|
||||
response.at("event")
|
||||
};
|
||||
|
||||
const auto auth_events
|
||||
{
|
||||
replace(std::string{proto.get("auth_events")}, "\\/", "/")
|
||||
};
|
||||
|
||||
const auto prev_events
|
||||
{
|
||||
replace(std::string{proto.get("prev_events")}, "\\/", "/")
|
||||
};
|
||||
|
||||
json::iov event;
|
||||
json::iov content;
|
||||
const json::iov::push push[]
|
||||
{
|
||||
{ event, { "type", "m.room.member" }},
|
||||
{ event, { "sender", user_id }},
|
||||
{ event, { "state_key", user_id }},
|
||||
{ event, { "membership", "join" }},
|
||||
{ content, { "membership", "join" }},
|
||||
{ event, { "prev_events", prev_events }},
|
||||
{ event, { "auth_events", auth_events }},
|
||||
{ event, { "prev_state", "[]" }},
|
||||
{ event, { "depth", proto.get<long>("depth") }},
|
||||
{ event, { "room_id", room_id }},
|
||||
};
|
||||
|
||||
const m::user user
|
||||
{
|
||||
user_id
|
||||
};
|
||||
|
||||
char displayname_buf[256];
|
||||
const string_view displayname
|
||||
{
|
||||
user.profile(displayname_buf, "displayname")
|
||||
};
|
||||
|
||||
char avatar_url_buf[256];
|
||||
const string_view avatar_url
|
||||
{
|
||||
user.profile(avatar_url_buf, "avatar_url")
|
||||
};
|
||||
|
||||
const json::iov::add_if add_if[]
|
||||
{
|
||||
{ content, !empty(displayname), { "displayname", displayname }},
|
||||
{ content, !empty(avatar_url), { "avatar_url", avatar_url }},
|
||||
};
|
||||
|
||||
m::vm::opts opts;
|
||||
opts.non_conform.set(m::event::conforms::MISSING_MEMBERSHIP);
|
||||
opts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
|
||||
opts.prev_check_exists = false;
|
||||
opts.history = false;
|
||||
opts.infolog_accept = true;
|
||||
const auto event_id
|
||||
{
|
||||
m::vm::commit(event, content, opts)
|
||||
};
|
||||
|
||||
const unique_buffer<mutable_buffer> ebuf
|
||||
{
|
||||
64_KiB
|
||||
};
|
||||
|
||||
const m::event mevent
|
||||
{
|
||||
event_id, ebuf
|
||||
};
|
||||
|
||||
const string_view strung
|
||||
{
|
||||
data(ebuf), serialized(mevent)
|
||||
};
|
||||
|
||||
const unique_buffer<mutable_buffer> buf2
|
||||
{
|
||||
16_KiB
|
||||
};
|
||||
|
||||
m::v1::send_join sj
|
||||
{
|
||||
room_id, event_id, strung, buf2, { room_alias.host() }
|
||||
};
|
||||
|
||||
sj.wait(seconds(8)); //TODO: conf
|
||||
|
||||
const auto sjcode
|
||||
{
|
||||
sj.get()
|
||||
};
|
||||
|
||||
return event_id;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue