Use _SendMessage() to send messages from protocol to Caya because it will always add the "protocol" field.

This commit is contained in:
plfiorini 2010-05-30 12:30:47 +00:00
parent 7757c0b64c
commit 5cf1ffadfb
2 changed files with 39 additions and 34 deletions

View File

@ -206,17 +206,40 @@ JabberHandler::MessengerInterface() const
} }
void
JabberHandler::_SendMessage(BMessage* msg)
{
// Skip invalid messages
if (!msg)
return;
msg->AddString("protocol", kProtocolSignature);
fServerMessenger->SendMessage(msg);
}
void
JabberHandler::_Progress(const char* title, const char* message, float progress)
{
BMessage msg(IM_MESSAGE);
msg.AddInt32("im_what", IM_PROGRESS);
msg.AddString("title", title);
msg.AddString("message", message);
msg.AddFloat("progress", progress);
_SendMessage(&msg);
}
void void
JabberHandler::_MessageSent(const char* id, const char* subject, JabberHandler::_MessageSent(const char* id, const char* subject,
const char* body) const char* body)
{ {
BMessage msg(IM_MESSAGE); BMessage msg(IM_MESSAGE);
msg.AddInt32("im_what", IM_MESSAGE_SENT); msg.AddInt32("im_what", IM_MESSAGE_SENT);
msg.AddString("protocol", kProtocolSignature);
msg.AddString("id", id); msg.AddString("id", id);
msg.AddString("subject", subject); msg.AddString("subject", subject);
msg.AddString("body", body); msg.AddString("body", body);
fServerMessenger->SendMessage(&msg); _SendMessage(&msg);
} }
@ -350,22 +373,8 @@ JabberHandler::_AvatarChanged(const char* id, const char* filename)
msg.AddInt32("im_what", IM_AVATAR_SET); msg.AddInt32("im_what", IM_AVATAR_SET);
msg.AddString("id", id); msg.AddString("id", id);
} }
msg.AddString("protocol", kProtocolSignature);
msg.AddRef("ref", &ref); msg.AddRef("ref", &ref);
fServerMessenger->SendMessage(&msg); _SendMessage(&msg);
}
void
JabberHandler::_Progress(const char* title, const char* message, float progress)
{
BMessage msg(IM_MESSAGE);
msg.AddInt32("im_what", IM_PROGRESS);
msg.AddString("protocol", kProtocolSignature);
msg.AddString("title", title);
msg.AddString("message", message);
msg.AddFloat("progress", progress);
fServerMessenger->SendMessage(&msg);
} }
@ -402,9 +411,8 @@ JabberHandler::onConnect()
{ {
BMessage msg(IM_MESSAGE); BMessage msg(IM_MESSAGE);
msg.AddInt32("im_what", IM_OWN_STATUS_SET); msg.AddInt32("im_what", IM_OWN_STATUS_SET);
msg.AddString("protocol", kProtocolSignature);
msg.AddInt32("status", CAYA_ONLINE); msg.AddInt32("status", CAYA_ONLINE);
fServerMessenger->SendMessage(&msg); _SendMessage(&msg);
BString content(fUsername); BString content(fUsername);
content << " has logged in!"; content << " has logged in!";
@ -419,9 +427,8 @@ JabberHandler::onDisconnect(gloox::ConnectionError e)
{ {
BMessage msg(IM_MESSAGE); BMessage msg(IM_MESSAGE);
msg.AddInt32("im_what", IM_OWN_STATUS_SET); msg.AddInt32("im_what", IM_OWN_STATUS_SET);
msg.AddString("protocol", kProtocolSignature);
msg.AddInt32("status", CAYA_OFFLINE); msg.AddInt32("status", CAYA_OFFLINE);
fServerMessenger->SendMessage(&msg); _SendMessage(&msg);
BString content(fUsername); BString content(fUsername);
content << " has logged out!"; content << " has logged out!";
@ -462,7 +469,6 @@ JabberHandler::handleRoster(const gloox::Roster& roster)
// Contact information message // Contact information message
BMessage infoMsg(IM_MESSAGE); BMessage infoMsg(IM_MESSAGE);
infoMsg.AddInt32("im_what", IM_CONTACT_INFO); infoMsg.AddInt32("im_what", IM_CONTACT_INFO);
infoMsg.AddString("protocol", kProtocolSignature);
infoMsg.AddString("id", jid); infoMsg.AddString("id", jid);
infoMsg.AddString("name", name); infoMsg.AddString("name", name);
infoMsg.AddInt32("subscription", subscription); infoMsg.AddInt32("subscription", subscription);
@ -485,15 +491,14 @@ JabberHandler::handleRoster(const gloox::Roster& roster)
} }
// Send server based contact list // Send server based contact list
contactListMsg.AddString("protocol", kProtocolSignature); _SendMessage(&contactListMsg);
fServerMessenger->SendMessage(&contactListMsg);
// Contact list and vCard request // Contact list and vCard request
std::list<BMessage>::iterator msgsIt; std::list<BMessage>::iterator msgsIt;
for (msgsIt = msgs.begin(); msgsIt != msgs.end(); ++msgsIt) { for (msgsIt = msgs.begin(); msgsIt != msgs.end(); ++msgsIt) {
BMessage msg = (*msgsIt); BMessage msg = (*msgsIt);
const char* jid = msg.FindString("id"); const char* jid = msg.FindString("id");
fServerMessenger->SendMessage(&msg); _SendMessage(&msg);
fVCardManager->fetchVCard(gloox::JID(jid), this); fVCardManager->fetchVCard(gloox::JID(jid), this);
} }
} }
@ -511,11 +516,10 @@ JabberHandler::handleMessage(const gloox::Message& m, gloox::MessageSession*)
} else { } else {
BMessage msg(IM_MESSAGE); BMessage msg(IM_MESSAGE);
msg.AddInt32("im_what", IM_MESSAGE_RECEIVED); msg.AddInt32("im_what", IM_MESSAGE_RECEIVED);
msg.AddString("protocol", kProtocolSignature);
msg.AddString("id", m.from().bare().c_str()); msg.AddString("id", m.from().bare().c_str());
msg.AddString("subject", m.subject().c_str()); msg.AddString("subject", m.subject().c_str());
msg.AddString("body", m.body().c_str()); msg.AddString("body", m.body().c_str());
fServerMessenger->SendMessage(&msg); _SendMessage(&msg);
} }
} }
@ -558,11 +562,10 @@ JabberHandler::handleRosterPresence(const gloox::RosterItem& item,
{ {
BMessage msg(IM_MESSAGE); BMessage msg(IM_MESSAGE);
msg.AddInt32("im_what", IM_STATUS_SET); msg.AddInt32("im_what", IM_STATUS_SET);
msg.AddString("protocol", kProtocolSignature);
msg.AddString("id", item.jid().c_str()); msg.AddString("id", item.jid().c_str());
msg.AddInt32("status", _GlooxStatusToCaya(type)); msg.AddInt32("status", _GlooxStatusToCaya(type));
msg.AddString("message", presenceMsg.c_str()); msg.AddString("message", presenceMsg.c_str());
fServerMessenger->SendMessage(&msg); _SendMessage(&msg);
} }
@ -581,7 +584,7 @@ JabberHandler::handleSelfPresence(const gloox::RosterItem& item, const std::stri
//groups //groups
msg.AddInt32("status", _GlooxStatusToCaya(type)); msg.AddInt32("status", _GlooxStatusToCaya(type));
msg.AddString("message", presenceMsg.c_str()); msg.AddString("message", presenceMsg.c_str());
fServerMessenger->SendMessage(&msg); _SendMessage(&msg);
} }
@ -633,7 +636,6 @@ JabberHandler::handleVCard(const gloox::JID& jid, const gloox::VCard* card)
BMessage msg(IM_MESSAGE); BMessage msg(IM_MESSAGE);
msg.AddInt32("im_what", IM_EXTENDED_CONTACT_INFO); msg.AddInt32("im_what", IM_EXTENDED_CONTACT_INFO);
msg.AddString("protocol", kProtocolSignature);
msg.AddString("id", jid.bare().c_str()); msg.AddString("id", jid.bare().c_str());
msg.AddString("nick", card->nickname().c_str()); msg.AddString("nick", card->nickname().c_str());
msg.AddString("family name", name.family.c_str()); msg.AddString("family name", name.family.c_str());
@ -642,7 +644,7 @@ JabberHandler::handleVCard(const gloox::JID& jid, const gloox::VCard* card)
msg.AddString("prefix", name.prefix.c_str()); msg.AddString("prefix", name.prefix.c_str());
msg.AddString("suffix", name.suffix.c_str()); msg.AddString("suffix", name.suffix.c_str());
msg.AddString("full name", fullName.c_str()); msg.AddString("full name", fullName.c_str());
fServerMessenger->SendMessage(&msg); _SendMessage(&msg);
// Return if there's no avatar icon // Return if there's no avatar icon
if (!photo.binval.c_str()) if (!photo.binval.c_str())

View File

@ -76,15 +76,18 @@ private:
BMessage fAvatarCache; BMessage fAvatarCache;
BList* fAvatars; BList* fAvatars;
void _SendMessage(BMessage* msg);
void _MessageSent(const char* id, const char* subject, void _MessageSent(const char* id, const char* subject,
const char* body); const char* body);
CayaStatus _GlooxStatusToCaya(gloox::Presence::PresenceType type); void _Progress(const char* title, const char* message, float progress);
status_t _SetupAvatarCache(); status_t _SetupAvatarCache();
status_t _SaveAvatarCache(); status_t _SaveAvatarCache();
void _CacheAvatar(const char* id, const char* binval, size_t length); void _CacheAvatar(const char* id, const char* binval, size_t length);
void _AvatarChanged(const char*id, const char* filename); void _AvatarChanged(const char*id, const char* filename);
void _Progress(const char* title, const char* message, float progress);
CayaStatus _GlooxStatusToCaya(gloox::Presence::PresenceType type);
virtual void onConnect(); virtual void onConnect();
virtual void onDisconnect(gloox::ConnectionError); virtual void onDisconnect(gloox::ConnectionError);