mirror of
https://github.com/matrix-construct/construct
synced 2024-11-28 17:52:54 +01:00
ircd:Ⓜ️ Add granular options for pretty_msgline().
This commit is contained in:
parent
f6b17e5fed
commit
94d9444988
3 changed files with 42 additions and 17 deletions
|
@ -13,6 +13,8 @@
|
|||
|
||||
namespace ircd::m
|
||||
{
|
||||
struct pretty_opts;
|
||||
|
||||
// Informational pretty string condensed to single line.
|
||||
// fmt = 0: w/o content keys, w/ hashes/sigs
|
||||
// fmt = 1: w/ content keys w/ hashes/sigs
|
||||
|
@ -25,8 +27,8 @@ namespace ircd::m
|
|||
std::string pretty(const event &);
|
||||
|
||||
// Informational content-oriented
|
||||
std::ostream &pretty_msgline(std::ostream &, const event &, const int &fmt = 0);
|
||||
std::string pretty_msgline(const event &, const int &fmt = 0);
|
||||
std::ostream &pretty_msgline(std::ostream &, const event &, const pretty_opts &);
|
||||
std::string pretty_msgline(const event &, const pretty_opts &);
|
||||
|
||||
// Informational pretty for state
|
||||
// io=true will run db queries to enhance w/ more information.
|
||||
|
@ -36,3 +38,17 @@ namespace ircd::m
|
|||
// note: lots of queries.
|
||||
std::ostream &pretty_detailed(std::ostream &, const event &, const event::idx &);
|
||||
}
|
||||
|
||||
struct ircd::m::pretty_opts
|
||||
{
|
||||
event::idx event_idx {0};
|
||||
|
||||
bool show_event_idx {true};
|
||||
bool show_depth {true};
|
||||
bool show_origin_server_ts {true};
|
||||
bool show_event_id {true};
|
||||
bool show_sender {true};
|
||||
bool show_state_key {true};
|
||||
bool show_content {true};
|
||||
bool show_msgtype {true};
|
||||
};
|
||||
|
|
|
@ -610,12 +610,12 @@ ircd::m::pretty_oneline(std::ostream &s,
|
|||
|
||||
std::string
|
||||
ircd::m::pretty_msgline(const event &event,
|
||||
const int &fmt)
|
||||
const pretty_opts &opts)
|
||||
{
|
||||
std::string ret;
|
||||
std::stringstream s;
|
||||
pubsetbuf(s, ret, 4096);
|
||||
pretty_msgline(s, event, fmt);
|
||||
pretty_msgline(s, event, opts);
|
||||
resizebuf(s, ret);
|
||||
return ret;
|
||||
}
|
||||
|
@ -623,24 +623,29 @@ ircd::m::pretty_msgline(const event &event,
|
|||
std::ostream &
|
||||
ircd::m::pretty_msgline(std::ostream &s,
|
||||
const event &event,
|
||||
const int &fmt)
|
||||
const pretty_opts &opts)
|
||||
{
|
||||
const bool text_only
|
||||
(
|
||||
fmt & 1
|
||||
);
|
||||
if(opts.show_event_idx)
|
||||
s << opts.event_idx << ' ';
|
||||
|
||||
if(!text_only)
|
||||
{
|
||||
if(opts.show_depth)
|
||||
s << json::get<"depth"_>(event) << ' ';
|
||||
|
||||
if(opts.show_origin_server_ts)
|
||||
{
|
||||
char sdbuf[48];
|
||||
if(json::get<"origin_server_ts"_>(event) != json::undefined_number)
|
||||
s << smalldate(sdbuf, json::get<"origin_server_ts"_>(event) / 1000L) << ' ';
|
||||
}
|
||||
|
||||
if(opts.show_event_id)
|
||||
s << event.event_id << ' ';
|
||||
|
||||
if(opts.show_sender)
|
||||
s << json::get<"sender"_>(event) << ' ';
|
||||
|
||||
if(opts.show_state_key)
|
||||
{
|
||||
const auto &state_key
|
||||
{
|
||||
json::get<"state_key"_>(event)
|
||||
|
@ -659,7 +664,7 @@ ircd::m::pretty_msgline(std::ostream &s,
|
|||
json::get<"content"_>(event)
|
||||
};
|
||||
|
||||
switch(hash(json::get<"type"_>(event)))
|
||||
if(opts.show_content) switch(hash(json::get<"type"_>(event)))
|
||||
{
|
||||
case "m.room.message"_:
|
||||
{
|
||||
|
@ -678,7 +683,7 @@ ircd::m::pretty_msgline(std::ostream &s,
|
|||
msg.body()
|
||||
};
|
||||
|
||||
if(!text_only)
|
||||
if(opts.show_msgtype)
|
||||
s << type << ' ';
|
||||
else if(type != "m.text")
|
||||
break;
|
||||
|
@ -688,9 +693,6 @@ ircd::m::pretty_msgline(std::ostream &s,
|
|||
}
|
||||
|
||||
default:
|
||||
if(text_only)
|
||||
break;
|
||||
|
||||
s << string_view{content};
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -11559,8 +11559,15 @@ console_cmd__room__messages(opt &out, const string_view &line)
|
|||
if(!seek(std::nothrow, event, event_idx))
|
||||
return true;
|
||||
|
||||
const m::pretty_opts opts
|
||||
{
|
||||
.event_idx = event_idx,
|
||||
.show_event_id = false,
|
||||
.show_state_key = false,
|
||||
};
|
||||
|
||||
out
|
||||
<< pretty_msgline(event)
|
||||
<< pretty_msgline(event, opts)
|
||||
<< std::endl;
|
||||
return ++i < limit;
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue