bool XMPPChatMarkerCommand::executeCommand(QStringList * const arguments) { bool ret = false; if (arguments->length() not_eq 2) { this->client->write(tr("ERROR: xmppChatMarker <resource> <marker>") + "\r\n"); } else { const QString resource = arguments->first(); QXmppClient * const client = XMPPResourceStore::instance()->getFromStore(resource); arguments->removeFirst(); if (client) { QSharedPointer<QXmppStanza> lastStanza = XMPPResourceStore::instance()->getLastMessageReceived( client); if (lastStanza) { const QSharedPointer<QXmppMessage> lastMsg = lastStanza.dynamicCast<QXmppMessage>(); if (lastMsg and lastMsg->isMarkable()) { bool markerOk = true; QXmppMessage::Marker msgMarker; const QString marker = arguments->first(); arguments->removeFirst(); if (marker == "received") { msgMarker = QXmppMessage::Received; } else if (marker == "displayed") { msgMarker = QXmppMessage::Displayed; } else if (marker == "acknowledged") { msgMarker = QXmppMessage::Acknowledged; } else { markerOk = false; } if (markerOk) { QXmppMessage markerMessage; markerMessage.setId(QUuid::createUuid().toString()); markerMessage.setThread(""); markerMessage.setMarkable(false); markerMessage.setTo(lastMsg->from()); markerMessage.setMarker(msgMarker, lastMsg->id()); markerMessage.addHint(QXmppMessage::AllowPermantStorage); if (XMPPDebugCommand::isDebugEnabled()) { XMPPPrintCommand::printMessage( true, &markerMessage); } ret = client->sendPacket(markerMessage); if (not ret) { this->client->write(tr("ERROR: Failed to send packet") + "\r\n"); } else { XMPPResourceStore::instance()->setLastMessageSent( client, markerMessage); } } else { this->client->write(tr("ERROR: Invalid marker") + "\r\n"); } } else { this->client->write(tr("ERROR: The last message isn't Markable") + "\r\n"); } } else { this->client->write(tr("ERROR: Can't find the last message received to mark") + "\r\n"); } } else { this->client->write(tr("ERROR: Unknown resource") + "\r\n"); } } return ret; }