From 67e0a4fa4e45f41550bcdee1bbe96c967746a58f Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 12 Jan 2017 13:36:18 +0100 Subject: [PATCH] feat(ui/modules/Linphone/Chat/OutgoingMessage): supports resend action --- tests/src/components/chat/ChatModel.cpp | 22 +++++++++++++++++++ tests/src/components/chat/ChatModel.hpp | 2 ++ tests/src/components/chat/ChatProxyModel.cpp | 7 ++++++ tests/src/components/chat/ChatProxyModel.hpp | 1 + .../modules/Linphone/Chat/OutgoingMessage.qml | 6 +++-- 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/tests/src/components/chat/ChatModel.cpp b/tests/src/components/chat/ChatModel.cpp index f605ca3c3..937778d85 100644 --- a/tests/src/components/chat/ChatModel.cpp +++ b/tests/src/components/chat/ChatModel.cpp @@ -253,6 +253,28 @@ void ChatModel::sendMessage (const QString &message) { emit messageSent(_message); } +void ChatModel::resendMessage (int id) { + if (id < 0 || id > m_entries.count()) { + qWarning() << QStringLiteral("Entry %1 not exists.").arg(id); + return; + } + + const ChatEntryData &entry = m_entries[id]; + if (entry.first["type"] != EntryType::MessageEntry) { + qWarning() << QStringLiteral("Unable to resend entry %1. It's not a message.").arg(id); + return; + } + + shared_ptr message = static_pointer_cast(entry.second); + if (message->getState() != linphone::ChatMessageStateNotDelivered) { + qWarning() << QStringLiteral("Unable to resend message: %1. Bad state.").arg(id); + return; + } + + message->setListener(m_message_handlers); + m_chat_room->sendMessage(message); +} + // ----------------------------------------------------------------------------- void ChatModel::fillMessageEntry ( diff --git a/tests/src/components/chat/ChatModel.hpp b/tests/src/components/chat/ChatModel.hpp index 0ba1d300f..48b5c5c05 100644 --- a/tests/src/components/chat/ChatModel.hpp +++ b/tests/src/components/chat/ChatModel.hpp @@ -68,6 +68,8 @@ public: void sendMessage (const QString &message); + void resendMessage (int id); + signals: void sipAddressChanged (const QString &sip_address); void allEntriesRemoved (); diff --git a/tests/src/components/chat/ChatProxyModel.cpp b/tests/src/components/chat/ChatProxyModel.cpp index 257863c3e..6a901a21f 100644 --- a/tests/src/components/chat/ChatProxyModel.cpp +++ b/tests/src/components/chat/ChatProxyModel.cpp @@ -98,6 +98,13 @@ void ChatProxyModel::sendMessage (const QString &message) { static_cast(m_chat_model_filter->sourceModel())->sendMessage(message); } +void ChatProxyModel::resendMessage (int id) { + QModelIndex source_index = mapToSource(index(id, 0)); + static_cast(m_chat_model_filter->sourceModel())->resendMessage( + m_chat_model_filter->mapToSource(source_index).row() + ); +} + bool ChatProxyModel::filterAcceptsRow (int source_row, const QModelIndex &) const { return m_chat_model_filter->rowCount() - source_row <= m_n_max_displayed_entries; } diff --git a/tests/src/components/chat/ChatProxyModel.hpp b/tests/src/components/chat/ChatProxyModel.hpp index dbee58dd0..01ec056ed 100644 --- a/tests/src/components/chat/ChatProxyModel.hpp +++ b/tests/src/components/chat/ChatProxyModel.hpp @@ -29,6 +29,7 @@ public: Q_INVOKABLE void removeAllEntries (); Q_INVOKABLE void sendMessage (const QString &message); + Q_INVOKABLE void resendMessage (int id); signals: void sipAddressChanged (const QString &sip_address); diff --git a/tests/ui/modules/Linphone/Chat/OutgoingMessage.qml b/tests/ui/modules/Linphone/Chat/OutgoingMessage.qml index b6a8b92e3..ffafa9b09 100644 --- a/tests/ui/modules/Linphone/Chat/OutgoingMessage.qml +++ b/tests/ui/modules/Linphone/Chat/OutgoingMessage.qml @@ -32,12 +32,14 @@ Item { id: icon Icon { - icon: $chatEntry.status === ChatModel.MessageStatusNotDelivered ? 'chat_error' : 'chat_send' + property bool isNotDelivered: $chatEntry.status === ChatModel.MessageStatusNotDelivered + + icon: isNotDelivered ? 'chat_error' : 'chat_send' iconSize: ChatStyle.entry.message.outgoing.sendIconSize MouseArea { anchors.fill: parent - onClicked: console.log('resend') + onClicked: isNotDelivered && proxyModel.resendMessage(index) } } }