very bad and basic archive support
This commit is contained in:
parent
48e735b0e9
commit
fad72d8db2
11 changed files with 180 additions and 20 deletions
|
@ -7,12 +7,14 @@ using namespace Core;
|
|||
Account::Account(const QString& p_login, const QString& p_server, const QString& p_password, const QString& p_name, QObject* parent):
|
||||
QObject(parent),
|
||||
name(p_name),
|
||||
achiveQueries(),
|
||||
client(),
|
||||
config(),
|
||||
presence(),
|
||||
state(Shared::disconnected),
|
||||
groups(),
|
||||
cm(new QXmppCarbonManager())
|
||||
cm(new QXmppCarbonManager()),
|
||||
am(new QXmppMamManager())
|
||||
{
|
||||
config.setUser(p_login);
|
||||
config.setDomain(p_server);
|
||||
|
@ -35,6 +37,12 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
|
|||
|
||||
QObject::connect(cm, SIGNAL(messageReceived(const QXmppMessage&)), this, SLOT(onCarbonMessageReceived(const QXmppMessage&)));
|
||||
QObject::connect(cm, SIGNAL(messageSent(const QXmppMessage&)), this, SLOT(onCarbonMessageSent(const QXmppMessage&)));
|
||||
|
||||
client.addExtension(am);
|
||||
|
||||
QObject::connect(am, SIGNAL(archivedMessageReceived(const QString&, const QXmppMessage&)), this, SLOT(onMamMessageReceived(const QString&, const QXmppMessage&)));
|
||||
QObject::connect(am, SIGNAL(resultsRecieved(const QString&, const QXmppResultSetReply&, bool)),
|
||||
this, SLOT(onMamResultsReceived(const QString&, const QXmppResultSetReply&, bool)));
|
||||
}
|
||||
|
||||
Account::~Account()
|
||||
|
@ -397,15 +405,15 @@ void Core::Account::sendMessage(const Shared::Message& data)
|
|||
|
||||
void Core::Account::onCarbonMessageReceived(const QXmppMessage& msg)
|
||||
{
|
||||
handleChatMessage(msg, false, true);
|
||||
handleChatMessage(msg, false, true);
|
||||
}
|
||||
|
||||
void Core::Account::onCarbonMessageSent(const QXmppMessage& msg)
|
||||
{
|
||||
handleChatMessage(msg, true, true);
|
||||
handleChatMessage(msg, true, true);
|
||||
}
|
||||
|
||||
bool Core::Account::handleChatMessage(const QXmppMessage& msg, bool outgoing, bool forwarded)
|
||||
bool Core::Account::handleChatMessage(const QXmppMessage& msg, bool outgoing, bool forwarded, bool guessing)
|
||||
{
|
||||
QString body(msg.body());
|
||||
if (body.size() != 0) {
|
||||
|
@ -417,6 +425,13 @@ bool Core::Account::handleChatMessage(const QXmppMessage& msg, bool outgoing, bo
|
|||
sMsg.setTo(msg.to());
|
||||
sMsg.setBody(body);
|
||||
sMsg.setForwarded(forwarded);
|
||||
if (guessing) {
|
||||
if (sMsg.getFromJid() == getLogin() + "@" + getServer()) {
|
||||
outgoing = true;
|
||||
} else {
|
||||
outgoing = false;
|
||||
}
|
||||
}
|
||||
sMsg.setOutgoing(outgoing);
|
||||
if (time.isValid()) {
|
||||
sMsg.setTime(time);
|
||||
|
@ -435,3 +450,32 @@ bool Core::Account::handleChatMessage(const QXmppMessage& msg, bool outgoing, bo
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Core::Account::onMamMessageReceived(const QString& bareJid, const QXmppMessage& msg)
|
||||
{
|
||||
handleChatMessage(msg, false, true, true);
|
||||
}
|
||||
|
||||
void Core::Account::requestAchive(const QString& jid)
|
||||
{
|
||||
QXmppResultSetQuery query;
|
||||
query.setMax(100);
|
||||
QDateTime from = QDateTime::currentDateTime().addDays(-7);
|
||||
|
||||
QString q = am->retrieveArchivedMessages("", "", jid, from, QDateTime(), query);
|
||||
achiveQueries.insert(std::make_pair(q, jid));
|
||||
}
|
||||
|
||||
void Core::Account::onMamResultsReceived(const QString& queryId, const QXmppResultSetReply& resultSetReply, bool complete)
|
||||
{
|
||||
std::map<QString, QString>::const_iterator itr = achiveQueries.find(queryId);
|
||||
QString jid = itr->second;
|
||||
achiveQueries.erase(itr);
|
||||
if (!complete) {
|
||||
QXmppResultSetQuery q;
|
||||
q.setAfter(resultSetReply.last());
|
||||
q.setMax(100);
|
||||
QString nQ = am->retrieveArchivedMessages("", "", jid, QDateTime::currentDateTime().addDays(-7), QDateTime(), q);
|
||||
achiveQueries.insert(std::make_pair(nQ, jid));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include <qxmpp/QXmppRosterManager.h>
|
||||
#include <qxmpp/QXmppCarbonManager.h>
|
||||
#include <qxmpp/QXmppMamManager.h>
|
||||
#include <qxmpp/QXmppClient.h>
|
||||
#include "../global.h"
|
||||
|
||||
|
@ -39,6 +40,7 @@ public:
|
|||
void setAvailability(Shared::Availability avail);
|
||||
QString getFullJid() const;
|
||||
void sendMessage(const Shared::Message& data);
|
||||
void requestAchive(const QString& jid);
|
||||
|
||||
signals:
|
||||
void connectionStateChanged(int);
|
||||
|
@ -55,12 +57,14 @@ signals:
|
|||
|
||||
private:
|
||||
QString name;
|
||||
std::map<QString, QString> achiveQueries;
|
||||
QXmppClient client;
|
||||
QXmppConfiguration config;
|
||||
QXmppPresence presence;
|
||||
Shared::ConnectionState state;
|
||||
std::map<QString, std::set<QString>> groups;
|
||||
QXmppCarbonManager* cm;
|
||||
QXmppMamManager* am;
|
||||
|
||||
private slots:
|
||||
void onClientConnected();
|
||||
|
@ -74,10 +78,12 @@ private slots:
|
|||
void onMessageReceived(const QXmppMessage& message);
|
||||
void onCarbonMessageReceived(const QXmppMessage& message);
|
||||
void onCarbonMessageSent(const QXmppMessage& message);
|
||||
void onMamMessageReceived(const QString& bareJid, const QXmppMessage& message);
|
||||
void onMamResultsReceived(const QString &queryId, const QXmppResultSetReply &resultSetReply, bool complete);
|
||||
|
||||
private:
|
||||
void addedAccount(const QString &bareJid);
|
||||
bool handleChatMessage(const QXmppMessage& msg, bool outgoing = false, bool forwarded = false);
|
||||
bool handleChatMessage(const QXmppMessage& msg, bool outgoing = false, bool forwarded = false, bool guessing = false);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -220,3 +220,13 @@ void Core::Squawk::sendMessage(const QString& account, const Shared::Message& da
|
|||
|
||||
itr->second->sendMessage(data);
|
||||
}
|
||||
|
||||
void Core::Squawk::requestArchive(const QString& account, const QString& jid)
|
||||
{
|
||||
AccountsMap::const_iterator itr = amap.find(account);
|
||||
if (itr == amap.end()) {
|
||||
qDebug("An attempt to request an archive of non existing account, skipping");
|
||||
return;
|
||||
}
|
||||
itr->second->requestAchive(jid);
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ public slots:
|
|||
void disconnectAccount(const QString& account);
|
||||
void changeState(int state);
|
||||
void sendMessage(const QString& account, const Shared::Message& data);
|
||||
void requestArchive(const QString& account, const QString& jid);
|
||||
|
||||
private:
|
||||
typedef std::deque<Account*> Accounts;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue