From ba14df8bf05b6afc9782efbe638350177244feb6 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 17 Jan 2017 11:23:37 +0100 Subject: [PATCH] fix(src/components/chat/ChatModel): supports new message states --- tests/src/components/chat/ChatModel.cpp | 53 +++++++++---------- tests/src/components/chat/ChatModel.hpp | 5 ++ .../ui/modules/Linphone/Chat/FileMessage.qml | 7 ++- .../modules/Linphone/Chat/OutgoingMessage.qml | 7 ++- 4 files changed, 41 insertions(+), 31 deletions(-) diff --git a/tests/src/components/chat/ChatModel.cpp b/tests/src/components/chat/ChatModel.cpp index 406f1f89d..e2ad7ef38 100644 --- a/tests/src/components/chat/ChatModel.cpp +++ b/tests/src/components/chat/ChatModel.cpp @@ -92,17 +92,9 @@ private: emit m_chat_model->dataChanged(m_chat_model->index(row, 0), m_chat_model->index(row, 0)); } - void onFileTransferRecv ( - const shared_ptr &, - const shared_ptr &, - const shared_ptr & - ) override { - qWarning() << "`onFileTransferRecv` called."; - } - shared_ptr onFileTransferSend ( const shared_ptr &, - const shared_ptr &, + const shared_ptr &content, size_t, size_t ) override { @@ -136,15 +128,9 @@ private: if (it == m_chat_model->m_entries.end()) return; - if (state == linphone::ChatMessageStateFileTransferError) - state = linphone::ChatMessageStateNotDelivered; - else if (state == linphone::ChatMessageStateFileTransferDone) { - if (!message->isOutgoing()) { - createThumbnail(message); - fillThumbnailProperty((*it).first, message); - } - - state = linphone::ChatMessageStateDelivered; + if (state == linphone::ChatMessageStateFileTransferDone && !message->isOutgoing()) { + createThumbnail(message); + fillThumbnailProperty((*it).first, message); } (*it).first["status"] = state; @@ -359,14 +345,17 @@ void ChatModel::resendMessage (int id) { } shared_ptr message = static_pointer_cast(entry.second); - int state = message->getState(); - if (state != linphone::ChatMessageStateNotDelivered && state != linphone::ChatMessageStateFileTransferError) { - qWarning() << QStringLiteral("Unable to resend message: %1. Bad state.").arg(id); - return; - } - message->setListener(m_message_handlers); - m_chat_room->sendChatMessage(message); + switch (message->getState()) { + case MessageStatusFileTransferError: + case MessageStatusNotDelivered: + message->setListener(m_message_handlers); + m_chat_room->sendChatMessage(message); + break; + + default: + qWarning() << QStringLiteral("Unable to resend message: %1. Bad state.").arg(id); + } } void ChatModel::sendFileMessage (const QString &path) { @@ -414,10 +403,16 @@ void ChatModel::downloadFile (int id, const QString &download_path) { return; } - int state = message->getState(); - if (state != linphone::ChatMessageStateDelivered && state != linphone::ChatMessageStateFileTransferDone) { - qWarning() << QStringLiteral("Unable to download file of entry %1. It was not uploaded.").arg(id); - return; + switch (message->getState()) { + case MessageStatusDelivered: + case MessageStatusDeliveredToUser: + case MessageStatusDisplayed: + case MessageStatusFileTransferDone: + break; + + default: + qWarning() << QStringLiteral("Unable to download file of entry %1. It was not uploaded.").arg(id); + return; } message->setFileTransferFilepath( diff --git a/tests/src/components/chat/ChatModel.hpp b/tests/src/components/chat/ChatModel.hpp index c640a82ec..fd3596c07 100644 --- a/tests/src/components/chat/ChatModel.hpp +++ b/tests/src/components/chat/ChatModel.hpp @@ -41,6 +41,11 @@ public: enum MessageStatus { MessageStatusDelivered = linphone::ChatMessageStateDelivered, + MessageStatusDeliveredToUser = linphone::ChatMessageStateDeliveredToUser, + MessageStatusDisplayed = linphone::ChatMessageStateDisplayed, + MessageStatusFileTransferDone = linphone::ChatMessageStateFileTransferDone, + MessageStatusFileTransferError = linphone::ChatMessageStateFileTransferError, + MessageStatusIdle = linphone::ChatMessageStateIdle, MessageStatusInProgress = linphone::ChatMessageStateInProgress, MessageStatusNotDelivered = linphone::ChatMessageStateNotDelivered }; diff --git a/tests/ui/modules/Linphone/Chat/FileMessage.qml b/tests/ui/modules/Linphone/Chat/FileMessage.qml index 7b7609b59..7204e77fa 100644 --- a/tests/ui/modules/Linphone/Chat/FileMessage.qml +++ b/tests/ui/modules/Linphone/Chat/FileMessage.qml @@ -48,7 +48,12 @@ Row { Rectangle { id: rectangle - readonly property bool isNotDelivered: $chatEntry.status === ChatModel.MessageStatusNotDelivered + readonly property bool isNotDelivered: Utils.includes([ + ChatModel.MessageStatusFileTransferError, + ChatModel.MessageStatusIdle, + ChatModel.MessageStatusInProgress, + ChatModel.MessageStatusNotDelivered + ], $chatEntry.status) color: $chatEntry.isOutgoing ? ChatStyle.entry.message.outgoing.backgroundColor diff --git a/tests/ui/modules/Linphone/Chat/OutgoingMessage.qml b/tests/ui/modules/Linphone/Chat/OutgoingMessage.qml index 52b48d7c5..2c60359e9 100644 --- a/tests/ui/modules/Linphone/Chat/OutgoingMessage.qml +++ b/tests/ui/modules/Linphone/Chat/OutgoingMessage.qml @@ -32,7 +32,12 @@ Item { id: icon Icon { - property bool isNotDelivered: $chatEntry.status === ChatModel.MessageStatusNotDelivered + property bool isNotDelivered: Utils.includes([ + ChatModel.MessageStatusFileTransferError, + ChatModel.MessageStatusIdle, + ChatModel.MessageStatusInProgress, + ChatModel.MessageStatusNotDelivered + ], $chatEntry.status) icon: isNotDelivered ? 'chat_error' : 'chat_send' iconSize: ChatStyle.entry.message.outgoing.sendIconSize