Better protocol status notifications

Now a notification is sent as soon as a protocol has been readied
(before connection established), and all status notifications use the
same message ID to avoid spamming the poor user.
This commit is contained in:
Jaidyn Ann 2021-08-18 17:22:08 -05:00
parent b2e17f57dc
commit 6e89dbdab1
2 changed files with 24 additions and 14 deletions

View File

@ -143,7 +143,7 @@ Server::Filter(BMessage* message, BHandler **target)
BString content(B_TRANSLATE("%user% has been disabled!")); BString content(B_TRANSLATE("%user% has been disabled!"));
content.ReplaceAll("%user%", name); content.ReplaceAll("%user%", name);
_SendNotification(B_TRANSLATE("Disabled"), content, icon); _SendNotification(B_TRANSLATE("Disabled"), content, name, icon);
} }
break; break;
} }
@ -156,7 +156,8 @@ Server::Filter(BMessage* message, BHandler **target)
BString content(B_TRANSLATE("%user% has been temporarily disabled.")); BString content(B_TRANSLATE("%user% has been temporarily disabled."));
content.ReplaceAll("%user%", name); content.ReplaceAll("%user%", name);
_SendNotification(B_TRANSLATE("Connection failed"), content, icon); _SendNotification(B_TRANSLATE("Connection failed"), content,
name, icon);
} }
break; break;
} }
@ -297,10 +298,12 @@ Server::ImMessage(BMessage* msg)
|| (oldStatus == STATUS_OFFLINE && status == STATUS_ONLINE)) || (oldStatus == STATUS_OFFLINE && status == STATUS_ONLINE))
{ {
if (status == STATUS_ONLINE) if (status == STATUS_ONLINE)
if (AppPreferences::Get()->NotifyProtocolStatus == true)
_ProtocolNotification(looper, _ProtocolNotification(looper,
BString(B_TRANSLATE("Connected")), BString(B_TRANSLATE("Connected")),
BString(B_TRANSLATE("%user% has connected!"))); BString(B_TRANSLATE("%user% has connected!")));
else else
if (AppPreferences::Get()->NotifyProtocolStatus == true)
_ProtocolNotification(looper, _ProtocolNotification(looper,
BString(B_TRANSLATE("Disconnected")), BString(B_TRANSLATE("Disconnected")),
BString(B_TRANSLATE("%user% is now offline!"))); BString(B_TRANSLATE("%user% is now offline!")));
@ -701,6 +704,10 @@ Server::AddProtocolLooper(bigtime_t instanceId, ChatProtocol* cayap)
fAccounts.AddItem(cayap->GetName(), instanceId); fAccounts.AddItem(cayap->GetName(), instanceId);
fAccountEnabled.AddItem(cayap->GetName(), false); fAccountEnabled.AddItem(cayap->GetName(), false);
if (AppPreferences::Get()->NotifyProtocolStatus == true)
_ProtocolNotification(looper, BString(B_TRANSLATE("Connecting")),
BString(B_TRANSLATE("%user% is readying…")));
if (fStarted == true) if (fStarted == true)
Login(looper); Login(looper);
} }
@ -1035,21 +1042,24 @@ Server::_ProtocolNotification(ProtocolLooper* looper, BString title,
BString desc, notification_type type) BString desc, notification_type type)
{ {
if (looper == NULL || title.IsEmpty() == true) return; if (looper == NULL || title.IsEmpty() == true) return;
title.ReplaceAll("%user%", looper->Protocol()->GetName()); BString account = looper->Protocol()->GetName();
desc.ReplaceAll("%user%", looper->Protocol()->GetName()); title.ReplaceAll("%user%", account);
_SendNotification(title, desc, looper->Protocol()->Icon(), type); desc.ReplaceAll("%user%", account);
_SendNotification(title, desc, account, looper->Protocol()->Icon(), type);
} }
void void
Server::_SendNotification(BString title, BString content, BBitmap* icon, Server::_SendNotification(BString title, BString content, BString id,
notification_type type) BBitmap* icon, notification_type type)
{ {
BNotification notification(type); BNotification notification(type);
notification.SetGroup(BString(APP_NAME)); notification.SetGroup(BString(APP_NAME));
notification.SetTitle(title); notification.SetTitle(title);
if (content.IsEmpty() == false) if (content.IsEmpty() == false)
notification.SetContent(content); notification.SetContent(content);
if (id.IsEmpty() == false)
notification.SetMessageID(id);
if (icon != NULL) if (icon != NULL)
notification.SetIcon(icon); notification.SetIcon(icon);
notification.Send(); notification.Send();

View File

@ -83,7 +83,7 @@ private:
BString title, BString desc, BString title, BString desc,
notification_type type=B_INFORMATION_NOTIFICATION); notification_type type=B_INFORMATION_NOTIFICATION);
void _SendNotification(BString title, BString content, void _SendNotification(BString title, BString content,
BBitmap* icon=NULL, BString id, BBitmap* icon=NULL,
notification_type type=B_INFORMATION_NOTIFICATION); notification_type type=B_INFORMATION_NOTIFICATION);
void _ReplicantStatusNotify(UserStatus status); void _ReplicantStatusNotify(UserStatus status);