Move notifications from ConversationView to Conversation itself
This commit is contained in:
parent
c6f907101a
commit
fe4d0661a7
|
@ -7,9 +7,12 @@
|
||||||
|
|
||||||
#include <DateTimeFormat.h>
|
#include <DateTimeFormat.h>
|
||||||
#include <Locale.h>
|
#include <Locale.h>
|
||||||
|
#include <Notification.h>
|
||||||
|
#include <StringFormat.h>
|
||||||
#include <StringList.h>
|
#include <StringList.h>
|
||||||
|
|
||||||
#include "AppPreferences.h"
|
#include "AppPreferences.h"
|
||||||
|
#include "Cardie.h"
|
||||||
#include "ChatProtocolMessages.h"
|
#include "ChatProtocolMessages.h"
|
||||||
#include "RenderView.h"
|
#include "RenderView.h"
|
||||||
#include "ChatCommand.h"
|
#include "ChatCommand.h"
|
||||||
|
@ -35,7 +38,8 @@ Conversation::Conversation(BString id, BMessenger msgn)
|
||||||
fIcon(NULL),
|
fIcon(NULL),
|
||||||
fDateFormatter(),
|
fDateFormatter(),
|
||||||
fRoomFlags(0),
|
fRoomFlags(0),
|
||||||
fDisallowedFlags(0)
|
fDisallowedFlags(0),
|
||||||
|
fNotifyCount(0)
|
||||||
{
|
{
|
||||||
fConversationItem = new ConversationItem(fName.String(), this);
|
fConversationItem = new ConversationItem(fName.String(), this);
|
||||||
RegisterObserver(fConversationItem);
|
RegisterObserver(fConversationItem);
|
||||||
|
@ -74,6 +78,47 @@ Conversation::ImMessage(BMessage* msg)
|
||||||
_EnsureUser(msg);
|
_EnsureUser(msg);
|
||||||
_LogChatMessage(msg);
|
_LogChatMessage(msg);
|
||||||
GetView()->MessageReceived(msg);
|
GetView()->MessageReceived(msg);
|
||||||
|
|
||||||
|
BString text = msg->FindString("body");
|
||||||
|
Contact* contact = GetOwnContact();
|
||||||
|
bool mentioned = ((text.IFindFirst(contact->GetName()) != B_ERROR)
|
||||||
|
|| (text.IFindFirst(contact->GetName()) != B_ERROR));
|
||||||
|
|
||||||
|
// Send a notification, if it's appropriate
|
||||||
|
BWindow* win = fChatView->Window();
|
||||||
|
if ((win == NULL || !win->IsFront() || win->IsMinimized())
|
||||||
|
&& AppPreferences::Item()->NotifyNewMessage
|
||||||
|
&& (fUsers.CountItems() <= 2 || mentioned))
|
||||||
|
{
|
||||||
|
fNotifyCount++;
|
||||||
|
|
||||||
|
BString notifyTitle = "New mention";
|
||||||
|
BString notifyText = "You've been summoned from %source%.";
|
||||||
|
|
||||||
|
if (mentioned == false) {
|
||||||
|
notifyTitle.SetTo("New message");
|
||||||
|
notifyText.SetTo("");
|
||||||
|
|
||||||
|
BStringFormat pmFormat("{0, plural,"
|
||||||
|
"=1{You've got a new message from %source%.}"
|
||||||
|
"other{You've got # new messages from %source%.}}");
|
||||||
|
pmFormat.Format(notifyText, fNotifyCount);
|
||||||
|
}
|
||||||
|
notifyText.ReplaceAll("%source%", GetName());
|
||||||
|
|
||||||
|
BBitmap* icon = IconBitmap();
|
||||||
|
if (icon == NULL)
|
||||||
|
icon = ProtocolBitmap();
|
||||||
|
|
||||||
|
|
||||||
|
BNotification notification(B_INFORMATION_NOTIFICATION);
|
||||||
|
notification.SetGroup(BString(APP_NAME));
|
||||||
|
notification.SetTitle(notifyTitle);
|
||||||
|
notification.SetIcon(icon);
|
||||||
|
notification.SetContent(notifyText);
|
||||||
|
notification.SetMessageID(fID);
|
||||||
|
notification.Send();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IM_MESSAGE_SENT:
|
case IM_MESSAGE_SENT:
|
||||||
|
|
|
@ -90,6 +90,7 @@ private:
|
||||||
ProtocolLooper* fLooper;
|
ProtocolLooper* fLooper;
|
||||||
ConversationView* fChatView;
|
ConversationView* fChatView;
|
||||||
ConversationItem* fConversationItem;
|
ConversationItem* fConversationItem;
|
||||||
|
int32 fNotifyCount;
|
||||||
|
|
||||||
BString fID;
|
BString fID;
|
||||||
BString fName;
|
BString fName;
|
||||||
|
|
|
@ -12,9 +12,7 @@
|
||||||
|
|
||||||
#include <LayoutBuilder.h>
|
#include <LayoutBuilder.h>
|
||||||
#include <ListView.h>
|
#include <ListView.h>
|
||||||
#include <Notification.h>
|
|
||||||
#include <ScrollView.h>
|
#include <ScrollView.h>
|
||||||
#include <StringFormat.h>
|
|
||||||
#include <StringList.h>
|
#include <StringList.h>
|
||||||
#include <StringView.h>
|
#include <StringView.h>
|
||||||
|
|
||||||
|
@ -22,11 +20,10 @@
|
||||||
|
|
||||||
#include "AppMessages.h"
|
#include "AppMessages.h"
|
||||||
#include "AppPreferences.h"
|
#include "AppPreferences.h"
|
||||||
#include "Cardie.h"
|
|
||||||
#include "ChatProtocolMessages.h"
|
#include "ChatProtocolMessages.h"
|
||||||
#include "RenderView.h"
|
|
||||||
#include "Conversation.h"
|
#include "Conversation.h"
|
||||||
#include "NotifyMessage.h"
|
#include "NotifyMessage.h"
|
||||||
|
#include "RenderView.h"
|
||||||
#include "SendTextView.h"
|
#include "SendTextView.h"
|
||||||
#include "User.h"
|
#include "User.h"
|
||||||
#include "UserItem.h"
|
#include "UserItem.h"
|
||||||
|
@ -40,7 +37,6 @@ ConversationView::ConversationView()
|
||||||
fMessageQueue(),
|
fMessageQueue(),
|
||||||
fConversation(NULL)
|
fConversation(NULL)
|
||||||
{
|
{
|
||||||
fMessageCount = 0;
|
|
||||||
_InitInterface();
|
_InitInterface();
|
||||||
fSendView->MakeFocus(true);
|
fSendView->MakeFocus(true);
|
||||||
}
|
}
|
||||||
|
@ -132,47 +128,6 @@ ConversationView::ImMessage(BMessage* msg)
|
||||||
}
|
}
|
||||||
case IM_MESSAGE_RECEIVED:
|
case IM_MESSAGE_RECEIVED:
|
||||||
{
|
{
|
||||||
BString text = msg->FindString("body");
|
|
||||||
Contact* contact = fConversation->GetOwnContact();
|
|
||||||
bool mentioned = ((text.IFindFirst(contact->GetName()) != B_ERROR)
|
|
||||||
|| (text.IFindFirst(contact->GetName()) != B_ERROR));
|
|
||||||
|
|
||||||
// Send a notification, if it's appropriate
|
|
||||||
BWindow* win = Window();
|
|
||||||
if ((win == NULL || !win->IsFront() || win->IsMinimized())
|
|
||||||
&& AppPreferences::Item()->NotifyNewMessage
|
|
||||||
&& (fConversation->Users().CountItems() <= 2 || mentioned))
|
|
||||||
{
|
|
||||||
fMessageCount++;
|
|
||||||
|
|
||||||
BString notifyTitle = "New mention";
|
|
||||||
BString notifyText = "You've been summoned from %source%.";
|
|
||||||
|
|
||||||
if (mentioned == false) {
|
|
||||||
notifyTitle.SetTo("New message");
|
|
||||||
notifyText.SetTo("");
|
|
||||||
|
|
||||||
BStringFormat pmFormat("{0, plural,"
|
|
||||||
"=1{You've got a new message from %source%.}"
|
|
||||||
"other{You've got # new messages from %source%.}}");
|
|
||||||
pmFormat.Format(notifyText, fMessageCount);
|
|
||||||
}
|
|
||||||
notifyText.ReplaceAll("%source%", fConversation->GetName());
|
|
||||||
|
|
||||||
BBitmap* icon = fConversation->IconBitmap();
|
|
||||||
if (icon == NULL)
|
|
||||||
icon = fConversation->ProtocolBitmap();
|
|
||||||
|
|
||||||
|
|
||||||
BNotification notification(B_INFORMATION_NOTIFICATION);
|
|
||||||
notification.SetGroup(BString(APP_NAME));
|
|
||||||
notification.SetTitle(notifyTitle);
|
|
||||||
notification.SetIcon(icon);
|
|
||||||
notification.SetContent(notifyText);
|
|
||||||
notification.SetMessageID(fConversation->GetId());
|
|
||||||
notification.Send();
|
|
||||||
}
|
|
||||||
|
|
||||||
_AppendOrEnqueueMessage(msg);
|
_AppendOrEnqueueMessage(msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,6 @@ private:
|
||||||
BMessage* msg);
|
BMessage* msg);
|
||||||
|
|
||||||
Conversation* fConversation;
|
Conversation* fConversation;
|
||||||
int32 fMessageCount;
|
|
||||||
BObjectList<BMessage> fMessageQueue;
|
BObjectList<BMessage> fMessageQueue;
|
||||||
|
|
||||||
BTextView* fNameTextView;
|
BTextView* fNameTextView;
|
||||||
|
|
Ŝarĝante…
Reference in New Issue