mirror of
https://github.com/matrix-construct/construct
synced 2024-09-29 20:28:52 +02:00
modules/m_event: Add pretty_stateline() for state event detail.
This commit is contained in:
parent
d55bb7a762
commit
15dc7d17ef
3 changed files with 133 additions and 78 deletions
|
@ -27,4 +27,8 @@ namespace ircd::m
|
|||
// Informational content-oriented
|
||||
std::ostream &pretty_msgline(std::ostream &, const event &);
|
||||
std::string pretty_msgline(const event &);
|
||||
|
||||
// Informational pretty for state
|
||||
// io=true will run db queries to enhance w/ more information.
|
||||
std::ostream &pretty_stateline(std::ostream &, const event &, const event::id &rel = {}, const event::idx & = 0);
|
||||
}
|
||||
|
|
|
@ -9054,19 +9054,28 @@ console_cmd__room__state__history(opt &out, const string_view &line)
|
|||
room_id, event_id
|
||||
};
|
||||
|
||||
const m::room::state state
|
||||
{
|
||||
room
|
||||
};
|
||||
|
||||
const m::room::state::history history
|
||||
{
|
||||
room, bound
|
||||
};
|
||||
|
||||
history.for_each(type, state_key, [&out]
|
||||
history.for_each(type, state_key, [&out, &room]
|
||||
(const auto &type, const auto &state_key, const auto &depth, const auto &event_idx)
|
||||
{
|
||||
out << std::setw(11) << std::left << event_idx;
|
||||
out << " " << std::setw(9) << std::left << depth;
|
||||
out << " " << std::setw(32) << std::left << type;
|
||||
out << " " << std::setw(64) << std::left << state_key;
|
||||
out << std::endl;
|
||||
const m::event::fetch event
|
||||
{
|
||||
event_idx, std::nothrow
|
||||
};
|
||||
|
||||
if(!event.valid)
|
||||
return true;
|
||||
|
||||
m::pretty_stateline(out, event, room.event_id, event_idx);
|
||||
return true;
|
||||
});
|
||||
|
||||
|
@ -9124,78 +9133,7 @@ console_cmd__room__state__space(opt &out, const string_view &line)
|
|||
if(!event.valid)
|
||||
return true;
|
||||
|
||||
const bool active
|
||||
{
|
||||
state.has(event.event_idx)
|
||||
};
|
||||
|
||||
const bool redacted
|
||||
{
|
||||
m::redacted(event.event_idx)
|
||||
};
|
||||
|
||||
const bool power
|
||||
{
|
||||
m::room::auth::is_power_event(event)
|
||||
};
|
||||
|
||||
const auto auth
|
||||
{
|
||||
m::room::auth::check(std::nothrow, event)
|
||||
};
|
||||
|
||||
char buf[16];
|
||||
const string_view flags
|
||||
{
|
||||
fmt::sprintf
|
||||
{
|
||||
buf, "%c%c%c%c",
|
||||
active? 'A' : ' ',
|
||||
!std::get<bool>(auth)? 'F' : ' ',
|
||||
power? 'P' : ' ',
|
||||
redacted? 'R' : ' ',
|
||||
}
|
||||
};
|
||||
|
||||
thread_local char smbuf[48];
|
||||
if(event.event_id.version() == "1")
|
||||
{
|
||||
out
|
||||
<< smalldate(smbuf, json::get<"origin_server_ts"_>(event) / 1000L)
|
||||
<< std::right << " "
|
||||
<< std::setw(9) << json::get<"depth"_>(event)
|
||||
<< std::right << " [ "
|
||||
<< std::setw(30) << type
|
||||
<< std::left << " | "
|
||||
<< std::setw(50) << state_key
|
||||
<< std::left << " ] " << flags << " "
|
||||
<< std::setw(10) << event.event_idx
|
||||
<< std::left << " "
|
||||
<< std::setw(72) << string_view{event.event_id}
|
||||
<< std::left << " "
|
||||
;
|
||||
} else {
|
||||
out
|
||||
<< std::left
|
||||
<< smalldate(smbuf, json::get<"origin_server_ts"_>(event) / 1000L)
|
||||
<< ' '
|
||||
<< string_view{event.event_id}
|
||||
<< std::right << " "
|
||||
<< std::setw(9) << json::get<"depth"_>(event)
|
||||
<< std::right << " [ "
|
||||
<< std::setw(40) << type
|
||||
<< std::left << " | "
|
||||
<< std::setw(56) << state_key
|
||||
<< std::left << " ] " << flags << " "
|
||||
<< std::setw(10) << event.event_idx
|
||||
<< ' '
|
||||
;
|
||||
}
|
||||
|
||||
if(std::get<1>(auth))
|
||||
out << ":" << trunc(what(std::get<1>(auth)), 72);
|
||||
|
||||
out << std::endl;
|
||||
m::pretty_stateline(out, event, {}, event_idx);
|
||||
return true;
|
||||
});
|
||||
|
||||
|
|
|
@ -18,3 +18,116 @@ IRCD_MODULE
|
|||
{
|
||||
"Matrix event library"
|
||||
};
|
||||
|
||||
std::ostream &
|
||||
IRCD_MODULE_EXPORT
|
||||
ircd::m::pretty_stateline(std::ostream &out,
|
||||
const event &event,
|
||||
const event::id &rel,
|
||||
const event::idx &event_idx)
|
||||
{
|
||||
const room room
|
||||
{
|
||||
json::get<"room_id"_>(event), rel?: event::id{}
|
||||
};
|
||||
|
||||
const room::state &state
|
||||
{
|
||||
room
|
||||
};
|
||||
|
||||
const bool active
|
||||
{
|
||||
event_idx?
|
||||
state.has(event_idx):
|
||||
false
|
||||
};
|
||||
|
||||
const bool redacted
|
||||
{
|
||||
event_idx?
|
||||
bool(m::redacted(event_idx)):
|
||||
false
|
||||
};
|
||||
|
||||
const bool power
|
||||
{
|
||||
m::room::auth::is_power_event(event)
|
||||
};
|
||||
|
||||
const auto auth
|
||||
{
|
||||
event_idx?
|
||||
room::auth::check(std::nothrow, event):
|
||||
room::auth::passfail{true, {}}
|
||||
};
|
||||
|
||||
char buf[16];
|
||||
const string_view flags
|
||||
{
|
||||
fmt::sprintf
|
||||
{
|
||||
buf, "%c%c%c%c",
|
||||
active? 'A' : ' ',
|
||||
!std::get<bool>(auth)? 'F' : ' ',
|
||||
power? 'P' : ' ',
|
||||
redacted? 'R' : ' ',
|
||||
}
|
||||
};
|
||||
|
||||
const auto &type
|
||||
{
|
||||
at<"type"_>(event)
|
||||
};
|
||||
|
||||
const auto &state_key
|
||||
{
|
||||
at<"state_key"_>(event)
|
||||
};
|
||||
|
||||
const auto &depth
|
||||
{
|
||||
at<"depth"_>(event)
|
||||
};
|
||||
|
||||
thread_local char smbuf[48];
|
||||
if(event.event_id.version() == "1")
|
||||
{
|
||||
out
|
||||
<< smalldate(smbuf, json::get<"origin_server_ts"_>(event) / 1000L)
|
||||
<< std::right << " "
|
||||
<< std::setw(9) << json::get<"depth"_>(event)
|
||||
<< std::right << " [ "
|
||||
<< std::setw(30) << type
|
||||
<< std::left << " | "
|
||||
<< std::setw(50) << state_key
|
||||
<< std::left << " ] " << flags << " "
|
||||
<< std::setw(10) << event_idx
|
||||
<< std::left << " "
|
||||
<< std::setw(72) << string_view{event.event_id}
|
||||
<< std::left << " "
|
||||
;
|
||||
} else {
|
||||
out
|
||||
<< std::left
|
||||
<< smalldate(smbuf, json::get<"origin_server_ts"_>(event) / 1000L)
|
||||
<< ' '
|
||||
<< string_view{event.event_id}
|
||||
<< std::right << " "
|
||||
<< std::setw(9) << json::get<"depth"_>(event)
|
||||
<< std::right << " [ "
|
||||
<< std::setw(40) << type
|
||||
<< std::left << " | "
|
||||
<< std::setw(56) << state_key
|
||||
<< std::left << " ] " << flags << " "
|
||||
<< std::setw(10) << event_idx
|
||||
<< ' '
|
||||
;
|
||||
}
|
||||
|
||||
if(std::get<1>(auth))
|
||||
out << ":" << trunc(what(std::get<1>(auth)), 72);
|
||||
|
||||
out << std::endl;
|
||||
return out;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue