Merge pull request #152 from ggrog/master

Add "context" notification filter; update docs
This commit is contained in:
John Reese 2015-03-27 12:01:34 -07:00
commit fa7723470e
2 changed files with 74 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
@ -455,11 +476,19 @@ to something similar to "http://domain/#channel/2011-03-09 14:25:09", or
notification if any of the three conditions in the sub-expression are met, while still
requiring all of the conditions outside of the parentheses to also be met.
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 and context`
* `query_conditions` Default: `all`
This option is more or less identical to `channel_conditions`, except that it is used
to filter notifications for private messages.
Specifying `all` is equivalent to:
* `away_only and client_count_less_than and idle and last_active and last_notification and nick_blacklist and replied`
* `debug` Default: `off`
When set to `on`, this option enables debug output for various features, and is useful

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;
}