Working conversation from legacy -> XMPP
This commit is contained in:
parent
18a72df685
commit
76c678dd6f
11 changed files with 377 additions and 6 deletions
53
include/transport/abstractconversation.h
Normal file
53
include/transport/abstractconversation.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* XMPP - libpurple transport
|
||||
*
|
||||
* Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include "transport/transport.h"
|
||||
|
||||
#include "Swiften/Swiften.h"
|
||||
#include "Swiften/Elements/Message.h"
|
||||
|
||||
namespace Transport {
|
||||
|
||||
class ConversationManager;
|
||||
|
||||
class AbstractConversation {
|
||||
public:
|
||||
/// Constructor.
|
||||
AbstractConversation(ConversationManager *conversationManager, const std::string &legacyName);
|
||||
|
||||
/// Destructor
|
||||
virtual ~AbstractConversation();
|
||||
|
||||
const std::string &getLegacyName() { return m_legacyName; }
|
||||
|
||||
void handleMessage(boost::shared_ptr<Swift::Message> &message);
|
||||
|
||||
virtual void sendMessage(boost::shared_ptr<Swift::Message> &message) = 0;
|
||||
|
||||
private:
|
||||
ConversationManager *m_conversationManager;
|
||||
std::string m_legacyName;
|
||||
};
|
||||
|
||||
}
|
61
include/transport/conversationmanager.h
Normal file
61
include/transport/conversationmanager.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
* XMPP - libpurple transport
|
||||
*
|
||||
* Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include "Swiften/Swiften.h"
|
||||
|
||||
namespace Transport {
|
||||
|
||||
class AbstractConversation;
|
||||
class User;
|
||||
class Component;
|
||||
|
||||
class ConversationManager {
|
||||
public:
|
||||
/// Creates new ConversationManager.
|
||||
/// \param user User associated with this ConversationManager.
|
||||
/// \param component Transport instance associated with this roster.
|
||||
ConversationManager(User *user, Component *component);
|
||||
|
||||
/// Destructor.
|
||||
virtual ~ConversationManager();
|
||||
|
||||
/// Returns user associated with this manager.
|
||||
/// \return User
|
||||
User *getUser() { return m_user; }
|
||||
|
||||
Component *getComponent() { return m_component; }
|
||||
|
||||
void setConversation(AbstractConversation *conv);
|
||||
|
||||
void unsetConversation(AbstractConversation *conv);
|
||||
|
||||
private:
|
||||
Component *m_component;
|
||||
User *m_user;
|
||||
|
||||
std::map<std::string, AbstractConversation *> m_convs;
|
||||
};
|
||||
|
||||
}
|
|
@ -54,6 +54,8 @@ class RosterManager {
|
|||
/// \param buddy AbstractBuddy.
|
||||
void unsetBuddy(AbstractBuddy *buddy);
|
||||
|
||||
AbstractBuddy *getBuddy(const std::string &name);
|
||||
|
||||
/// Returns user associated with this roster.
|
||||
/// \return User
|
||||
User *getUser() { return m_user; }
|
||||
|
|
|
@ -30,6 +30,7 @@ namespace Transport {
|
|||
|
||||
class Component;
|
||||
class RosterManager;
|
||||
class ConversationManager;
|
||||
struct UserInfo;
|
||||
|
||||
/// Represents online XMPP user.
|
||||
|
@ -55,6 +56,8 @@ class User {
|
|||
|
||||
RosterManager *getRosterManager() { return m_rosterManager; }
|
||||
|
||||
ConversationManager *getConversationManager() { return m_conversationManager; }
|
||||
|
||||
|
||||
Component *getComponent() { return m_component; }
|
||||
|
||||
|
@ -77,6 +80,7 @@ class User {
|
|||
Swift::JID m_jid;
|
||||
Component *m_component;
|
||||
RosterManager *m_rosterManager;
|
||||
ConversationManager *m_conversationManager;
|
||||
Swift::EntityCapsManager *m_entityCapsManager;
|
||||
Swift::PresenceOracle *m_presenceOracle;
|
||||
UserInfo m_userInfo;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "transport/rostermanager.h"
|
||||
#include "spectrumeventloop.h"
|
||||
#include "spectrumbuddy.h"
|
||||
#include "spectrumconversation.h"
|
||||
#include "geventloop.h"
|
||||
|
||||
#define Log(X, STRING) std::cout << "[SPECTRUM] " << X << " " << STRING << "\n";
|
||||
|
@ -109,8 +110,8 @@ static void NodeRemoved(PurpleBlistNode *node, void *data) {
|
|||
return;
|
||||
PurpleBuddy *buddy = (PurpleBuddy *) node;
|
||||
|
||||
PurpleAccount *account = purple_buddy_get_account(buddy);
|
||||
User *user = (User *) account->ui_data;
|
||||
// PurpleAccount *account = purple_buddy_get_account(buddy);
|
||||
// User *user = (User *) account->ui_data;
|
||||
if (buddy->node.ui_data) {
|
||||
SpectrumBuddy *s_buddy = (SpectrumBuddy *) buddy->node.ui_data;
|
||||
s_buddy->removeBuddy(buddy);
|
||||
|
@ -139,6 +140,63 @@ static PurpleBlistUiOps blistUiOps =
|
|||
NULL
|
||||
};
|
||||
|
||||
static void conv_new(PurpleConversation *conv) {
|
||||
PurpleAccount *account = purple_conversation_get_account(conv);
|
||||
User *user = (User *) account->ui_data;
|
||||
|
||||
if (!user)
|
||||
return;
|
||||
|
||||
std::string name = purple_conversation_get_name(conv);
|
||||
size_t pos = name.find("/");
|
||||
if (pos != std::string::npos)
|
||||
name.erase((int) pos, name.length() - (int) pos);
|
||||
|
||||
SpectrumConversation *s_conv = new SpectrumConversation(user->getConversationManager(), name, conv);
|
||||
conv->ui_data = s_conv;
|
||||
}
|
||||
|
||||
static void conv_destroy(PurpleConversation *conv) {
|
||||
SpectrumConversation *s_conv = (SpectrumConversation *) conv->ui_data;
|
||||
if (s_conv) {
|
||||
delete s_conv;
|
||||
}
|
||||
}
|
||||
|
||||
static void conv_write_im(PurpleConversation *conv, const char *who, const char *message, PurpleMessageFlags flags, time_t mtime) {
|
||||
SpectrumConversation *s_conv = (SpectrumConversation *) conv->ui_data;
|
||||
if (!s_conv)
|
||||
return;
|
||||
|
||||
boost::shared_ptr<Swift::Message> msg(new Swift::Message());
|
||||
msg->setBody(message);
|
||||
|
||||
s_conv->handleMessage(msg);
|
||||
}
|
||||
|
||||
static PurpleConversationUiOps conversation_ui_ops =
|
||||
{
|
||||
conv_new,
|
||||
conv_destroy,
|
||||
NULL,//conv_write_chat, /* write_chat */
|
||||
conv_write_im, /* write_im */
|
||||
NULL,//conv_write_conv, /* write_conv */
|
||||
NULL,//conv_chat_add_users, /* chat_add_users */
|
||||
NULL,//conv_chat_rename_user, /* chat_rename_user */
|
||||
NULL,//conv_chat_remove_users, /* chat_remove_users */
|
||||
NULL,//pidgin_conv_chat_update_user, /* chat_update_user */
|
||||
NULL,//pidgin_conv_present_conversation, /* present */
|
||||
NULL,//pidgin_conv_has_focus, /* has_focus */
|
||||
NULL,//pidgin_conv_custom_smiley_add, /* custom_smiley_add */
|
||||
NULL,//pidgin_conv_custom_smiley_write, /* custom_smiley_write */
|
||||
NULL,//pidgin_conv_custom_smiley_close, /* custom_smiley_close */
|
||||
NULL,//pidgin_conv_send_confirm, /* send_confirm */
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
static void transport_core_ui_init(void)
|
||||
{
|
||||
purple_blist_set_ui_ops(&blistUiOps);
|
||||
|
@ -147,7 +205,7 @@ static void transport_core_ui_init(void)
|
|||
// purple_request_set_ui_ops(&requestUiOps);
|
||||
// purple_xfers_set_ui_ops(getXferUiOps());
|
||||
// purple_connections_set_ui_ops(&conn_ui_ops);
|
||||
// purple_conversations_set_ui_ops(&conversation_ui_ops);
|
||||
purple_conversations_set_ui_ops(&conversation_ui_ops);
|
||||
// #ifndef WIN32
|
||||
// purple_dnsquery_set_ui_ops(getDNSUiOps());
|
||||
// #endif
|
||||
|
@ -196,6 +254,8 @@ static bool initPurple(Config &cfg) {
|
|||
bool ret;
|
||||
|
||||
purple_util_set_user_dir("./");
|
||||
remove("./accounts.xml");
|
||||
remove("./blist.xml");
|
||||
|
||||
// if (m_configuration.logAreas & LOG_AREA_PURPLE)
|
||||
purple_debug_set_ui_ops(&debugUiOps);
|
||||
|
|
36
spectrum/src/spectrumconversation.cpp
Normal file
36
spectrum/src/spectrumconversation.cpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
* XMPP - libpurple transport
|
||||
*
|
||||
* Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
|
||||
*/
|
||||
|
||||
#include "spectrumconversation.h"
|
||||
#include "transport/user.h"
|
||||
|
||||
#define Log(X, STRING) std::cout << "[SPECTRUM] " << X << " " << STRING << "\n";
|
||||
|
||||
SpectrumConversation::SpectrumConversation(ConversationManager *conversationManager, const std::string &legacyName, PurpleConversation *conv) : AbstractConversation(conversationManager, legacyName), m_conv(conv) {
|
||||
}
|
||||
|
||||
SpectrumConversation::~SpectrumConversation() {
|
||||
}
|
||||
|
||||
void SpectrumConversation::sendMessage(boost::shared_ptr<Swift::Message> &message) {
|
||||
|
||||
}
|
||||
|
||||
|
46
spectrum/src/spectrumconversation.h
Normal file
46
spectrum/src/spectrumconversation.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* XMPP - libpurple transport
|
||||
*
|
||||
* Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "purple.h"
|
||||
#include "account.h"
|
||||
#include "glib.h"
|
||||
#include <algorithm>
|
||||
#include "transport/abstractconversation.h"
|
||||
#include "transport/conversationmanager.h"
|
||||
|
||||
using namespace Transport;
|
||||
|
||||
// Wrapper for PurpleBuddy
|
||||
class SpectrumConversation : public AbstractConversation {
|
||||
public:
|
||||
SpectrumConversation(ConversationManager *conversationManager, const std::string &legacyName, PurpleConversation *conv);
|
||||
virtual ~SpectrumConversation();
|
||||
|
||||
PurpleConversation *getConversation() { return m_conv; }
|
||||
|
||||
void sendMessage(boost::shared_ptr<Swift::Message> &message);
|
||||
|
||||
private:
|
||||
PurpleConversation *m_conv;
|
||||
};
|
||||
|
54
src/abstractconversation.cpp
Normal file
54
src/abstractconversation.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* XMPP - libpurple transport
|
||||
*
|
||||
* Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include "transport/abstractconversation.h"
|
||||
#include "transport/conversationmanager.h"
|
||||
#include "transport/user.h"
|
||||
#include "transport/transport.h"
|
||||
#include "transport/abstractbuddy.h"
|
||||
#include "transport/rostermanager.h"
|
||||
|
||||
namespace Transport {
|
||||
|
||||
AbstractConversation::AbstractConversation(ConversationManager *conversationManager, const std::string &legacyName) : m_conversationManager(conversationManager) {
|
||||
m_conversationManager->setConversation(this);
|
||||
m_legacyName = legacyName;
|
||||
}
|
||||
|
||||
AbstractConversation::~AbstractConversation() {
|
||||
m_conversationManager->unsetConversation(this);
|
||||
}
|
||||
|
||||
void AbstractConversation::handleMessage(boost::shared_ptr<Swift::Message> &message) {
|
||||
message->setTo(m_conversationManager->getUser()->getJID().toBare());
|
||||
AbstractBuddy *buddy = m_conversationManager->getUser()->getRosterManager()->getBuddy(m_legacyName);
|
||||
if (buddy) {
|
||||
std::cout << m_legacyName << " 222222\n";
|
||||
message->setFrom(buddy->getJID());
|
||||
}
|
||||
else {
|
||||
std::cout << m_legacyName << " 1111111\n";
|
||||
// TODO: escape from and setFrom
|
||||
}
|
||||
m_conversationManager->getComponent()->getStanzaChannel()->sendMessage(message);
|
||||
}
|
||||
|
||||
}
|
48
src/conversationmanager.cpp
Normal file
48
src/conversationmanager.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* XMPP - libpurple transport
|
||||
*
|
||||
* Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
|
||||
*/
|
||||
|
||||
#include "transport/conversationmanager.h"
|
||||
#include "transport/abstractconversation.h"
|
||||
#include "transport/usermanager.h"
|
||||
#include "transport/abstractbuddy.h"
|
||||
#include "transport/user.h"
|
||||
#include "Swiften/Roster/SetRosterRequest.h"
|
||||
#include "Swiften/Elements/RosterPayload.h"
|
||||
#include "Swiften/Elements/RosterItemPayload.h"
|
||||
|
||||
namespace Transport {
|
||||
|
||||
ConversationManager::ConversationManager(User *user, Component *component){
|
||||
m_user = user;
|
||||
m_component = component;
|
||||
}
|
||||
|
||||
ConversationManager::~ConversationManager() {
|
||||
}
|
||||
|
||||
void ConversationManager::setConversation(AbstractConversation *conv) {
|
||||
m_convs[conv->getLegacyName()] = conv;
|
||||
}
|
||||
|
||||
void ConversationManager::unsetConversation(AbstractConversation *conv) {
|
||||
m_convs.erase(conv->getLegacyName());
|
||||
}
|
||||
|
||||
}
|
|
@ -53,14 +53,14 @@ void RosterManager::sendBuddyRosterPush(AbstractBuddy *buddy) {
|
|||
payload->addItem(item);
|
||||
|
||||
Swift::SetRosterRequest::ref request = Swift::SetRosterRequest::create(payload, m_component->getIQRouter(), m_user->getJID().toBare());
|
||||
request->onResponse.connect(boost::bind(&RosterManager::handleBuddyRosterPushResponse, this, _1, buddy->getSafeName()));
|
||||
request->onResponse.connect(boost::bind(&RosterManager::handleBuddyRosterPushResponse, this, _1, buddy->getName()));
|
||||
request->send();
|
||||
}
|
||||
|
||||
void RosterManager::setBuddyCallback(AbstractBuddy *buddy) {
|
||||
m_setBuddyTimer->onTick.disconnect(boost::bind(&RosterManager::setBuddyCallback, this, buddy));
|
||||
|
||||
m_buddies[buddy->getSafeName()] = buddy;
|
||||
m_buddies[buddy->getName()] = buddy;
|
||||
onBuddySet(buddy);
|
||||
|
||||
if (m_component->inServerMode()) {
|
||||
|
@ -73,7 +73,7 @@ void RosterManager::setBuddyCallback(AbstractBuddy *buddy) {
|
|||
}
|
||||
|
||||
void RosterManager::unsetBuddy(AbstractBuddy *buddy) {
|
||||
m_buddies.erase(buddy->getSafeName());
|
||||
m_buddies.erase(buddy->getName());
|
||||
onBuddyUnset(buddy);
|
||||
}
|
||||
|
||||
|
@ -83,4 +83,8 @@ void RosterManager::handleBuddyRosterPushResponse(Swift::ErrorPayload::ref error
|
|||
}
|
||||
}
|
||||
|
||||
AbstractBuddy *RosterManager::getBuddy(const std::string &name) {
|
||||
return m_buddies[name];
|
||||
}
|
||||
|
||||
}
|
|
@ -22,6 +22,7 @@
|
|||
#include "transport/transport.h"
|
||||
#include "transport/storagebackend.h"
|
||||
#include "transport/rostermanager.h"
|
||||
#include "transport/conversationmanager.h"
|
||||
#include "Swiften/Swiften.h"
|
||||
|
||||
namespace Transport {
|
||||
|
@ -40,10 +41,12 @@ User::User(const Swift::JID &jid, UserInfo &userInfo, Component *component) {
|
|||
m_reconnectTimer->onTick.connect(boost::bind(&User::onConnectingTimeout, this));
|
||||
|
||||
m_rosterManager = new RosterManager(this, m_component);
|
||||
m_conversationManager = new ConversationManager(this, m_component);
|
||||
}
|
||||
|
||||
User::~User(){
|
||||
delete m_rosterManager;
|
||||
delete m_conversationManager;
|
||||
}
|
||||
|
||||
const Swift::JID &User::getJID() {
|
||||
|
|
Loading…
Add table
Reference in a new issue