Add context filter

This commit is contained in:
ggrog 2015-03-25 22:57:12 -05:00
parent 9507c89b56
commit 1a6ee99f54
2 changed files with 66 additions and 1 deletions

View File

@ -407,6 +407,27 @@ to something similar to "http://domain/#channel/2011-03-09 14:25:09", or
If set to `yes`, notifications will only be sent if you have replied to the channel or
query window more recently than the last time a notification was sent for that context.
* `context` Default: `*`
Similar to `highlight`, this is a space-separated list of strings to match against message
contexts using case-insensitive, wildcard matching. Strings will be compared in order
they appear in the configuration value, and the first string to match will end the search,
meaning that earlier strings take priority over later values.
Individual strings may be prefixed with a `-` (hyphen) to negate the match, which makes
the string act as a filter rather than a search.
The wildcard `*` (the default) may be used to match any context.
Examples:
* `#important` - Only messages from the #important channel that match all the other
conditions will be pushed
* `-#notimportant *` - Messages from #nonimportant will be ignored; everything else (`*`)
will be matched
* Set `channel_conditions` to `(highlight or context)` and `context` to `#iwantitall` -
Now you'll get notifications for every message in #iwantitall and messages that match your
highlight rules everywhere else.
### Proxy
@ -457,7 +478,7 @@ to something similar to "http://domain/#channel/2011-03-09 14:25:09", or
Specifying `all` is equivalent to:
* `away_only and client_count_less_than and highlight and idle and last_active and last_notification and nick_blacklist and replied`
* `away_only and client_count_less_than and highlight and idle and last_active and last_notification and nick_blacklist and replied and context`
* `query_conditions` Default: `all`

View File

@ -146,6 +146,7 @@ class CPushMod : public CModule
defaults["last_notification"] = "300";
defaults["nick_blacklist"] = "";
defaults["replied"] = "yes";
defaults["context"] = "*";
// Proxy, for libcurl
defaults["proxy"] = "";
@ -755,6 +756,7 @@ class CPushMod : public CModule
expr("last_notification", last_notification(context))
expr("nick_blacklist", nick_blacklist(nick))
expr("replied", replied(context))
expr("context", context_filter(context))
else
{
@ -853,6 +855,47 @@ class CPushMod : public CModule
return false;
}
/**
* Determine if the given context matches any context rules.
*
* @param context The context of a message
* @return True if context matches the filter
*/
bool context_filter(const CString& context)
{
if (context == "all" || context == "*")
return true;
VCString values;
options["context"].Split(" ", values, false);
for (VCString::iterator i = values.begin(); i != values.end(); i++)
{
CString value = i->AsLower();
char prefix = value[0];
bool push = true;
if (prefix == '-')
{
push = false;
value.LeftChomp(1);
}
if (value != "*")
{
value = "*" + value.AsLower() + "*";
}
if (context.WildCmp(value))
{
return push;
}
}
return false;
}
/**
* Check if the idle condition is met.
*
@ -971,6 +1014,7 @@ class CPushMod : public CModule
&& last_notification(context)
&& nick_blacklist(nick)
&& replied(context)
&& context_filter(context)
&& true;
}