diff options
author | James Booth <boothj5@gmail.com> | 2016-04-07 01:01:27 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2016-04-07 01:01:27 +0100 |
commit | f243e333fcb6740ff8d09cc04db27d88040f5f7d (patch) | |
tree | 63a10e47de649d46779c081ce84ff7d16f36aa19 /src/ui | |
parent | 6edf3b3f94eb81413826e1559ee96be0604f3adf (diff) | |
download | profani-tty-f243e333fcb6740ff8d09cc04db27d88040f5f7d.tar.gz |
Added whole word matches for room mention
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/console.c | 10 | ||||
-rw-r--r-- | src/ui/mucwin.c | 49 | ||||
-rw-r--r-- | src/ui/ui.h | 2 |
3 files changed, 34 insertions, 27 deletions
diff --git a/src/ui/console.c b/src/ui/console.c index 69984333..c104e21b 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1550,6 +1550,16 @@ cons_notify_setting(void) else cons_show("Room mention (/notify room) : OFF"); + if (prefs_get_boolean(PREF_NOTIFY_MENTION_CASE_SENSITIVE)) + cons_show("Room mention case (/notify room) : Case sensitive"); + else + cons_show("Room mention case (/notify room) : Case insensitive"); + + if (prefs_get_boolean(PREF_NOTIFY_MENTION_WHOLE_WORD)) + cons_show("Room mention word (/notify room) : Whole word only"); + else + cons_show("Room mention word (/notify room) : Part of word"); + if (prefs_get_boolean(PREF_NOTIFY_ROOM_TRIGGER)) cons_show("Room trigger (/notify room) : ON"); else diff --git a/src/ui/mucwin.c b/src/ui/mucwin.c index 4d323ef1..0b3c65f7 100644 --- a/src/ui/mucwin.c +++ b/src/ui/mucwin.c @@ -359,33 +359,30 @@ mucwin_history(ProfMucWin *mucwin, const char *const nick, GDateTime *timestamp, } static void -_mucwin_print_mention(ProfWin *window, const char *const message, const char *const my_nick) +_mucwin_print_mention(ProfWin *window, const char *const message, const char *const nick, GSList *mentions) { - char *mynick_lower = g_utf8_strdown(my_nick, -1); - char *message_lower = g_utf8_strdown(message, -1); - char message_section[strlen(message) + 1]; + int last_pos = 0; + int pos = 0; + GSList *curr = mentions; + while (curr) { + pos = GPOINTER_TO_INT(curr->data); - int i = 0; - while(!g_str_has_prefix(&message_lower[i], mynick_lower) && i < strlen(message)) { - message_section[i] = message[i]; - i++; - } - message_section[i] = '\0'; + char *before_str = g_strndup(message + last_pos, pos - last_pos); + win_print(window, '-', 0, NULL, NO_DATE | NO_ME | NO_EOL, THEME_ROOMMENTION, "", before_str); + g_free(before_str); + char *nick_str = g_strndup(message + pos, strlen(nick)); + win_print(window, '-', 0, NULL, NO_DATE | NO_ME | NO_EOL, THEME_ROOMMENTION_TERM, "", nick_str); + g_free(nick_str); - char *mention_section = strndup(&message[i], strlen(my_nick)); - int used = strlen(message_section) + strlen(mention_section); + last_pos = pos + strlen(nick); - win_print(window, '-', 0, NULL, NO_DATE | NO_ME | NO_EOL, THEME_ROOMMENTION, "", message_section); - if (strlen(message) > used) { - win_print(window, '-', 0, NULL, NO_DATE | NO_ME | NO_EOL, THEME_ROOMMENTION_TERM, "", mention_section); - _mucwin_print_mention(window, &message[used], my_nick); + curr = g_slist_next(curr); + } + if (last_pos < strlen(message)) { + win_print(window, '-', 0, NULL, NO_DATE | NO_ME, THEME_ROOMMENTION, "", &message[last_pos]); } else { - win_print(window, '-', 0, NULL, NO_DATE | NO_ME, THEME_ROOMMENTION_TERM, "", mention_section); + win_print(window, '-', 0, NULL, NO_DATE | NO_ME, THEME_ROOMMENTION, "", ""); } - - free(mention_section); - g_free(mynick_lower); - g_free(message_lower); } gint @@ -472,17 +469,17 @@ _mucwin_print_triggers(ProfWin *window, const char *const message, GList *trigge } void -mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const message, gboolean mention, GList *triggers) +mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const message, GSList *mentions, GList *triggers) { assert(mucwin != NULL); ProfWin *window = (ProfWin*)mucwin; - char *my_nick = muc_nick(mucwin->roomjid); + char *mynick = muc_nick(mucwin->roomjid); - if (g_strcmp0(nick, my_nick) != 0) { - if (mention) { + if (g_strcmp0(nick, mynick) != 0) { + if (g_slist_length(mentions) > 0) { win_print(window, '-', 0, NULL, NO_ME | NO_EOL, THEME_ROOMMENTION, nick, ""); - _mucwin_print_mention(window, message, my_nick); + _mucwin_print_mention(window, message, mynick, mentions); } else if (triggers) { win_print(window, '-', 0, NULL, NO_ME | NO_EOL, THEME_ROOMTRIGGER, nick, ""); _mucwin_print_triggers(window, message, triggers); diff --git a/src/ui/ui.h b/src/ui/ui.h index ab42f4d1..924ba33c 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -157,7 +157,7 @@ void mucwin_occupant_role_and_affiliation_change(ProfMucWin *mucwin, const char const char *const role, const char *const affiliation, const char *const actor, const char *const reason); void mucwin_roster(ProfMucWin *mucwin, GList *occupants, const char *const presence); void mucwin_history(ProfMucWin *mucwin, const char *const nick, GDateTime *timestamp, const char *const message); -void mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const message, gboolean mention, GList *triggers); +void mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const message, GSList *mentions, GList *triggers); void mucwin_subject(ProfMucWin *mucwin, const char *const nick, const char *const subject); void mucwin_requires_config(ProfMucWin *mucwin); void mucwin_info(ProfMucWin *mucwin); |