mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 19:37:35 +00:00
IRCClient: Post desktop notifications when messaged while inactive
If you receive a channel or query message while the app is inactive, or while the channel/query is inactive, we now post a desktop notification so you can learn that something is happening. :^)
This commit is contained in:
parent
96c7e2cd6d
commit
163812df97
4 changed files with 25 additions and 4 deletions
|
@ -69,7 +69,7 @@ void IRCChannel::remove_member(const String& name)
|
||||||
void IRCChannel::add_message(char prefix, const String& name, const String& text, Color color)
|
void IRCChannel::add_message(char prefix, const String& name, const String& text, Color color)
|
||||||
{
|
{
|
||||||
log().add_message(prefix, name, text, color);
|
log().add_message(prefix, name, text, color);
|
||||||
window().did_add_message();
|
window().did_add_message(name, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRCChannel::add_message(const String& text, Color color)
|
void IRCChannel::add_message(const String& text, Color color)
|
||||||
|
|
|
@ -56,7 +56,7 @@ void IRCQuery::dump() const
|
||||||
void IRCQuery::add_message(char prefix, const String& name, const String& text, Color color)
|
void IRCQuery::add_message(char prefix, const String& name, const String& text, Color color)
|
||||||
{
|
{
|
||||||
log().add_message(prefix, name, text, color);
|
log().add_message(prefix, name, text, color);
|
||||||
window().did_add_message();
|
window().did_add_message(name, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRCQuery::say(const String& text)
|
void IRCQuery::say(const String& text)
|
||||||
|
|
|
@ -28,11 +28,14 @@
|
||||||
#include "IRCChannel.h"
|
#include "IRCChannel.h"
|
||||||
#include "IRCChannelMemberListModel.h"
|
#include "IRCChannelMemberListModel.h"
|
||||||
#include "IRCClient.h"
|
#include "IRCClient.h"
|
||||||
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibGUI/BoxLayout.h>
|
#include <LibGUI/BoxLayout.h>
|
||||||
|
#include <LibGUI/Notification.h>
|
||||||
#include <LibGUI/Splitter.h>
|
#include <LibGUI/Splitter.h>
|
||||||
#include <LibGUI/TableView.h>
|
#include <LibGUI/TableView.h>
|
||||||
#include <LibGUI/TextBox.h>
|
#include <LibGUI/TextBox.h>
|
||||||
#include <LibGUI/TextEditor.h>
|
#include <LibGUI/TextEditor.h>
|
||||||
|
#include <LibGUI/Window.h>
|
||||||
#include <LibWeb/HtmlView.h>
|
#include <LibWeb/HtmlView.h>
|
||||||
|
|
||||||
IRCWindow::IRCWindow(IRCClient& client, void* owner, Type type, const String& name)
|
IRCWindow::IRCWindow(IRCClient& client, void* owner, Type type, const String& name)
|
||||||
|
@ -90,8 +93,26 @@ bool IRCWindow::is_active() const
|
||||||
return m_client.current_window() == this;
|
return m_client.current_window() == this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRCWindow::did_add_message()
|
void IRCWindow::did_add_message(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);
|
||||||
|
}
|
||||||
|
|
||||||
|
notification->set_title(name);
|
||||||
|
notification->set_text(message);
|
||||||
|
notification->show();
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_active()) {
|
if (!is_active()) {
|
||||||
++m_unread_count;
|
++m_unread_count;
|
||||||
m_client.aid_update_window_list();
|
m_client.aid_update_window_list();
|
||||||
|
|
|
@ -57,7 +57,7 @@ public:
|
||||||
int unread_count() const;
|
int unread_count() const;
|
||||||
void clear_unread_count();
|
void clear_unread_count();
|
||||||
|
|
||||||
void did_add_message();
|
void did_add_message(const String& name = {}, const String& message = {});
|
||||||
|
|
||||||
IRCChannel& channel() { return *(IRCChannel*)m_owner; }
|
IRCChannel& channel() { return *(IRCChannel*)m_owner; }
|
||||||
const IRCChannel& channel() const { return *(const IRCChannel*)m_owner; }
|
const IRCChannel& channel() const { return *(const IRCChannel*)m_owner; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue