Skip to content

Commit

Permalink
fix: no longer double count some alerts in tab notification count
Browse files Browse the repository at this point in the history
  • Loading branch information
JFreegman committed Jan 23, 2025
1 parent 9cc7aba commit 8dc35e7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
19 changes: 11 additions & 8 deletions src/chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -900,17 +900,17 @@ static void chat_onGroupInvite(ToxWindow *self, Toxic *toxic, uint32_t friendnum
memcpy(Friends.list[friendnumber].group_invite.data, invite_data, length);
Friends.list[friendnumber].group_invite.length = length;

sound_notify(self, toxic, generic_message, NT_WNDALERT_2 | c_config->bell_on_invite, NULL);

char name[TOXIC_MAX_NAME_LENGTH + 1];
get_friend_name(name, sizeof(name), friendnumber);

const uint64_t flags = NT_WNDALERT_2 | c_config->bell_on_invite;

if (self->active_box != -1) {
box_silent_notify2(self, toxic, NT_WNDALERT_2 | NT_NOFOCUS, self->active_box,
"invites you to join group chat");
box_notify2(self, toxic, generic_message, flags, self->active_box,
"You have been invited to a group chat.");
} else {
box_silent_notify(self, toxic, NT_WNDALERT_2 | NT_NOFOCUS, &self->active_box, name,
"invites you to join group chat");
box_notify(self, toxic, generic_message, flags, &self->active_box, name,
"You have been invited to a group chat.");
}

line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "%s has invited you to join group chat \"%s\"",
Expand Down Expand Up @@ -1022,14 +1022,17 @@ static void chat_onInvite(ToxWindow *self, Toxic *toxic, uint32_t friend_number,
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0,
"Incoming audio call! Type: \"/answer\" or \"/reject\"");

uint64_t box_flags = NT_NOFOCUS | NT_WNDALERT_0;

if (self->ringing_sound == -1) {
sound_notify(self, toxic, call_incoming, NT_LOOP | c_config->bell_on_invite, &self->ringing_sound);
box_flags |= NT_NO_INCREMENT;
}

if (self->active_box != -1) {
box_silent_notify2(self, toxic, NT_NOFOCUS | NT_WNDALERT_0, self->active_box, "Incoming audio call!");
box_silent_notify2(self, toxic, box_flags, self->active_box, "Incoming audio call!");
} else {
box_silent_notify(self, toxic, NT_NOFOCUS | NT_WNDALERT_0, &self->active_box, self->name, "Incoming audio call!");
box_silent_notify(self, toxic, box_flags, &self->active_box, self->name, "Incoming audio call!");
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/groupchats.c
Original file line number Diff line number Diff line change
Expand Up @@ -1003,12 +1003,12 @@ static void groupchat_onGroupMessage(ToxWindow *self, Toxic *toxic, uint32_t gro

/* Only play sound if mentioned by someone else */
if (strcasestr(msg, self_nick) && strcmp(self_nick, nick)) {
sound_notify(self, toxic, generic_message, NT_WNDALERT_0 | c_config->bell_on_message, NULL);

if (self->active_box != -1) {
box_silent_notify2(self, toxic, NT_NOFOCUS, self->active_box, "%s %s", nick, msg);
box_notify2(self, toxic, generic_message, NT_WNDALERT_0 | NT_NOFOCUS |
c_config->bell_on_message, self->active_box, "%s: %s", nick, msg);
} else {
box_silent_notify(self, toxic, NT_NOFOCUS, &self->active_box, self->name, "%s %s", nick, msg);
box_notify(self, toxic, generic_message, NT_WNDALERT_0 | NT_NOFOCUS |
c_config->bell_on_message, &self->active_box, self->name, "%s: %s", nick, msg);
}

nick_clr = RED;
Expand Down
4 changes: 3 additions & 1 deletion src/notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ static void tab_notify(ToxWindow *self, uint64_t flags)
self->alert = WINDOW_ALERT_2;
}

++self->pending_messages;
if (!(flags & NT_NO_INCREMENT)) {
++self->pending_messages;
}
}

static bool notifications_are_disabled(const Toxic *toxic, uint64_t flags)
Expand Down
2 changes: 2 additions & 0 deletions src/notify.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ typedef enum _Flags {
NT_WNDALERT_2 = 1 << 7, /* Alert toxic */

NT_ALWAYS = 1 << 8, /* Force sound to play */

NT_NO_INCREMENT = 1 << 9, /* Prevents notification from incrementing pending message counter in window's tab */
} Flags;

int init_notify(int login_cooldown, int notification_timeout);
Expand Down

0 comments on commit 8dc35e7

Please sign in to comment.