primitive messages receiving
This commit is contained in:
parent
4775c7b700
commit
3cc53dfaf6
15 changed files with 264 additions and 22 deletions
|
@ -333,20 +333,76 @@ void Core::Account::setResource(const QString& p_resource)
|
|||
config.setResource(p_resource);
|
||||
}
|
||||
|
||||
void Core::Account::onMessageReceived(const QXmppMessage& message)
|
||||
void Core::Account::onMessageReceived(const QXmppMessage& msg)
|
||||
{
|
||||
qDebug() << "Message received: ";
|
||||
qDebug() << "- from: " << message.from();
|
||||
qDebug() << "- to: " << message.to();
|
||||
qDebug() << "- body: " << message.body();
|
||||
qDebug() << "- type: " << message.type();
|
||||
qDebug() << "- state: " << message.state();
|
||||
qDebug() << "- stamp: " << message.stamp();
|
||||
qDebug() << "- id: " << message.id();
|
||||
qDebug() << "- isAttentionRequested: " << message.isAttentionRequested();
|
||||
qDebug() << "- isReceiptRequested: " << message.isReceiptRequested();
|
||||
qDebug() << "- receiptId: " << message.receiptId();
|
||||
qDebug() << "- subject: " << message.subject();
|
||||
qDebug() << "- thread: " << message.thread();
|
||||
qDebug() << "- isMarkable: " << message.isMarkable();
|
||||
QString from = msg.from();
|
||||
QStringList fcomps = from.split("/");
|
||||
QString fjid = fcomps.front();
|
||||
QString fresource = fcomps.back();
|
||||
|
||||
QString to = msg.to();
|
||||
QStringList tcomps = to.split("/");
|
||||
QString tjid = tcomps.front();
|
||||
QString tresource = tcomps.back();
|
||||
bool handled = false;
|
||||
switch (msg.type()) {
|
||||
case QXmppMessage::Normal:
|
||||
qDebug() << "received a message with type \"Normal\", not sure what to do with it now, skipping";
|
||||
break;
|
||||
case QXmppMessage::Chat:{
|
||||
QString body(msg.body());
|
||||
if (body.size() != 0) {
|
||||
QString id(msg.id());
|
||||
emit message({
|
||||
{"body", body},
|
||||
{"from", fjid},
|
||||
{"to", tjid},
|
||||
{"fromResource", fresource},
|
||||
{"toResource", tresource},
|
||||
{"id", id}
|
||||
});
|
||||
|
||||
if (msg.isReceiptRequested() && id.size() > 0) {
|
||||
QXmppMessage receipt(getFullJid(), from, "");
|
||||
receipt.setReceiptId(id);
|
||||
client.sendPacket(receipt);
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case QXmppMessage::GroupChat:
|
||||
qDebug() << "received a message with type \"GroupChat\", not sure what to do with it now, skipping";
|
||||
break;
|
||||
case QXmppMessage::Error:
|
||||
qDebug() << "received a message with type \"Error\", not sure what to do with it now, skipping";
|
||||
break;
|
||||
case QXmppMessage::Headline:
|
||||
qDebug() << "received a message with type \"Headline\", not sure what to do with it now, skipping";
|
||||
break;
|
||||
}
|
||||
if (!handled) {
|
||||
|
||||
qDebug() << "Message wasn't handled: ";
|
||||
qDebug() << "- from: " << msg.from();
|
||||
qDebug() << "- to: " << msg.to();
|
||||
qDebug() << "- body: " << msg.body();
|
||||
qDebug() << "- type: " << msg.type();
|
||||
qDebug() << "- state: " << msg.state();
|
||||
qDebug() << "- stamp: " << msg.stamp();
|
||||
qDebug() << "- id: " << msg.id();
|
||||
qDebug() << "- isAttentionRequested: " << msg.isAttentionRequested();
|
||||
qDebug() << "- isReceiptRequested: " << msg.isReceiptRequested();
|
||||
qDebug() << "- receiptId: " << msg.receiptId();
|
||||
qDebug() << "- subject: " << msg.subject();
|
||||
qDebug() << "- thread: " << msg.thread();
|
||||
qDebug() << "- isMarkable: " << msg.isMarkable();
|
||||
qDebug() << "==============================";
|
||||
}
|
||||
}
|
||||
|
||||
QString Core::Account::getFullJid() const
|
||||
{
|
||||
return getLogin() + "@" + getServer() + "/" + getResource();
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ public:
|
|||
void setPassword(const QString& p_password);
|
||||
void setResource(const QString& p_resource);
|
||||
void setAvailability(Shared::Availability avail);
|
||||
QString getFullJid() const;
|
||||
|
||||
signals:
|
||||
void connectionStateChanged(int);
|
||||
|
@ -47,6 +48,7 @@ signals:
|
|||
void changeContact(const QString& jid, const QMap<QString, QVariant>& data);
|
||||
void addPresence(const QString& jid, const QString& name, const QMap<QString, QVariant>& data);
|
||||
void removePresence(const QString& jid, const QString& name);
|
||||
void message(const QMap<QString, QString>& data);
|
||||
|
||||
private:
|
||||
QString name;
|
||||
|
|
|
@ -86,6 +86,7 @@ void Core::Squawk::addAccount(const QString& login, const QString& server, const
|
|||
connect(acc, SIGNAL(addPresence(const QString&, const QString&, const QMap<QString, QVariant>&)),
|
||||
this, SLOT(onAccountAddPresence(const QString&, const QString&, const QMap<QString, QVariant>&)));
|
||||
connect(acc, SIGNAL(removePresence(const QString&, const QString&)), this, SLOT(onAccountRemovePresence(const QString&, const QString&)));
|
||||
connect(acc, SIGNAL(message(const QMap<QString, QString>&)), this, SLOT(onAccountMessage(const QMap<QString, QString>&)));
|
||||
|
||||
QMap<QString, QVariant> map = {
|
||||
{"login", login},
|
||||
|
@ -192,3 +193,9 @@ void Core::Squawk::onAccountAvailabilityChanged(int state)
|
|||
Account* acc = static_cast<Account*>(sender());
|
||||
emit accountAvailabilityChanged(acc->getName(), state);
|
||||
}
|
||||
|
||||
void Core::Squawk::onAccountMessage(const QMap<QString, QString>& data)
|
||||
{
|
||||
Account* acc = static_cast<Account*>(sender());
|
||||
emit accountMessage(acc->getName(), data);
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ signals:
|
|||
void addPresence(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data);
|
||||
void removePresence(const QString& account, const QString& jid, const QString& name);
|
||||
void stateChanged(int state);
|
||||
void accountMessage(const QString& account, const QMap<QString, QString>& data);
|
||||
|
||||
public slots:
|
||||
void start();
|
||||
|
@ -66,6 +67,7 @@ private slots:
|
|||
void onAccountChangeContact(const QString& jid, const QMap<QString, QVariant>& data);
|
||||
void onAccountAddPresence(const QString& jid, const QString& name, const QMap<QString, QVariant>& data);
|
||||
void onAccountRemovePresence(const QString& jid, const QString& name);
|
||||
void onAccountMessage(const QMap<QString, QString>& data);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue