fix(src/components/chat/ChatModel): avoid the duplication of message on resend

This commit is contained in:
Ronan Abhamon 2017-01-17 16:43:42 +01:00
parent 9dcc33759c
commit 490ff80135
2 changed files with 19 additions and 9 deletions

@ -1 +1 @@
Subproject commit c0048ed884a411dc29f92daf7bf4c6941074675a
Subproject commit 030b1c05d5d77dac2d34a1be1c98516a8fb9887a

View file

@ -251,7 +251,7 @@ void ChatModel::setSipAddress (const QString &sip_address) {
// TODO: Remove me in a future linphone core version.
if (message->getState() == linphone::ChatMessageStateInProgress)
map["status"] = linphone::ChatMessageStateDelivered;
map["status"] = linphone::ChatMessageStateNotDelivered;
m_entries << qMakePair(map, static_pointer_cast<void>(message));
}
@ -344,19 +344,29 @@ void ChatModel::resendMessage (int id) {
}
const ChatEntryData &entry = m_entries[id];
if (entry.first["type"] != EntryType::MessageEntry) {
const QVariantMap &map = entry.first;
if (map["type"] != EntryType::MessageEntry) {
qWarning() << QStringLiteral("Unable to resend entry %1. It's not a message.").arg(id);
return;
}
shared_ptr<linphone::ChatMessage> message = static_pointer_cast<linphone::ChatMessage>(entry.second);
switch (message->getState()) {
switch (map["status"].toInt()) {
case MessageStatusFileTransferError:
case MessageStatusNotDelivered:
message->setListener(m_message_handlers);
m_chat_room->sendChatMessage(message);
case MessageStatusNotDelivered: {
shared_ptr<linphone::ChatMessage> message = static_pointer_cast<linphone::ChatMessage>(entry.second);
// TODO: Remove workaround in a future linphone core version.
// `sendChatMessage` duplicates the message on resend.
shared_ptr<linphone::ChatMessage> message2 = message->clone();
message2->setListener(m_message_handlers);
m_chat_room->sendChatMessage(message2);
removeEntry(id);
insertMessageAtEnd(message2);
break;
}
default:
qWarning() << QStringLiteral("Unable to resend message: %1. Bad state.").arg(id);