Commit 4d53d079 authored by Linus Jahn's avatar Linus Jahn Committed by Jonah Brüchert

MessageHandler: Don't reply to receipt requests from carbon messages

Fixes that own messages will be marked as received, when synced from other
clients.
parent b64e00b0
......@@ -52,6 +52,7 @@
#include <gloox/carbons.h>
#include <gloox/vcardmanager.h>
#include <gloox/vcardupdate.h>
#include <gloox/delayeddelivery.h>
// package fetch interval in ms
static const unsigned int KAIDAN_CLIENT_LOOP_INTERVAL = 30;
......
......@@ -36,6 +36,9 @@
#include <QDebug>
#include <QString>
// gloox
#include <gloox/client.h>
#include <gloox/message.h>
#include <gloox/messagesession.h>
#include <gloox/receipt.h>
#include <gloox/carbons.h>
// Kaidan
......@@ -104,7 +107,7 @@ void MessageHandler::handleMessage(const gloox::Message &stanza, gloox::MessageS
QString body = QString::fromStdString(message->body());
if (body.size() > 0) {
if (!body.isEmpty()) {
//
// Extract information of the message
//
......@@ -164,28 +167,40 @@ void MessageHandler::handleMessage(const gloox::Message &stanza, gloox::MessageS
}
// XEP-0184: Message Delivery Receipts
// try to get a possible delivery receipt
// try to handle a possible delivery receipt
handleReceiptMessage(message, isCarbonMessage);
}
void MessageHandler::handleReceiptMessage(const gloox::Message *message,
bool isCarbonMessage)
{
// check if message contains receipt
gloox::Receipt *receipt = (gloox::Receipt*) message->findExtension<gloox::Receipt>(gloox::ExtReceipt);
if (!receipt)
return;
if (receipt) {
// get the type of the receipt
gloox::Receipt::ReceiptType receiptType = receipt->rcpt();
if (receiptType == gloox::Receipt::Request) {
// send the asked confirmation, that the message has been arrived
// new message to the author of the request
gloox::Message receiptMessage(gloox::Message::Chat, message->from());
// add the receipt extension containing the request's message id
gloox::Receipt *receiptPayload = new gloox::Receipt(gloox::Receipt::Received, message->id());
receiptMessage.addExtension(receiptPayload);
// send the receipt message
client->send(receiptMessage);
} else if (receiptType == gloox::Receipt::Received) {
// Delivery Receipt Received -> mark message as read in db
emit messageModel->setMessageAsDeliveredRequested(
QString::fromStdString(receipt->id()));
}
// get the type of the receipt
gloox::Receipt::ReceiptType receiptType = receipt->rcpt();
if (receiptType == gloox::Receipt::Request && !isCarbonMessage) {
// carbon messages won't be accepted to not send a receipt to own msgs
// carbon msgs from other contacts should be processed by the first client
// send the asked confirmation, that the message has been arrived
// new message to the author of the request
gloox::Message receiptMessage(gloox::Message::Chat, message->from());
// add the receipt extension containing the request's message id
gloox::Receipt *receiptPayload = new gloox::Receipt(gloox::Receipt::Received, message->id());
receiptMessage.addExtension(receiptPayload);
// send the receipt message
client->send(receiptMessage);
} else if (receiptType == gloox::Receipt::Received) {
// Delivery Receipt Received -> mark message as read in db
emit messageModel->setMessageAsDeliveredRequested(
QString::fromStdString(receipt->id()));
}
}
......
......@@ -35,14 +35,17 @@
#include <QObject>
#include <QSqlDatabase>
// gloox
#include <gloox/client.h>
#include <gloox/message.h>
#include <gloox/messagehandler.h>
#include <gloox/messagesession.h>
// Kaidan
#include "MessageModel.h"
#include "RosterModel.h"
namespace gloox {
class Client;
class Message;
class MessageSession;
}
class MessageHandler : public QObject, public gloox::MessageHandler
{
Q_OBJECT
......@@ -53,6 +56,13 @@ public:
~MessageHandler();
virtual void handleMessage(const gloox::Message &message, gloox::MessageSession *session = 0);
/**
* Handles a message with a possible receipt or receipt request
*/
void handleReceiptMessage(const gloox::Message *message,
bool isCarbonMessage);
void updateLastExchangedOfJid(const QString &jid);
void newUnreadMessageForJid(const QString &jid);
void resetUnreadMessagesForJid(const QString &jid);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment