Implemented the Version() method.

This commit is contained in:
plfiorini 2010-07-10 19:27:32 +00:00
parent 5e4e5d68c4
commit a9df932fec
2 changed files with 103 additions and 14 deletions

View File

@ -16,6 +16,9 @@
#include <libsupport/SHA1.h>
#include <libgloox/chatstatefilter.h>
#include <libgloox/messageeventfilter.h>
#include "JabberHandler.h"
@ -43,7 +46,8 @@ connect_thread(void* data)
JabberHandler::JabberHandler()
:
fClient(NULL),
fVCardManager(NULL)
fVCardManager(NULL),
fSession(NULL)
{
fAvatars = new BList();
}
@ -51,7 +55,6 @@ JabberHandler::JabberHandler()
JabberHandler::~JabberHandler()
{
fVCardManager->cancelVCardOperations(this);
Shutdown();
BString* item = NULL;
@ -126,8 +129,14 @@ JabberHandler::Process(BMessage* msg)
status_t
JabberHandler::Shutdown()
{
if (fClient)
if (fVCardManager)
fVCardManager->cancelVCardOperations(this);
if (fClient) {
fClient->disposeMessageSession(fSession);
fClient->disconnect();
}
return B_OK;
}
@ -178,7 +187,7 @@ JabberHandler::UpdateSettings(BMessage* msg)
if (fPort > 0)
fClient->setPort(fPort);
fClient->registerConnectionListener(this);
fClient->registerMessageHandler(this);
fClient->registerMessageSessionHandler(this);
fClient->rosterManager()->registerRosterListener(this);
fClient->disco()->setVersion("Caya", VERSION);
fClient->disco()->setIdentity("client", "caya");
@ -214,6 +223,13 @@ JabberHandler::MessengerInterface() const
}
uint32
JabberHandler::Version() const
{
return CAYA_VERSION_1_PRE_ALPHA_1;
}
gloox::Client*
JabberHandler::Client() const
{
@ -797,6 +813,29 @@ JabberHandler::handleRoster(const gloox::Roster& roster)
}
void
JabberHandler::handleMessageSession(gloox::MessageSession* session)
{
// Delete previous session
if (fSession)
fClient->disposeMessageSession(fSession);
fSession = session;
// Register message handler
fSession->registerMessageHandler(this);
// Message event filter
gloox::MessageEventFilter* messageFilter
= new gloox::MessageEventFilter(fSession);
messageFilter->registerMessageEventHandler(this);
// Chat state filter
gloox::ChatStateFilter* chatFilter
= new gloox::ChatStateFilter(fSession);
chatFilter->registerChatStateHandler(this);
}
void
JabberHandler::handleMessage(const gloox::Message& m, gloox::MessageSession*)
{
@ -804,16 +843,53 @@ JabberHandler::handleMessage(const gloox::Message& m, gloox::MessageSession*)
if (m.subtype() != gloox::Message::Chat)
return;
if (m.body() == "") {
// TODO: Started and stopped typing
} else {
// We need a body
if (m.body() == "")
return;
// Notify that a chat message was received
BMessage msg(IM_MESSAGE);
msg.AddInt32("im_what", IM_MESSAGE_RECEIVED);
msg.AddString("id", m.from().bare().c_str());
msg.AddInt32("im_what", IM_MESSAGE_RECEIVED);
if (m.subject() != "")
msg.AddString("subject", m.subject().c_str());
msg.AddString("body", m.body().c_str());
_SendMessage(&msg);
}
void
JabberHandler::handleMessageEvent(const gloox::JID& from, gloox::MessageEventType event)
{
}
void
JabberHandler::handleChatState(const gloox::JID& from, gloox::ChatStateType state)
{
printf("------ %d\n", state);
// We're interested only in some states
if (state == gloox::ChatStateActive || state == gloox::ChatStateInvalid)
return;
BMessage msg(IM_MESSAGE);
msg.AddString("id", from.bare().c_str());
switch (state) {
case gloox::ChatStateComposing:
msg.AddInt32("im_what", IM_CONTACT_STARTED_TYPING);
break;
case gloox::ChatStatePaused:
msg.AddInt32("im_what", IM_CONTACT_STOPPED_TYPING);
break;
case gloox::ChatStateGone:
// TODO
break;
default:
break;
}
_SendMessage(&msg);
}

View File

@ -10,6 +10,7 @@
#include <String.h>
#include <libgloox/client.h>
#include <libgloox/chatstatehandler.h>
#include <libgloox/connectionlistener.h>
#include <libgloox/connectiontcpclient.h>
#include <libgloox/discohandler.h>
@ -18,6 +19,9 @@
#include <libgloox/loghandler.h>
#include <libgloox/logsink.h>
#include <libgloox/messagehandler.h>
#include <libgloox/messagesession.h>
#include <libgloox/messagesessionhandler.h>
#include <libgloox/messageeventhandler.h>
#include <libgloox/message.h>
#include <libgloox/presence.h>
#include <libgloox/vcardhandler.h>
@ -29,7 +33,9 @@
class BList;
class JabberHandler : public CayaProtocol, gloox::RosterListener, gloox::ConnectionListener,
gloox::LogHandler, gloox::MessageHandler, gloox::VCardHandler {
gloox::LogHandler, gloox::MessageSessionHandler,
gloox::MessageHandler, gloox::MessageEventHandler,
gloox::ChatStateHandler, gloox::VCardHandler {
public:
JabberHandler();
virtual ~JabberHandler();
@ -51,6 +57,8 @@ public:
virtual CayaProtocolMessengerInterface*
MessengerInterface() const;
virtual uint32 Version() const;
// Functions for gloox
gloox::Client* Client() const;
void HandleError(gloox::ConnectionError& e);
@ -74,6 +82,7 @@ private:
gloox::ConnectionTCPClient*
fConnection;
gloox::VCardManager* fVCardManager;
gloox::MessageSession* fSession;
gloox::JID fJid;
thread_id fRecvThread;
@ -103,7 +112,11 @@ private:
virtual bool onTLSConnect(const gloox::CertInfo&);
virtual void onResourceBindError(const gloox::Error*);
virtual void handleRoster(const gloox::Roster&);
virtual void handleMessage(const gloox::Message&, gloox::MessageSession*);
virtual void handleMessageSession(gloox::MessageSession* session);
virtual void handleMessage(const gloox::Message& m, gloox::MessageSession*);
virtual void handleMessageEvent(const gloox::JID& from, gloox::MessageEventType event);
virtual void handleChatState(const gloox::JID& from, gloox::ChatStateType state);
virtual void handleItemAdded(const gloox::JID&);
virtual void handleItemSubscribed(const gloox::JID&);
virtual void handleItemUnsubscribed(const gloox::JID&);