0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-17 17:38:22 +02:00

ircd:Ⓜ️ Add pretty_msgline() suite.

This commit is contained in:
Jason Volk 2018-09-04 06:35:10 -07:00
parent 79364ef610
commit aeb41e7341
2 changed files with 56 additions and 0 deletions

View file

@ -50,6 +50,10 @@ namespace ircd::m
// Informational pretty string on multiple lines.
std::ostream &pretty(std::ostream &, const event &);
std::string pretty(const event &);
// Informational content-oriented
std::ostream &pretty_msgline(std::ostream &, const event &);
std::string pretty_msgline(const event &);
}
#pragma GCC diagnostic push

View file

@ -231,6 +231,58 @@ ircd::m::pretty_oneline(std::ostream &s,
return s;
}
std::string
ircd::m::pretty_msgline(const event &event)
{
std::string ret;
std::stringstream s;
pubsetbuf(s, ret, 4096);
pretty_msgline(s, event);
resizebuf(s, ret);
return ret;
}
std::ostream &
ircd::m::pretty_msgline(std::ostream &s,
const event &event)
{
s << json::get<"depth"_>(event) << " :";
s << json::get<"type"_>(event) << " ";
s << json::get<"sender"_>(event) << " ";
s << json::get<"event_id"_>(event) << " ";
const auto &state_key
{
json::get<"state_key"_>(event)
};
if(defined(state_key) && empty(state_key))
s << "\"\"" << " ";
else if(defined(state_key))
s << state_key << " ";
else
s << "*" << " ";
const json::object &content
{
json::get<"content"_>(event)
};
switch(hash(json::get<"type"_>(event)))
{
case "m.room.message"_:
s << unquote(content.get("msgtype")) << " ";
s << unquote(content.get("body")) << " ";
break;
default:
s << string_view{content};
break;
}
return s;
}
ircd::m::id::event
ircd::m::make_id(const event &event,
id::event::buf &buf)