-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow selection of what kind of activity targets to ignore #612
Allow selection of what kind of activity targets to ignore #612
Conversation
vague666
commented
Jan 9, 2017
•
edited
Loading
edited
don't like this very much, we shoulld think of some better way. It's like a quick hack :-) |
I'm not sure there is a better way. Anything else would probably involve major changes to the codebase as I see it. |
Perhaps by modifying |
That change wouldn't be too taxing, sure... it just needs more cowbell |
src/fe-common/core/fe-common-core.c
Outdated
@@ -470,16 +470,23 @@ gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) | |||
return TRUE; | |||
|
|||
if (dest->server_tag != NULL) { | |||
char *tagtarget = g_strdup_printf("%s/%s", dest->server_tag, "*"); | |||
char *tagtarget = g_strdup_printf("%s/%s", dest->server_tag, "#"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the possible tagtarget
values are in the form server_tag/{#,@,*,target}
so it might make sense to have a strarray_find_prefix
function so that you find the first entry matching server_tag/
(the first one is the winner in case of duplicates) and then parse the part after the slash.
(please drop the previous commit and rebase this against master)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll have to explain the git steps one by one :) Close the PR? revert? I do not know!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can git reset
to the commit that diverged from master
and then cherry-pick the changes on a pristine copy of the code 🔨
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you expand what you mean with strarray_find_prefix when used on server_tag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the entries in the list for a given tag start with tagname/
so it makes sense to do a prefix search on the list and then check whether the part after the slash is a @
,#
,*
or a valid target
name.
One more detail jumped to my mind, if the user sets the list to Freenode/@,Freenode/#
should we respect both even though that's better expressed as Freenode/*
?
I should also |
…ypes of targets Syntax: * Ignore activity in all windows # Ignore activity in all channels @ Ignore activity in all queries = Ignore activity in all dcc chats #chan|nick Ignore activity in named target(channel, query, dcc chat) tag/* Ignore all activity on network 'tag' tag/# Ignore activity in all channels on network 'tag' tag/@ Ignore activity in all queries on network 'tag' tag/= Ignore activity in all dcc chats on network 'tag' tag/#chan|nick Ignore activity in named channel/query/dcc chat on network 'tag'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're getting there! I'm really looking forward to see this merged 🎉
src/fe-common/core/fe-common-core.c
Outdated
GSList *targets = NULL, *iterator = NULL; | ||
gboolean found = FALSE; | ||
|
||
if (type != NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible for type
to be NULL
? If so when?
You didn't check for it being NULL
above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a left-over from an earlier attempt
src/fe-common/core/fe-common-core.c
Outdated
if (strarray_find(array, "*") != -1) | ||
const char *type = module_find_id_str("WINDOW ITEM TYPE", dest->window->active->type); | ||
|
||
if ((strarray_find(array, "*") != -1) || // we ignore all targets |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put the check for *
in its own line please (and comments on the line above the one they refer to)
src/fe-common/core/fe-common-core.c
Outdated
const char *type = module_find_id_str("WINDOW ITEM TYPE", dest->window->active->type); | ||
|
||
if ((strarray_find(array, "*") != -1) || // we ignore all targets | ||
(g_ascii_strcasecmp(type, "CHANNEL") == 0 && strarray_find(array, "#") != -1) || // we ignore all channels |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a small helper function taking a TEXT_DEST_REC
and returning an enum depending on whether it is a channel, a dcc query or a regular one would make the code easier to read and avoid many string comparisons.
src/fe-common/core/fe-common-core.c
Outdated
return TRUE; | ||
else if (dest->server_tag != NULL) { | ||
char *prefix = g_strdup_printf("%s/", dest->server_tag); | ||
if (strarray_find_prefix(array, prefix)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apply the early exit pattern here, if the prefix isn't there then we have no business to do (and avoid a whole level of indentation)
src/fe-common/core/fe-common-core.c
Outdated
targets = g_slist_append(targets, g_strdup("@")); | ||
} | ||
|
||
for (iterator = targets; iterator; iterator = iterator->next) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole targets
list is quite wasteful as you just need 4 bits to represent the set of all the possible checks to do (*
, #
, =
, dest->target
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes it easier to build the list for which types to check for
src/fe-common/core/window-items.h
Outdated
WITEM_TYPE_PRIVMSG = 4, | ||
WITEM_TYPE_DCCCHAT = 8, | ||
WITEM_TYPE_OTHER = 16 | ||
} WindowType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WI_TYPE
?
src/fe-common/core/fe-common-core.c
Outdated
return TRUE; | ||
else if (dest->server_tag != NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If server_tag
is NULL
we can just exit
src/core/misc.c
Outdated
item = g_ascii_strdown(item, -1); | ||
index = 0; | ||
for (tmp = array; *tmp != NULL; tmp++, index++) { | ||
if (g_str_has_prefix(g_ascii_strdown(*tmp, -1), item)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
g_ascii_strncasecmp
src/core/misc.c
Outdated
@@ -168,6 +168,24 @@ int strarray_find(char **array, const char *item) | |||
return -1; | |||
} | |||
|
|||
gboolean strarray_find_prefix(char **array, const char *item) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make this match the prototype of strarray_find
src/fe-common/core/fe-common-core.c
Outdated
@@ -462,25 +463,57 @@ void fe_common_core_finish_init(void) | |||
gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) | |||
{ | |||
g_return_val_if_fail(array != NULL, FALSE); | |||
WindowType type = window_item_get_type(dest->window->active); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either make it const
or split the declaration and the initializer.
src/fe-common/core/fe-common-core.c
Outdated
|
||
tagtarget = g_strdup_printf("%s/%s", dest->server_tag, dest->target); | ||
ret = strarray_find(array, tagtarget); | ||
GSList *targets = NULL, *iterator = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Declarations at the top please
src/fe-common/core/fe-common-core.c
Outdated
|
||
g_slist_foreach(targets, (GFunc)g_free, NULL); | ||
g_slist_free(targets); | ||
g_free(prefix); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get rid of prefix
when it is not needed anymore
src/fe-common/core/fe-common-core.c
Outdated
|
||
// we ignore all targets |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the array is empty then we could return early
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
src/fe-common/core/fe-common-core.c
Outdated
g_free(tagtarget); | ||
if (ret != -1) | ||
return TRUE; | ||
g_return_val_if_fail(dest->server_tag != NULL, FALSE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The g_return
macros are only used at the top of the function to do some basic checks on the parameters, the explicit if block was fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I misunderstood your 'use !' comment
src/fe-common/core/fe-common-core.c
Outdated
tagtarget = g_strdup_printf("%s/%s", dest->server_tag, dest->target); | ||
ret = strarray_find(array, tagtarget); | ||
// create a list of types to look for | ||
targets = g_slist_append(targets, g_strdup("*")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to strdup anything since the string literals have a ∞ lifetime and dest->target
is definitely alive when it's feed into printf never to be used again.
src/fe-common/core/window-items.c
Outdated
{ | ||
g_return_val_if_fail(item != NULL, WI_TYPE_OTHER); | ||
|
||
const char *type = module_find_id_str("WINDOW ITEM TYPE", item->type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alignment
WI_TYPE_PRIVMSG = 4, | ||
WI_TYPE_DCCCHAT = 8, | ||
WI_TYPE_OTHER = 16 | ||
} WindowType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WI_TYPE
maybe ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pulled that name from SettingType
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove it
src/core/misc.c
Outdated
|
||
index = 0; | ||
for (tmp = array; *tmp != NULL; tmp++, index++) { | ||
//if (g_str_has_prefix(g_ascii_strdown(*tmp, -1), item)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, forgot :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep fighting the good fight
@@ -461,26 +462,63 @@ void fe_common_core_finish_init(void) | |||
|
|||
gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) | |||
{ | |||
const WindowType type = dest->window->active ? window_item_get_type(dest->window->active) : WI_TYPE_OTHER; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the whole WindowType
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use item = window_item_find_window(dest->window, dest->server, dest->target)
else if (type & WI_TYPE_OTHER) | ||
return FALSE; | ||
// we ignore all channels | ||
else if (type & WI_TYPE_CHANNEL && strarray_find(array, "#") != -1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
static int channel_type = module_get_uniq_id_str("WINDOW ITEM TYPE", "CHANNEL");
... if (item->type == channel_type && ...
if (strarray_find(array, "*") != -1) | ||
return TRUE; | ||
|
||
if (strarray_find(array, dest->target) != -1) | ||
// exit if not a channel or query |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of strarray_find
,, strarray_find_prefix
and GSLists, rewrite the code like this:
- loop once over array
- in each iteration, check if anything that needs to match, does match
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
example check:
if (item != NULL && item->type == channel_type && g_strcmp0(current_element, "#"))
@@ -138,6 +138,21 @@ void window_item_set_active(WINDOW_REC *window, WI_ITEM_REC *item) | |||
} | |||
} | |||
|
|||
WindowType window_item_get_type(WI_ITEM_REC *item) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove it
WI_TYPE_PRIVMSG = 4, | ||
WI_TYPE_DCCCHAT = 8, | ||
WI_TYPE_OTHER = 16 | ||
} WindowType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove it
Superseded by #779 |