mirror of
https://github.com/matrix-construct/construct
synced 2025-03-14 05:20:17 +01:00
ircd:Ⓜ️:bridge: Refactor config interface; remove central !bridge room related.
This commit is contained in:
parent
5fb3710d4f
commit
207997ac95
4 changed files with 68 additions and 88 deletions
|
@ -18,7 +18,6 @@ namespace ircd::m::bridge
|
|||
struct config;
|
||||
struct query;
|
||||
|
||||
bool exists(const string_view &id);
|
||||
string_view make_uri(const mutable_buffer &, const config &, const string_view &path);
|
||||
|
||||
extern log::log log;
|
||||
|
@ -106,16 +105,13 @@ struct ircd::m::bridge::config
|
|||
json::property<name::protocols, json::array>
|
||||
>
|
||||
{
|
||||
using closure_bool = std::function<bool (const event::idx &, const config &)>;
|
||||
using closure = std::function<void (const event::idx &, const config &)>;
|
||||
|
||||
static event::idx idx(std::nothrow_t, const string_view &id);
|
||||
static event::idx idx(const string_view &id);
|
||||
|
||||
static bool get(std::nothrow_t, const string_view &id, const closure &);
|
||||
static void get(const string_view &id, const closure &);
|
||||
using closure_bool = std::function<bool (const event::idx &, const event &, const config &)>;
|
||||
using closure = std::function<void (const event::idx &, const event &, const config &)>;
|
||||
|
||||
static bool for_each(const closure_bool &);
|
||||
static bool get(std::nothrow_t, const string_view &id, const closure &);
|
||||
static void get(const string_view &id, const closure &);
|
||||
static bool exists(const string_view &id);
|
||||
|
||||
using super_type::tuple;
|
||||
};
|
||||
|
|
125
matrix/bridge.cc
125
matrix/bridge.cc
|
@ -39,12 +39,6 @@ ircd::m::bridge::make_uri(const mutable_buffer &buf,
|
|||
};
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::bridge::exists(const string_view &id)
|
||||
{
|
||||
return config::idx(std::nothrow, id);
|
||||
}
|
||||
|
||||
//
|
||||
// query
|
||||
//
|
||||
|
@ -143,29 +137,11 @@ ircd::m::bridge::query::query(const config &config,
|
|||
//
|
||||
|
||||
bool
|
||||
ircd::m::bridge::config::for_each(const closure_bool &closure)
|
||||
ircd::m::bridge::config::exists(const string_view &id)
|
||||
{
|
||||
const m::room::id::buf bridge_room_id
|
||||
return get(std::nothrow, id, []
|
||||
(const auto &, const auto &, const auto &)
|
||||
{
|
||||
"bridge", my_host()
|
||||
};
|
||||
|
||||
const m::room::state state
|
||||
{
|
||||
bridge_room_id
|
||||
};
|
||||
|
||||
return state.for_each("ircd.bridge", [&closure]
|
||||
(const string_view &type, const string_view &state_key, const event::idx &event_idx)
|
||||
{
|
||||
bool ret{true};
|
||||
m::get(std::nothrow, event_idx, "content", [&event_idx, &closure, &ret]
|
||||
(const json::object &content)
|
||||
{
|
||||
ret = closure(event_idx, content);
|
||||
});
|
||||
|
||||
return ret;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -173,11 +149,11 @@ void
|
|||
ircd::m::bridge::config::get(const string_view &id,
|
||||
const closure &closure)
|
||||
{
|
||||
if(!get(std::nothrow, id, closure))
|
||||
if(unlikely(!get(std::nothrow, id, closure)))
|
||||
throw m::NOT_FOUND
|
||||
{
|
||||
"Configuration for appservice '%s' not found.",
|
||||
id
|
||||
"No bridge config found for '%s'",
|
||||
id,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -186,49 +162,68 @@ ircd::m::bridge::config::get(std::nothrow_t,
|
|||
const string_view &id,
|
||||
const closure &closure)
|
||||
{
|
||||
const auto event_idx
|
||||
return !config::for_each([&id, &closure]
|
||||
(const auto &event_idx, const auto &event, const config &config)
|
||||
{
|
||||
idx(std::nothrow, id)
|
||||
};
|
||||
if(json::get<"id"_>(config) != id)
|
||||
return true;
|
||||
|
||||
return m::get(std::nothrow, event_idx, "content", [&event_idx, &closure]
|
||||
(const json::object &content)
|
||||
{
|
||||
closure(event_idx, content);
|
||||
closure(event_idx, event, config);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
ircd::m::event::idx
|
||||
ircd::m::bridge::config::idx(const string_view &id)
|
||||
bool
|
||||
ircd::m::bridge::config::for_each(const closure_bool &closure)
|
||||
{
|
||||
const auto ret
|
||||
return events::type::for_each_in("ircd.bridge", [&closure]
|
||||
(const string_view &, const event::idx &event_idx)
|
||||
{
|
||||
idx(std::nothrow, id)
|
||||
};
|
||||
|
||||
if(!ret)
|
||||
throw m::NOT_FOUND
|
||||
const m::event::fetch event
|
||||
{
|
||||
"Configuration for appservice '%s' not found.",
|
||||
id
|
||||
std::nothrow, event_idx
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::m::event::idx
|
||||
ircd::m::bridge::config::idx(std::nothrow_t,
|
||||
const string_view &id)
|
||||
{
|
||||
const m::room::id::buf bridge_room_id
|
||||
{
|
||||
"bridge", my_host()
|
||||
};
|
||||
|
||||
const m::room::state state
|
||||
{
|
||||
bridge_room_id
|
||||
};
|
||||
|
||||
return state.get("ircd.bridge", id);
|
||||
if(unlikely(!event.valid))
|
||||
return true;
|
||||
|
||||
if(!my(event))
|
||||
return true;
|
||||
|
||||
if(!defined(json::get<"state_key"_>(event)))
|
||||
return true;
|
||||
|
||||
const bridge::config config
|
||||
{
|
||||
json::get<"content"_>(event)
|
||||
};
|
||||
|
||||
if(!json::get<"id"_>(config))
|
||||
return true;
|
||||
|
||||
// the state_key has to match the id for now
|
||||
if(json::get<"id"_>(config) != json::get<"state_key"_>(event))
|
||||
return true;
|
||||
|
||||
// filter replaced state
|
||||
if(room::state::next(event_idx))
|
||||
return true;
|
||||
|
||||
// filter redacted state
|
||||
if(redacted(event_idx))
|
||||
return true;
|
||||
|
||||
const user::id sender
|
||||
{
|
||||
json::get<"sender"_>(event)
|
||||
};
|
||||
|
||||
if(!is_oper(sender))
|
||||
return true;
|
||||
|
||||
if(likely(closure(event_idx, event, config)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -104,16 +104,6 @@ try
|
|||
control_room_id
|
||||
};
|
||||
|
||||
const m::room::id::buf bridge_room_id
|
||||
{
|
||||
"bridge", origin(*this)
|
||||
};
|
||||
|
||||
const m::room bridge_room
|
||||
{
|
||||
bridge_room_id
|
||||
};
|
||||
|
||||
if(my_id.hostname() == "localhost")
|
||||
log::warning
|
||||
{
|
||||
|
@ -133,7 +123,6 @@ try
|
|||
create(public_room, me);
|
||||
create(alias_room, me);
|
||||
create(control_room, me);
|
||||
create(bridge_room, me);
|
||||
|
||||
send(my_room, me, "m.room.name", "",
|
||||
{
|
||||
|
|
|
@ -16901,7 +16901,7 @@ console_cmd__bridge(opt &out, const string_view &line)
|
|||
if(!id)
|
||||
{
|
||||
m::bridge::config::for_each([&out]
|
||||
(const auto &event_idx, const m::bridge::config &config)
|
||||
(const auto &event_idx, const auto &event, const m::bridge::config &config)
|
||||
{
|
||||
out
|
||||
<< json::get<"id"_>(config)
|
||||
|
@ -16913,7 +16913,7 @@ console_cmd__bridge(opt &out, const string_view &line)
|
|||
}
|
||||
|
||||
m::bridge::config::get(id, [&out]
|
||||
(const auto &event_idx, const m::bridge::config &config)
|
||||
(const auto &event_idx, const auto &event, const m::bridge::config &config)
|
||||
{
|
||||
for(const auto &[key, val] : config.source)
|
||||
out
|
||||
|
@ -16946,7 +16946,7 @@ console_cmd__bridge__query(opt &out, const string_view &line)
|
|||
|
||||
std::string config;
|
||||
m::bridge::config::get(bridge_id, [&config]
|
||||
(const auto &, const auto &object)
|
||||
(const auto &, const auto &, const auto &object)
|
||||
{
|
||||
config = object.source;
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue