diff options
author | Andreas Kling <kling@serenityos.org> | 2020-03-26 20:18:22 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-26 20:18:22 +0100 |
commit | 3c2981804861b86e1acf47dc089188bb5c75d9cd (patch) | |
tree | 10d3703ef506c3bf323a7c46acfd886f39dab3c4 /Applications/IRCClient | |
parent | 163812df976b0186b9a4ac75e3cd7dfe91438ba5 (diff) | |
download | serenity-3c2981804861b86e1acf47dc089188bb5c75d9cd.zip |
IRCClient: Only notify about channel messages containing our nickname
Diffstat (limited to 'Applications/IRCClient')
-rw-r--r-- | Applications/IRCClient/IRCWindow.cpp | 41 | ||||
-rw-r--r-- | Applications/IRCClient/IRCWindow.h | 2 |
2 files changed, 28 insertions, 15 deletions
diff --git a/Applications/IRCClient/IRCWindow.cpp b/Applications/IRCClient/IRCWindow.cpp index 4c9772bbcb..b17333204c 100644 --- a/Applications/IRCClient/IRCWindow.cpp +++ b/Applications/IRCClient/IRCWindow.cpp @@ -93,26 +93,37 @@ bool IRCWindow::is_active() const return m_client.current_window() == this; } -void IRCWindow::did_add_message(const String& name, const String& message) +void IRCWindow::post_notification_if_needed(const String& name, const String& message) { - if ((!is_active() || !window()->is_active()) && !name.is_null() && !message.is_null()) { - auto notification = GUI::Notification::construct(); - - if (type() == Type::Channel) { - StringBuilder builder; - builder.append(name); - builder.append(" in "); - builder.append(m_name); - notification->set_title(builder.to_string()); - } else { - notification->set_title(name); - } + if (name.is_null() || message.is_null()) + return; + if (is_active() && window()->is_active()) + return; + + auto notification = GUI::Notification::construct(); + + if (type() == Type::Channel) { + + if (!message.contains(m_client.nickname())) + return; + StringBuilder builder; + builder.append(name); + builder.append(" in "); + builder.append(m_name); + notification->set_title(builder.to_string()); + } else { notification->set_title(name); - notification->set_text(message); - notification->show(); } + notification->set_text(message); + notification->show(); +} + +void IRCWindow::did_add_message(const String& name, const String& message) +{ + post_notification_if_needed(name, message); + if (!is_active()) { ++m_unread_count; m_client.aid_update_window_list(); diff --git a/Applications/IRCClient/IRCWindow.h b/Applications/IRCClient/IRCWindow.h index e23108e525..ca8369b8bb 100644 --- a/Applications/IRCClient/IRCWindow.h +++ b/Applications/IRCClient/IRCWindow.h @@ -68,6 +68,8 @@ public: private: IRCWindow(IRCClient&, void* owner, Type, const String& name); + void post_notification_if_needed(const String& name, const String& message); + IRCClient& m_client; void* m_owner { nullptr }; Type m_type; |