diff --git a/src/api/interaction.h b/src/api/interaction.h index 75e5d1c175ba1c85b5069fe0ccf092682246591e..64e5a924d6c213047aaff27b8b57c01e8688efdf 100644 --- a/src/api/interaction.h +++ b/src/api/interaction.h @@ -32,7 +32,7 @@ namespace interaction { Q_NAMESPACE Q_CLASSINFO("RegisterEnumClassesUnscoped", "false") -enum class Type { INVALID, TEXT, CALL, CONTACT, DATA_TRANSFER, MERGE, COUNT__ }; +enum class Type { INVALID, INITIAL, TEXT, CALL, CONTACT, DATA_TRANSFER, MERGE, COUNT__ }; Q_ENUM_NS(Type) static inline const QString @@ -41,6 +41,8 @@ to_string(const Type& type) switch (type) { case Type::TEXT: return "TEXT"; + case Type::INITIAL: + return "INITIAL"; case Type::CALL: return "CALL"; case Type::CONTACT: @@ -59,7 +61,9 @@ to_string(const Type& type) static inline Type to_type(const QString& type) { - if (type == "TEXT" || type == "text/plain") + if (type == "INITIAL" || type == "initial") + return interaction::Type::INITIAL; + else if (type == "TEXT" || type == "text/plain") return interaction::Type::TEXT; else if (type == "CALL" || type == "application/call-history+json") return interaction::Type::CALL; @@ -286,13 +290,9 @@ struct Info if (type == Type::CONTACT) { authorUri = accountURI == message["uri"] ? "" : message["uri"]; body = getContactInteractionString(authorUri, to_action(message["action"])); - } - if (message["type"] == "initial" && message.find("invited") != message.end()) { - type = Type::CONTACT; - authorUri = accountURI != message["invited"] ? "" : message["invited"]; - body = getContactInteractionString(authorUri, ContactAction::ADD); - } - if (type == Type::CALL) { + } else if (type == Type::INITIAL) { + body = QObject::tr("Swarm created"); + } else if (type == Type::CALL) { duration = message["duration"].toInt() / 1000; } commit = message; diff --git a/src/conversationmodel.cpp b/src/conversationmodel.cpp index 0af17cda194b9b22055a5627f1383ddec6a464d1..ef3ff043b0bcc1daa16180f13f4f3fe2e0748703 100644 --- a/src/conversationmodel.cpp +++ b/src/conversationmodel.cpp @@ -2210,25 +2210,20 @@ ConversationModelPimpl::slotConversationLoaded(uint32_t requestId, return; } + auto allLoaded = false; + try { auto& conversation = getConversationForUid(conversationId).get(); - auto size = messages.size(); - for (int i = size - 1; i >= 0; --i) { - auto message = messages[i]; + for (const auto& message: messages) { if (message["type"].isEmpty() || message["type"] == "application/update-profile") { continue; } - if (message["type"] == "initial") { - conversation.allMessagesLoaded = true; - Q_EMIT linked.conversationUpdated(conversationId); - if (message.find("invited") == message.end()) { - continue; - } - } auto msgId = message["id"]; auto msg = interaction::Info(message, linked.owner.profileInfo.uri); auto downloadFile = false; - if (msg.type == interaction::Type::DATA_TRANSFER) { + if (msg.type == interaction::Type::INITIAL) { + allLoaded = true; + } else if (msg.type == interaction::Type::DATA_TRANSFER) { auto fileId = message["fileId"]; QString path; qlonglong bytesProgress, totalSize; @@ -2284,6 +2279,11 @@ ConversationModelPimpl::slotConversationLoaded(uint32_t requestId, auto conversationIdx = indexOf(conversationId); Q_EMIT linked.dataChanged(conversationIdx); Q_EMIT linked.conversationMessagesLoaded(requestId, conversationId); + + if (allLoaded) { + conversation.allMessagesLoaded = true; + Q_EMIT linked.conversationUpdated(conversationId); + } } catch (const std::exception& e) { qDebug() << "messages loaded for not existing conversation"; } @@ -2392,25 +2392,23 @@ ConversationModelPimpl::insertSwarmInteraction(const QString& interactionId, if (index >= 0) { auto result = conversation.interactions->insert(index + 1, qMakePair(interactionId, interaction)); - if (!result.second) { + if (!result.second) return false; - } } else { auto result = conversation.interactions->insert(std::make_pair(interactionId, interaction), insertAtBegin); - if (!result.second) { + if (!result.second) return false; - } - conversation.parentsId[interactionId] = interaction.parentId; + if (!interaction.parentId.isEmpty()) + conversation.parentsId[interactionId] = interaction.parentId; } if (!conversation.parentsId.values().contains(interactionId)) { return true; } auto msgIds = conversation.parentsId.keys(interactionId); conversation.interactions->moveMessages(msgIds, interactionId); - for (auto& msg : msgIds) { + for (auto& msg : msgIds) conversation.parentsId.remove(msg); - } return true; }