1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-07-21 18:24:14 -04:00

Only show reminder notifications when notifications are enabled

This commit is contained in:
James Booth 2015-11-25 22:08:33 +00:00
parent 20e63e364b
commit d3389db233
10 changed files with 73 additions and 18 deletions

View File

@ -239,6 +239,9 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha
char *display_name = roster_get_msg_display_name(chatwin->barejid, resource);
gboolean is_current = wins_is_current(window);
gboolean notify = prefs_get_notify_chat(is_current, message);
// currently viewing chat window with sender
if (wins_is_current(window)) {
win_print_incoming_message(window, timestamp, display_name, message, enc_mode);
@ -255,6 +258,9 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha
}
chatwin->unread++;
if (notify) {
chatwin->notify = TRUE;
}
if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) {
_chatwin_history(chatwin, chatwin->barejid);
}
@ -274,8 +280,6 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha
beep();
}
gboolean is_current = wins_is_current(window);
gboolean notify = prefs_get_notify_chat(is_current, message);
if (!notify) {
free(display_name);
return;

View File

@ -374,6 +374,9 @@ mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const mes
win_print(window, '-', 0, NULL, 0, THEME_TEXT_ME, nick, message);
}
gboolean is_current = wins_is_current(window);
gboolean notify = prefs_get_notify_room(is_current, my_nick, message);
// currently in groupchat window
if (wins_is_current(window)) {
status_bar_active(num);
@ -388,6 +391,9 @@ mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const mes
}
mucwin->unread++;
if (notify) {
mucwin->notify = TRUE;
}
}
// don't notify self messages
@ -399,8 +405,6 @@ mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const mes
beep();
}
gboolean is_current = wins_is_current(window);
gboolean notify = prefs_get_notify_room(is_current, my_nick, message);
if (!notify) {
return;
}

View File

@ -140,13 +140,14 @@ notify_remind(void)
gdouble elapsed = g_timer_elapsed(remind_timer, NULL);
gint remind_period = prefs_get_notify_remind();
if (remind_period > 0 && elapsed >= remind_period) {
gboolean notify = wins_get_notify();
gint unread = wins_get_total_unread();
gint open = muc_invites_count();
gint subs = presence_sub_request_count();
GString *text = g_string_new("");
if (unread > 0) {
if (notify && unread > 0) {
if (unread == 1) {
g_string_append(text, "1 unread message");
} else {
@ -175,7 +176,7 @@ notify_remind(void)
}
}
if ((unread > 0) || (open > 0) || (subs > 0)) {
if ((notify && unread > 0) || (open > 0) || (subs > 0)) {
_notify(text->str, 5000, "Incoming message");
}

View File

@ -53,6 +53,9 @@ privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDat
char *display_from = get_nick_from_full_jid(privatewin->fulljid);
gboolean is_current = wins_is_current(window);
gboolean notify = prefs_get_notify_chat(is_current, message);
// currently viewing chat window with sender
if (wins_is_current(window)) {
win_print_incoming_message(window, timestamp, display_from, message, PROF_MSG_PLAIN);
@ -62,6 +65,9 @@ privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDat
// not currently viewing chat window with sender
} else {
privatewin->unread++;
if (notify) {
privatewin->notify = TRUE;
}
status_bar_new(num);
cons_show_incoming_message(display_from, num);
win_print_incoming_message(window, timestamp, display_from, message, PROF_MSG_PLAIN);
@ -75,18 +81,6 @@ privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDat
beep();
}
if (!prefs_get_boolean(PREF_NOTIFY_MESSAGE)) {
free(display_from);
return;
}
gboolean notify = FALSE;
gboolean is_current = wins_is_current(window);
if (!is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) {
notify = TRUE;
}
if (!notify) {
free(display_from);
return;

View File

@ -319,6 +319,7 @@ ProfWin* win_create_muc_config(const char *const title, DataForm *form);
ProfWin* win_create_private(const char *const fulljid);
void win_update_virtual(ProfWin *window);
void win_free(ProfWin *window);
gboolean win_notify(ProfWin *window);
int win_unread(ProfWin *window);
void win_resize(ProfWin *window);
void win_hide_subwin(ProfWin *window);

View File

@ -102,6 +102,7 @@ typedef struct prof_chat_win_t {
ProfWin window;
char *barejid;
int unread;
gboolean notify;
ChatState *state;
gboolean is_otr;
gboolean otr_is_trusted;
@ -116,6 +117,7 @@ typedef struct prof_muc_win_t {
ProfWin window;
char *roomjid;
int unread;
gboolean notify;
gboolean showjid;
unsigned long memcheck;
} ProfMucWin;
@ -131,6 +133,7 @@ typedef struct prof_private_win_t {
ProfWin window;
char *fulljid;
int unread;
gboolean notify;
unsigned long memcheck;
} ProfPrivateWin;

View File

@ -141,6 +141,7 @@ win_create_chat(const char *const barejid)
new_win->pgp_send = FALSE;
new_win->history_shown = FALSE;
new_win->unread = 0;
new_win->notify = FALSE;
new_win->state = chat_state_new();
new_win->memcheck = PROFCHATWIN_MEMCHECK;
@ -180,6 +181,7 @@ win_create_muc(const char *const roomjid)
new_win->roomjid = strdup(roomjid);
new_win->unread = 0;
new_win->notify = FALSE;
if (prefs_get_boolean(PREF_OCCUPANTS_JID)) {
new_win->showjid = TRUE;
} else {
@ -215,6 +217,7 @@ win_create_private(const char *const fulljid)
new_win->fulljid = strdup(fulljid);
new_win->unread = 0;
new_win->notify = FALSE;
new_win->memcheck = PROFPRIVATEWIN_MEMCHECK;
@ -1245,6 +1248,26 @@ win_has_active_subwin(ProfWin *window)
}
}
gboolean
win_notify(ProfWin *window)
{
if (window->type == WIN_CHAT) {
ProfChatWin *chatwin = (ProfChatWin*) window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
return chatwin->notify;
} else if (window->type == WIN_MUC) {
ProfMucWin *mucwin = (ProfMucWin*) window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
return mucwin->notify;
} else if (window->type == WIN_PRIVATE) {
ProfPrivateWin *privatewin = (ProfPrivateWin*) window;
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
return privatewin->notify;
} else {
return FALSE;
}
}
int
win_unread(ProfWin *window)
{

View File

@ -189,13 +189,16 @@ wins_set_current_by_num(int i)
ProfChatWin *chatwin = (ProfChatWin*) window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
chatwin->unread = 0;
chatwin->notify = FALSE;
} else if (window->type == WIN_MUC) {
ProfMucWin *mucwin = (ProfMucWin*) window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
mucwin->unread = 0;
mucwin->notify = FALSE;
} else if (window->type == WIN_PRIVATE) {
ProfPrivateWin *privatewin = (ProfPrivateWin*) window;
privatewin->unread = 0;
privatewin->notify = FALSE;
}
}
}
@ -382,6 +385,23 @@ wins_new_private(const char *const fulljid)
return newwin;
}
gboolean
wins_get_notify(void)
{
GList *values = g_hash_table_get_values(windows);
GList *curr = values;
while (curr) {
ProfWin *window = curr->data;
if (win_notify(window)) {
g_list_free(values);
return TRUE;
}
curr = g_list_next(curr);
}
return FALSE;
}
int
wins_get_total_unread(void)
{

View File

@ -67,6 +67,7 @@ int wins_get_current_num(void);
void wins_close_current(void);
void wins_close_by_num(int i);
gboolean wins_is_current(ProfWin *window);
gboolean wins_get_notify(void);
int wins_get_total_unread(void);
void wins_resize_all(void);
GSList* wins_get_chat_recipients(void);

View File

@ -486,6 +486,10 @@ ProfWin* win_create_private(const char * const fulljid)
void win_update_virtual(ProfWin *window) {}
void win_free(ProfWin *window) {}
gboolean win_notify(ProfWin *window)
{
return TRUE;
}
int win_unread(ProfWin *window)
{
return 0;