diff --git a/src/api/contactmodel.h b/src/api/contactmodel.h index de5f8c37b06bc43043219a65a18d8b7f0673c922..987e3374f9255ee055f77bb4c3cca000f92ebe03 100644 --- a/src/api/contactmodel.h +++ b/src/api/contactmodel.h @@ -86,6 +86,11 @@ public: */ const contact::Info getContact(const QString& contactUri) const; ContactInfoMap getSearchResults() const; + + /** + * Retrieve when a contact is added + */ + time_t getAddedTs(const QString& contactUri) const; /** * get list of banned contacts. * @return list of banned contacts uris as string diff --git a/src/authority/storagehelper.cpp b/src/authority/storagehelper.cpp index 0ca2a5c1e19b564c88eacca74d85718067986446..3660d5f3b72c084f51ce87084f935c8ec548d8e7 100644 --- a/src/authority/storagehelper.cpp +++ b/src/authority/storagehelper.cpp @@ -357,7 +357,10 @@ getConversationsBetween(Database& db, const QString& peer1_uri, const QString& p } QString -beginConversationWithPeer(Database& db, const QString& peer_uri, const bool isOutgoing) +beginConversationWithPeer(Database& db, + const QString& peer_uri, + const bool isOutgoing, + time_t timestamp) { // Add conversation between account and profile auto newConversationsId = db.select("IFNULL(MAX(id), 0) + 1", "conversations", "1=1", {}) @@ -367,7 +370,7 @@ beginConversationWithPeer(Database& db, const QString& peer_uri, const bool isOu {{":id", newConversationsId}, {":participant", peer_uri}}); api::interaction::Info msg {isOutgoing ? "" : peer_uri, {}, - std::time(nullptr), + timestamp ? timestamp : std::time(nullptr), 0, api::interaction::Type::CONTACT, isOutgoing ? api::interaction::Status::SUCCESS diff --git a/src/authority/storagehelper.h b/src/authority/storagehelper.h index 8c70ecae72f7c3ffe5df19365ccb10d79fccf8e4..bf92431eb5304e8f334e51a7db92637fd2b5aaa1 100644 --- a/src/authority/storagehelper.h +++ b/src/authority/storagehelper.h @@ -172,11 +172,13 @@ VectorString getConversationsBetween(Database& db, * @param db * @param peer_uri the URI of the peer * @param isOutgoing + * @param timestamp * @return conversation_id of the new conversation. */ QString beginConversationWithPeer(Database& db, const QString& peer_uri, - const bool isOutgoing = true); + const bool isOutgoing = true, + time_t timestamp = 0); /** * Return interactions from a conversation diff --git a/src/contactmodel.cpp b/src/contactmodel.cpp index 1dee9092b80c48f1adbac50f48ebaf8c8e93d857..26666d32b01589b4eb59815884414a571a386325 100644 --- a/src/contactmodel.cpp +++ b/src/contactmodel.cpp @@ -234,6 +234,17 @@ ContactModel::getAllContacts() const return pimpl_->contacts; } +time_t +ContactModel::getAddedTs(const QString& contactUri) const +{ + MapStringString details = ConfigurationManager::instance().getContactDetails(owner.id, + contactUri); + auto itAdded = details.find("added"); + if (itAdded == details.end()) + return 0; + return itAdded.value().toUInt(); +} + void ContactModel::addContact(contact::Info contactInfo) { diff --git a/src/conversationmodel.cpp b/src/conversationmodel.cpp index 62f9033d5778f37a52417b9a846aebcfa8135516..ea3e100db51e243faeeac9a363ccc547aaeb724f 100644 --- a/src/conversationmodel.cpp +++ b/src/conversationmodel.cpp @@ -1932,7 +1932,11 @@ ConversationModelPimpl::initConversations() addContactRequest(c.second.profileInfo.uri); continue; } - conv.push_back(storage::beginConversationWithPeer(db, c.second.profileInfo.uri)); + conv.push_back(storage::beginConversationWithPeer(db, + c.second.profileInfo.uri, + true, + linked.owner.contactModel->getAddedTs( + c.second.profileInfo.uri))); } addConversationWith(conv[0], c.first, isRequest); @@ -2570,7 +2574,11 @@ ConversationModelPimpl::slotContactAdded(const QString& contactUri) */ addConversation = true; if (conv.empty()) { - conv.push_back(storage::beginConversationWithPeer(db, contactUri)); + conv.push_back(storage::beginConversationWithPeer(db, + contactUri, + true, + linked.owner.contactModel->getAddedTs( + contactUri))); } } if (addConversation) {