From 6ce67a81a1e29601a53cced63eae2b792cb50591 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 27 Jun 2019 01:51:47 -0700 Subject: [PATCH] ircd::m::user::highlight: Add conf items to toggle counting; improve match detail. --- include/ircd/m/user/highlight.h | 6 ++ .../client/sync/rooms/unread_notifications.cc | 19 +++--- modules/m_user.cc | 60 ++++++++++++++++++- 3 files changed, 74 insertions(+), 11 deletions(-) diff --git a/include/ircd/m/user/highlight.h b/include/ircd/m/user/highlight.h index 3ee841038..2f20edad3 100644 --- a/include/ircd/m/user/highlight.h +++ b/include/ircd/m/user/highlight.h @@ -16,6 +16,12 @@ struct ircd::m::user::highlight { m::user user; + static conf::item enable_count; + static conf::item match_mxid_full; + static conf::item match_mxid_local_cs; + static conf::item match_mxid_local_ci; + + bool match(const string_view &text) const; bool has(const event &) const; bool has(const event::idx &) const; diff --git a/modules/client/sync/rooms/unread_notifications.cc b/modules/client/sync/rooms/unread_notifications.cc index eea59536b..0a18469dc 100644 --- a/modules/client/sync/rooms/unread_notifications.cc +++ b/modules/client/sync/rooms/unread_notifications.cc @@ -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; } diff --git a/modules/m_user.cc b/modules/m_user.cc index 5cc4ceaf2..14e9dc74b 100644 --- a/modules/m_user.cc +++ b/modules/m_user.cc @@ -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; }