* Handle IM_NOTIFICATION.

* Shows notifications when contacts go online or offline. Unfortunately XMPP plugins will send presence notifications when the roster is populate so presence notification is shown for every online contact when the roster list view is populated the first time.
This commit is contained in:
plfiorini 2010-05-30 18:56:24 +00:00
parent d503077fac
commit 5ddeef6e7b
3 changed files with 64 additions and 3 deletions

View File

@ -13,11 +13,11 @@ enum message_what_codes {
//! All client <> protocol communication uses this what-code //! All client <> protocol communication uses this what-code
IM_MESSAGE = 'IMme', IM_MESSAGE = 'IMme',
//! Used for all error messages //! Used for very important (blocking) error messages
IM_ERROR = 'IMer', IM_ERROR = 'IMer',
//! Returned after a request has succeded //! Returned after a request has succeded
IM_ACTION_PERFORMED = 'IMok' IM_ACTION_PERFORMED = 'IMap'
}; };
/** /**
@ -158,6 +158,9 @@ enum im_what_code {
//! Progress message received, could be login sequence, file transfer etc... //! Progress message received, could be login sequence, file transfer etc...
IM_PROGRESS = 140, IM_PROGRESS = 140,
//! Notifications
IM_NOTIFICATION = 141,
/* /*
* Special messages * Special messages
*/ */

View File

@ -21,7 +21,9 @@
#include <GroupLayout.h> #include <GroupLayout.h>
#include <GroupLayoutBuilder.h> #include <GroupLayoutBuilder.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <Notification.h>
#include <PopUpMenu.h> #include <PopUpMenu.h>
#include <Roster.h>
#include <SpaceLayoutItem.h> #include <SpaceLayoutItem.h>
#include <ScrollView.h> #include <ScrollView.h>
#include <StringView.h> #include <StringView.h>
@ -221,22 +223,51 @@ MainWindow::ImMessage(BMessage* msg)
RosterItem* rosterItem = fServer->RosterItemForId(msg->FindString("id")); RosterItem* rosterItem = fServer->RosterItemForId(msg->FindString("id"));
if (rosterItem) { if (rosterItem) {
// Add or remove item
UpdateListItem(rosterItem); UpdateListItem(rosterItem);
// Add or remove item
switch (status) { switch (status) {
case CAYA_OFFLINE: case CAYA_OFFLINE:
// By default offline contacts are hidden
if (HasItem(rosterItem)) if (HasItem(rosterItem))
RemoveItem(rosterItem); RemoveItem(rosterItem);
return; return;
default: default:
// Add item because it has a non-offline status
if (!HasItem(rosterItem)) if (!HasItem(rosterItem))
AddItem(rosterItem); AddItem(rosterItem);
break; break;
} }
UpdateListItem(rosterItem); UpdateListItem(rosterItem);
// Sort list view again // Sort list view again
fListView->Sort(); fListView->Sort();
switch (status) {
case CAYA_ONLINE:
case CAYA_OFFLINE:
// Notify when contact is online or offline
if (status == CAYA_ONLINE) {
BString message;
message << rosterItem->GetContactLinker()->GetName();
if (status == CAYA_ONLINE)
message << " is available!";
else
message << " is offline!";
BNotification notification(B_INFORMATION_NOTIFICATION);
notification.SetApplication("Caya");
notification.SetTitle("Presence");
notification.SetIcon(rosterItem->Bitmap());
notification.SetContent(message.String());
be_roster->Notify(notification);
}
break;
default:
break;
}
} }
break; break;
} }

View File

@ -324,6 +324,33 @@ Server::ImMessage(BMessage* msg)
be_roster->Notify(notification); be_roster->Notify(notification);
break; break;
} }
case IM_NOTIFICATION:
{
int32 type = (int32)B_INFORMATION_NOTIFICATION;
const char* protocol = NULL;
const char* title = NULL;
const char* message = NULL;
if (msg->FindString("protocol", &protocol) != B_OK)
return result;
if (msg->FindInt32("type", &type) != B_OK)
return result;
if (msg->FindString("title", &title) != B_OK)
return result;
if (msg->FindString("message", &message) != B_OK)
return result;
CayaProtocolAddOn* addOn
= ProtocolManager::Get()->ProtocolAddOn(protocol);
BNotification notification((notification_type)type);
notification.SetApplication("Caya");
notification.SetTitle(title);
notification.SetIcon(addOn->Icon());
notification.SetContent(message);
be_roster->Notify(notification);
break;
}
default: default:
break; break;
} }