diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common.c | 15 | ||||
-rw-r--r-- | src/common.h | 1 | ||||
-rw-r--r-- | src/event/server_events.c | 11 |
3 files changed, 17 insertions, 10 deletions
diff --git a/src/common.c b/src/common.c index 050fc2b7..c056d167 100644 --- a/src/common.c +++ b/src/common.c @@ -510,3 +510,18 @@ get_random_string(int length) return rand; } + +GSList* +get_mentions(gboolean whole_word, gboolean case_sensitive, const char *const message, const char *const nick) +{ + GSList *mentions = NULL; + char *message_search = case_sensitive ? strdup(message) : g_utf8_strdown(message, -1); + char *mynick_search = case_sensitive ? strdup(nick) : g_utf8_strdown(nick, -1); + + mentions = prof_occurrences(mynick_search, message_search, 0, whole_word, &mentions); + + g_free(message_search); + g_free(mynick_search); + + return mentions; +} diff --git a/src/common.h b/src/common.h index 1681d4ab..6924d935 100644 --- a/src/common.h +++ b/src/common.h @@ -99,6 +99,7 @@ gboolean is_notify_enabled(void); GSList* prof_occurrences(const char *const needle, const char *const haystack, int offset, gboolean whole_word, GSList **result); +GSList* get_mentions(gboolean whole_word, gboolean case_sensitive, const char *const message, const char *const nick); int is_regular_file(const char *path); int is_dir(const char *path); diff --git a/src/event/server_events.c b/src/event/server_events.c index e8f11aa3..2272016c 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -319,17 +319,8 @@ sv_ev_room_message(ProfMessage *message) char *old_plain = message->plain; message->plain = plugins_pre_room_message_display(message->jid->barejid, message->jid->resourcepart, message->plain); - gboolean whole_word = prefs_get_boolean(PREF_NOTIFY_MENTION_WHOLE_WORD); - gboolean case_sensitive = prefs_get_boolean(PREF_NOTIFY_MENTION_CASE_SENSITIVE); - char *message_search = case_sensitive ? strdup(message->plain) : g_utf8_strdown(message->plain, -1); - char *mynick_search = case_sensitive ? strdup(mynick) : g_utf8_strdown(mynick, -1); - - GSList *mentions = NULL; - mentions = prof_occurrences(mynick_search, message_search, 0, whole_word, &mentions); + GSList *mentions = get_mentions(prefs_get_boolean(PREF_NOTIFY_MENTION_WHOLE_WORD), prefs_get_boolean(PREF_NOTIFY_MENTION_CASE_SENSITIVE), message->plain, mynick); gboolean mention = g_slist_length(mentions) > 0; - g_free(message_search); - g_free(mynick_search); - GList *triggers = prefs_message_get_triggers(message->plain); _clean_incoming_message(message); |