mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Tidy handling room mention and room triggers
This commit is contained in:
parent
d63910ffc8
commit
5ff9fbd810
@ -211,10 +211,11 @@ prefs_do_chat_notify(gboolean current_win, const char *const message)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
prefs_message_contains_trigger(const char *const message)
|
||||
GList*
|
||||
prefs_message_get_triggers(const char *const message)
|
||||
{
|
||||
gboolean trigger_found = FALSE;
|
||||
GList *result = NULL;
|
||||
|
||||
char *message_lower = g_utf8_strdown(message, -1);
|
||||
gsize len = 0;
|
||||
gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL);
|
||||
@ -222,21 +223,20 @@ prefs_message_contains_trigger(const char *const message)
|
||||
for (i = 0; i < len; i++) {
|
||||
char *trigger_lower = g_utf8_strdown(triggers[i], -1);
|
||||
if (g_strrstr(message_lower, trigger_lower)) {
|
||||
trigger_found = TRUE;
|
||||
g_free(trigger_lower);
|
||||
break;
|
||||
result = g_list_append(result, strdup(triggers[i]));
|
||||
}
|
||||
g_free(trigger_lower);
|
||||
}
|
||||
g_strfreev(triggers);
|
||||
g_free(message_lower);
|
||||
|
||||
return trigger_found;
|
||||
return result;
|
||||
}
|
||||
|
||||
gboolean
|
||||
prefs_do_room_notify(gboolean current_win, const char *const roomjid, const char *const nick,
|
||||
const char *const message)
|
||||
prefs_do_room_notify(gboolean current_win, const char *const roomjid, const char *const nick, const char *const message,
|
||||
gboolean mention, gboolean trigger_found)
|
||||
{
|
||||
gboolean notify_current = prefs_get_boolean(PREF_NOTIFY_ROOM_CURRENT);
|
||||
gboolean notify_window = FALSE;
|
||||
@ -263,16 +263,8 @@ prefs_do_room_notify(gboolean current_win, const char *const roomjid, const char
|
||||
} else {
|
||||
notify_mention = prefs_get_boolean(PREF_NOTIFY_ROOM_MENTION);
|
||||
}
|
||||
if (notify_mention) {
|
||||
char *message_lower = g_utf8_strdown(message, -1);
|
||||
char *nick_lower = g_utf8_strdown(nick, -1);
|
||||
if (g_strrstr(message_lower, nick_lower)) {
|
||||
g_free(message_lower);
|
||||
g_free(nick_lower);
|
||||
return TRUE;
|
||||
}
|
||||
g_free(message_lower);
|
||||
g_free(nick_lower);
|
||||
if (notify_mention && mention) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean notify_trigger = FALSE;
|
||||
@ -281,7 +273,7 @@ prefs_do_room_notify(gboolean current_win, const char *const roomjid, const char
|
||||
} else {
|
||||
notify_trigger = prefs_get_boolean(PREF_NOTIFY_ROOM_TRIGGER);
|
||||
}
|
||||
if (notify_trigger && prefs_message_contains_trigger(message)) {
|
||||
if (notify_trigger && trigger_found) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -225,8 +225,9 @@ void prefs_free_string(char *pref);
|
||||
void prefs_set_string(preference_t pref, char *value);
|
||||
|
||||
gboolean prefs_do_chat_notify(gboolean current_win, const char *const message);
|
||||
gboolean prefs_do_room_notify(gboolean current_win, const char *const roomjid, const char *const nick, const char *const message);
|
||||
gboolean prefs_message_contains_trigger(const char *const message);
|
||||
gboolean prefs_do_room_notify(gboolean current_win, const char *const roomjid, const char *const nick,
|
||||
const char *const message, gboolean mention, gboolean trigger_found);
|
||||
GList* prefs_message_get_triggers(const char *const message);
|
||||
|
||||
void prefs_set_room_notify(const char *const roomjid, gboolean value);
|
||||
void prefs_set_room_notify_mention(const char *const roomjid, gboolean value);
|
||||
|
@ -230,8 +230,7 @@ sv_ev_room_history(const char *const room_jid, const char *const nick,
|
||||
}
|
||||
|
||||
void
|
||||
sv_ev_room_message(const char *const room_jid, const char *const nick,
|
||||
const char *const message)
|
||||
sv_ev_room_message(const char *const room_jid, const char *const nick, const char *const message)
|
||||
{
|
||||
if (prefs_get_boolean(PREF_GRLOG)) {
|
||||
Jid *jid = jid_create(jabber_get_fulljid());
|
||||
@ -244,13 +243,25 @@ sv_ev_room_message(const char *const room_jid, const char *const nick,
|
||||
return;
|
||||
}
|
||||
|
||||
mucwin_message(mucwin, nick, message);
|
||||
char *mynick = muc_nick(mucwin->roomjid);
|
||||
|
||||
gboolean mention = FALSE;
|
||||
char *message_lower = g_utf8_strdown(message, -1);
|
||||
char *mynick_lower = g_utf8_strdown(mynick, -1);
|
||||
if (g_strrstr(message_lower, mynick_lower)) {
|
||||
mention = TRUE;
|
||||
}
|
||||
g_free(message_lower);
|
||||
g_free(mynick_lower);
|
||||
|
||||
GList *triggers = prefs_message_get_triggers(message);
|
||||
|
||||
mucwin_message(mucwin, nick, message, mention, triggers != NULL);
|
||||
|
||||
ProfWin *window = (ProfWin*)mucwin;
|
||||
gboolean is_current = wins_is_current(window);
|
||||
int num = wins_get_num(window);
|
||||
char *my_nick = muc_nick(mucwin->roomjid);
|
||||
gboolean notify = prefs_do_room_notify(is_current, mucwin->roomjid, my_nick, message);
|
||||
gboolean notify = prefs_do_room_notify(is_current, mucwin->roomjid, mynick, message, mention, triggers != NULL);
|
||||
|
||||
// currently in groupchat window
|
||||
if (wins_is_current(window)) {
|
||||
@ -267,7 +278,7 @@ sv_ev_room_message(const char *const room_jid, const char *const nick,
|
||||
}
|
||||
prefs_free_string(muc_show);
|
||||
|
||||
if (prefs_get_boolean(PREF_FLASH) && (strcmp(nick, my_nick) != 0)) {
|
||||
if (prefs_get_boolean(PREF_FLASH) && (strcmp(nick, mynick) != 0)) {
|
||||
flash();
|
||||
}
|
||||
|
||||
@ -280,7 +291,7 @@ sv_ev_room_message(const char *const room_jid, const char *const nick,
|
||||
rosterwin_roster();
|
||||
|
||||
// don't notify self messages
|
||||
if (strcmp(nick, my_nick) == 0) {
|
||||
if (strcmp(nick, mynick) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -356,7 +356,8 @@ mucwin_history(ProfMucWin *mucwin, const char *const nick, GDateTime *timestamp,
|
||||
}
|
||||
|
||||
void
|
||||
mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const message)
|
||||
mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const message, gboolean mention,
|
||||
gboolean trigger_found)
|
||||
{
|
||||
assert(mucwin != NULL);
|
||||
|
||||
@ -364,9 +365,9 @@ mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const mes
|
||||
char *my_nick = muc_nick(mucwin->roomjid);
|
||||
|
||||
if (g_strcmp0(nick, my_nick) != 0) {
|
||||
if (g_strrstr(message, my_nick)) {
|
||||
if (mention) {
|
||||
win_print(window, '-', 0, NULL, NO_ME, THEME_ROOMMENTION, nick, message);
|
||||
} else if (prefs_message_contains_trigger(message)) {
|
||||
} else if (trigger_found) {
|
||||
win_print(window, '-', 0, NULL, NO_ME, THEME_ROOMTRIGGER, nick, message);
|
||||
} else {
|
||||
win_print(window, '-', 0, NULL, NO_ME, THEME_TEXT_THEM, nick, message);
|
||||
|
@ -158,7 +158,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);
|
||||
void mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const message, gboolean mention, gboolean trigger_found);
|
||||
void mucwin_subject(ProfMucWin *mucwin, const char *const nick, const char *const subject);
|
||||
void mucwin_requires_config(ProfMucWin *mucwin);
|
||||
void mucwin_info(ProfMucWin *mucwin);
|
||||
|
Loading…
Reference in New Issue
Block a user