From c54f38cabcf6db20b933a447135e73866156b871 Mon Sep 17 00:00:00 2001
From: Tobias Markmann <tm@ayena.de>
Date: Wed, 19 Feb 2014 16:34:52 +0100
Subject: Handle error responses to XEP-0184 receipt requests.

Change-Id: I23d77168c1c387342164d857a3eb5577bff65fb9
License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.

diff --git a/Swift/Controllers/Chat/ChatController.cpp b/Swift/Controllers/Chat/ChatController.cpp
index 13fd22b..fd6da94 100644
--- a/Swift/Controllers/Chat/ChatController.cpp
+++ b/Swift/Controllers/Chat/ChatController.cpp
@@ -188,12 +188,21 @@ void ChatController::preHandleIncomingMessage(boost::shared_ptr<MessageEvent> me
 	chatStateTracker_->handleMessageReceived(message);
 	chatStateNotifier_->receivedMessageFromContact(message->getPayload<ChatState>());
 
+	// handle XEP-0184 Message Receipts
+	// incomming receipts
 	if (boost::shared_ptr<DeliveryReceipt> receipt = message->getPayload<DeliveryReceipt>()) {
 		SWIFT_LOG(debug) << "received receipt for id: " << receipt->getReceivedID() << std::endl;
 		if (requestedReceipts_.find(receipt->getReceivedID()) != requestedReceipts_.end()) {
 			chatWindow_->setMessageReceiptState(requestedReceipts_[receipt->getReceivedID()], ChatWindow::ReceiptReceived);
 			requestedReceipts_.erase(receipt->getReceivedID());
 		}
+	// incomming errors in response to send out receipts
+	} else if (message->getPayload<DeliveryReceiptRequest>() && (message->getType() == Message::Error)) {
+		if (requestedReceipts_.find(message->getID()) != requestedReceipts_.end()) {
+			chatWindow_->setMessageReceiptState(requestedReceipts_[message->getID()], ChatWindow::ReceiptFailed);
+			requestedReceipts_.erase(message->getID());
+		}
+	// incoming receipt requests
 	} else if (message->getPayload<DeliveryReceiptRequest>()) {
 		if (receivingPresenceFromUs_) {
 			boost::shared_ptr<Message> receiptMessage = boost::make_shared<Message>();
diff --git a/Swift/Controllers/UIInterfaces/ChatWindow.h b/Swift/Controllers/UIInterfaces/ChatWindow.h
index e6f61ca..0f0062d 100644
--- a/Swift/Controllers/UIInterfaces/ChatWindow.h
+++ b/Swift/Controllers/UIInterfaces/ChatWindow.h
@@ -84,7 +84,7 @@ namespace Swift {
 
 
 			enum AckState {Pending, Received, Failed};
-			enum ReceiptState {ReceiptRequested, ReceiptReceived};
+			enum ReceiptState {ReceiptRequested, ReceiptReceived, ReceiptFailed};
 			enum Tristate {Yes, No, Maybe};
 			enum OccupantAction {Kick, Ban, MakeModerator, MakeParticipant, MakeVisitor, AddContact, ShowProfile};
 			enum RoomAction {ChangeSubject, Configure, Affiliations, Destroy, Invite};
diff --git a/Swift/QtUI/QtWebKitChatView.cpp b/Swift/QtUI/QtWebKitChatView.cpp
index d1e250c..3f021e9 100644
--- a/Swift/QtUI/QtWebKitChatView.cpp
+++ b/Swift/QtUI/QtWebKitChatView.cpp
@@ -905,6 +905,8 @@ void QtWebKitChatView::setMessageReceiptState(const std::string& id, ChatWindow:
 		case ChatWindow::ReceiptRequested:
 			xml = "<img src='qrc:/icons/warn.png' title='" + tr("The receipt for this message has not yet been received. The recipient(s) might not have received this message.") + "'/>";
 			break;
+		case ChatWindow::ReceiptFailed:
+			xml = "<img src='qrc:/icons/error.png' title='" + tr("Failed to transmit message to the receipient(s).") + "'/>";
 	}
 	setReceiptXML(P2QSTRING(id), xml);
 }
-- 
cgit v0.10.2-6-g49f6