0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-28 11:48:54 +02:00

ircd:Ⓜ️:fed: Add hierarchy request w/ console cmd.

This commit is contained in:
Jason Volk 2022-06-19 13:46:33 -07:00
parent e403c20cc6
commit 3807a4d832
4 changed files with 176 additions and 0 deletions

View file

@ -32,6 +32,7 @@
#include "rooms.h"
#include "send.h"
#include "groups.h"
#include "hierarchy.h"
/// Federation Interface
namespace ircd::m::fed

View file

@ -0,0 +1,43 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2022 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.
#pragma once
#define HAVE_IRCD_M_FED_HIERARCHY_H
namespace ircd::m::fed
{
struct hierarchy;
};
struct ircd::m::fed::hierarchy
:request
{
struct opts;
explicit operator json::object() const
{
return json::object
{
in.content
};
}
hierarchy(const room::id &,
const mutable_buffer &,
opts);
hierarchy() = default;
};
struct ircd::m::fed::hierarchy::opts
:request::opts
{
bool suggested_only {false};
};

View file

@ -8,6 +8,43 @@
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
///////////////////////////////////////////////////////////////////////////////
//
// fed/hierarchy.h
//
ircd::m::fed::hierarchy::hierarchy(const room::id &room_id,
const mutable_buffer &buf_,
opts opts)
:request{[&]
{
assert(!!opts.remote);
if(likely(!defined(json::get<"method"_>(opts.request))))
json::get<"method"_>(opts.request) = "GET";
mutable_buffer buf{buf_};
if(likely(!defined(json::get<"uri"_>(opts.request))))
{
thread_local char ridbuf[768];
json::get<"uri"_>(opts.request) = fmt::sprintf
{
buf, "/_matrix/federation/v1/hierarchy/%s?suggested_only=%s",
url::encode(ridbuf, room_id),
lex_cast(opts.suggested_only),
};
consume(buf, size(json::get<"uri"_>(opts.request)));
}
return request
{
buf, std::move(opts)
};
}()}
{
}
///////////////////////////////////////////////////////////////////////////////
//
// fed/groups.h

View file

@ -14787,6 +14787,101 @@ console_cmd__feds__send(opt &out, const string_view &line)
// fed
//
bool
console_cmd__fed__hierarchy(opt &out, const string_view &line)
{
const params param{line, " ",
{
"room_id", "remote", "op"
}};
const auto &room_id
{
m::room_id(param.at(0))
};
const string_view remote
{
param.at(1, room_id.host())
};
const m::room room
{
room_id
};
const unique_mutable_buffer buf
{
16_KiB
};
m::fed::hierarchy::opts opts
{
m::fed::request::opts
{
.remote = remote
},
.suggested_only = has(param["op"], "suggested"),
};
m::fed::hierarchy request
{
room_id, buf, std::move(opts)
};
request.wait(out.timeout);
request.get();
const json::object &response
{
request
};
if(has(param["op"], "raw"))
{
out << string_view{response} << std::endl;
return true;
}
const json::array &inaccessible
{
response["inaccessible_children"]
};
for(const json::string room_id : inaccessible)
out << "inaccessible: " << room_id << std::endl;
const json::array &children
{
response["children"]
};
for(const json::object child : children)
for(const auto &[k, v] : child)
out << "child: " << std::setw(30) << k << " " << v << std::endl;
const json::object &room_summary
{
response["room"]
};
for(const auto &[k, v] : room_summary)
if(k != "children_state")
out << "room: " << std::setw(30) << k << " " << v << std::endl;
const json::array &children_state
{
room_summary["children_state"]
};
for(const json::object child : children_state)
for(const auto &[k, v] : child)
out << "state: " << std::setw(30) << k << " " << v << std::endl;
return true;
}
bool
console_cmd__fed__groups(opt &out, const string_view &line)
{