about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-02-20 10:03:36 +0100
committerMichael Vetter <jubalh@iodoru.org>2020-02-20 10:03:36 +0100
commit1ddac7b9c6327e52845aacae6f83ad5d1899c0e6 (patch)
treec3cf61bb7173f03e5ef9f4c16f963ab03f04642b /src
parent80dd3fdbb2ee8c453f5828d8cacb029d222d3779 (diff)
downloadprofani-tty-1ddac7b9c6327e52845aacae6f83ad5d1899c0e6.tar.gz
Put getting mentions in own function
So we can use it somewhere else too.

Regards https://github.com/profanity-im/profanity/issues/1261
Diffstat (limited to 'src')
-rw-r--r--src/common.c15
-rw-r--r--src/common.h1
-rw-r--r--src/event/server_events.c11
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);