0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-26 00:32:35 +01:00

ircd:Ⓜ️:user::highlight: Add conf items to toggle counting; improve match detail.

This commit is contained in:
Jason Volk 2019-06-27 01:51:47 -07:00
parent 1f1fa501d5
commit 6ce67a81a1
3 changed files with 74 additions and 11 deletions

View file

@ -16,6 +16,12 @@ struct ircd::m::user::highlight
{
m::user user;
static conf::item<bool> enable_count;
static conf::item<bool> match_mxid_full;
static conf::item<bool> match_mxid_local_cs;
static conf::item<bool> match_mxid_local_ci;
bool match(const string_view &text) const;
bool has(const event &) const;
bool has(const event::idx &) const;

View file

@ -116,15 +116,6 @@ ircd::m::sync::room_unread_notifications_polylog(data &data)
if(!apropos(data, start_idx))
return false;
// highlight_count
json::stack::member
{
*data.out, "highlight_count", json::value
{
_highlight_count(room, data.user, start_idx, data.range.second)
}
};
// notification_count
json::stack::member
{
@ -134,6 +125,16 @@ ircd::m::sync::room_unread_notifications_polylog(data &data)
}
};
// highlight_count
if(m::user::highlight::enable_count)
json::stack::member
{
*data.out, "highlight_count", json::value
{
_highlight_count(room, data.user, start_idx, data.range.second)
}
};
return true;
}

View file

@ -49,6 +49,34 @@ user_create(const m::user::id &user_id,
// m/user/highlight.h
//
decltype(ircd::m::user::highlight::enable_count)
ircd::m::user::highlight::enable_count
{
{ "name", "ircd.m.user.highlight.enable.count" },
{ "default", true },
};
decltype(ircd::m::user::highlight::match_mxid_full)
ircd::m::user::highlight::match_mxid_full
{
{ "name", "ircd.m.user.highlight.match.mxid.full" },
{ "default", true },
};
decltype(ircd::m::user::highlight::match_mxid_local_cs)
ircd::m::user::highlight::match_mxid_local_cs
{
{ "name", "ircd.m.user.highlight.match.mxid.local.cs" },
{ "default", true },
};
decltype(ircd::m::user::highlight::match_mxid_local_cs)
ircd::m::user::highlight::match_mxid_local_ci
{
{ "name", "ircd.m.user.highlight.match.mxid.local.ci" },
{ "default", false },
};
size_t
IRCD_MODULE_EXPORT
ircd::m::user::highlight::count()
@ -199,7 +227,7 @@ const
content.get("formatted_body")
};
if(ircd::has(formatted_body, user.user_id))
if(match(formatted_body))
return true;
const string_view &body
@ -207,5 +235,33 @@ const
content.get("body")
};
return ircd::has(body, user.user_id);
if(match(body))
return true;
return false;
}
bool
IRCD_MODULE_EXPORT
ircd::m::user::highlight::match(const string_view &text)
const
{
// Case insensitive and case-sensitive are exlusive; if both
// are true only one branch is taken.
if(match_mxid_local_ci)
{
if(ircd::ihas(text, user.user_id.localname()))
return true;
}
else if(match_mxid_local_cs)
{
if(ircd::has(text, user.user_id.localname()))
return true;
}
if(match_mxid_full)
if(ircd::has(text, user.user_id))
return true;
return false;
}