diff --git a/src/api/contactmodel.h b/src/api/contactmodel.h index 8d932a3abfda6f743b937066d640f19c98859648..878eea9a6536e3e56ec56a6f0528c2fd75a17929 100644 --- a/src/api/contactmodel.h +++ b/src/api/contactmodel.h @@ -139,10 +139,14 @@ Q_SIGNALS: /** * Connect this signal to know when a text message arrives for this account * @param accountId + * @param msgId Interaction's id * @param from peer uri * @param payloads content of the message */ - void newAccountMessage(std::string& accountId, std::string& from, std::map<std::string,std::string> payloads) const; + void newAccountMessage(std::string& accountId, + std::string& msgId, + std::string& from, + std::map<std::string,std::string> payloads) const; /** * Connect this signal to know when a file transfer interaction is incoming * @param dringId Daemon's ID for incoming transfer diff --git a/src/callbackshandler.cpp b/src/callbackshandler.cpp index 3d47dafb7f5621eb1b1e30170b455fe718e2a88b..a12a11cd012b67aba85ce5ed23de47c97b326f84 100644 --- a/src/callbackshandler.cpp +++ b/src/callbackshandler.cpp @@ -246,6 +246,7 @@ CallbacksHandler::subscribeToDebugReceived() void CallbacksHandler::slotNewAccountMessage(const QString& accountId, + const QString& msgId, const QString& from, const QMap<QString,QString>& payloads) { @@ -257,8 +258,9 @@ CallbacksHandler::slotNewAccountMessage(const QString& accountId, auto accountId2 = accountId.toStdString(); auto from2 = QString(from).replace("@ring.dht", "").toStdString(); + auto msgId2 = QString(msgId).toStdString(); - emit newAccountMessage(accountId2, from2, stdPayloads); + emit newAccountMessage(accountId2, msgId2, from2, stdPayloads); } void diff --git a/src/callbackshandler.h b/src/callbackshandler.h index 3a2ef5493d15b596aa6589094eea09a89fe14dd3..9b724d76d94ad453c54e87f52711e65158b73dc6 100644 --- a/src/callbackshandler.h +++ b/src/callbackshandler.h @@ -59,10 +59,12 @@ Q_SIGNALS: /** * Connect this signal to get incoming text interaction from the DHT. * @param accountId interaction receiver. - * @param from interaction sender. + * @param msgId interaction's id. + * @param from interaction sender. * @param payloads. */ void newAccountMessage(std::string& accountId, + std::string& msgId, std::string& from, std::map<std::string,std::string> payloads); /** @@ -296,10 +298,12 @@ private Q_SLOTS: /** * Emit newAccountMessage * @param accountId + * @param msgId * @param from * @param payloads of the interaction */ void slotNewAccountMessage(const QString& accountId, + const QString& msgId, const QString& from, const QMap<QString,QString>& payloads); /** diff --git a/src/contactmodel.cpp b/src/contactmodel.cpp index ad59ad79b9535e53eb05b92b563405c953a59972..0e9bb5c846bbb1b08368c6e044a800ec33e553bf 100644 --- a/src/contactmodel.cpp +++ b/src/contactmodel.cpp @@ -166,10 +166,12 @@ public Q_SLOTS: /** * Listen from callbacksHandler for new account interaction and add pending contact if not present * @param accountId + * @param msgId * @param from * @param payloads */ void slotNewAccountMessage(std::string& accountId, + std::string& msgId, std::string& from, std::map<std::string,std::string> payloads); @@ -847,6 +849,7 @@ ContactModelPimpl::slotIncomingCall(const std::string& fromId, const std::string void ContactModelPimpl::slotNewAccountMessage(std::string& accountId, + std::string& msgId, std::string& from, std::map<std::string,std::string> payloads) { @@ -876,7 +879,7 @@ ContactModelPimpl::slotNewAccountMessage(std::string& accountId, if (emitNewTrust) { emit behaviorController.newTrustRequest(linked.owner.id, from); } - emit linked.newAccountMessage(accountId, from, payloads); + emit linked.newAccountMessage(accountId, msgId, from, payloads); } std::string diff --git a/src/conversationmodel.cpp b/src/conversationmodel.cpp index 2035c5468af10a4bfa95ae5e7200b03534332eec..1d0cbea50a57dd0fd1cdfc444843a124b8a35d07 100644 --- a/src/conversationmodel.cpp +++ b/src/conversationmodel.cpp @@ -115,10 +115,11 @@ public: * @param from the author uri * @param body the content of the message * @param timestamp the timestamp of the message + * @return msgId generated (in db) */ - void addIncomingMessage(const std::string& from, - const std::string& body, - const uint64_t& timestamp = 0); + int addIncomingMessage(const std::string& from, + const std::string& body, + const uint64_t& timestamp = 0); /** * Change the status of an interaction. Listen from callbacksHandler * @param accountId, account linked @@ -218,10 +219,12 @@ public Q_SLOTS: /** * Listen from CallbacksHandler for new incoming interactions; * @param accountId + * @param msgId * @param from uri * @param payloads body */ void slotNewAccountMessage(std::string& accountId, + std::string& msgId, std::string& from, std::map<std::string,std::string> payloads); /** @@ -1765,6 +1768,7 @@ ConversationModelPimpl::addOrUpdateCallMessage(const std::string& callId, void ConversationModelPimpl::slotNewAccountMessage(std::string& accountId, + std::string& msgId, std::string& from, std::map<std::string,std::string> payloads) { @@ -1773,7 +1777,8 @@ ConversationModelPimpl::slotNewAccountMessage(std::string& accountId, for (const auto &payload : payloads) { if (payload.first.find("text/plain") != std::string::npos) { - addIncomingMessage(from, payload.second); + auto dbId = addIncomingMessage(from, payload.second); + storage::addDaemonMsgId(db, std::to_string(dbId), msgId); } } } @@ -1801,7 +1806,7 @@ ConversationModelPimpl::slotIncomingCallMessage(const std::string& callId, const } -void +int ConversationModelPimpl::addIncomingMessage(const std::string& from, const std::string& body, const uint64_t& timestamp) @@ -1832,6 +1837,7 @@ ConversationModelPimpl::addIncomingMessage(const std::string& from, emit linked.newInteraction(convIds[0], msgId, msg); sortConversations(); emit linked.modelSorted(); + return msgId; } void diff --git a/src/qtwrapper/configurationmanager_wrap.h b/src/qtwrapper/configurationmanager_wrap.h index 26e61ab5fbccf2b74fd44ced4479e503c7208e0e..f384bed4c6054ca9552268f155074c4e21b8c87d 100644 --- a/src/qtwrapper/configurationmanager_wrap.h +++ b/src/qtwrapper/configurationmanager_wrap.h @@ -141,8 +141,8 @@ public: Q_EMIT this->registeredNameFound(QString(accountId.c_str()), status, QString(address.c_str()), QString(name.c_str())); }), exportable_callback<ConfigurationSignal::IncomingAccountMessage>( - [this] (const std::string& account_id, const std::string& from, const std::map<std::string, std::string>& payloads) { - Q_EMIT this->incomingAccountMessage(QString(account_id.c_str()), QString(from.c_str()), convertMap(payloads)); + [this] (const std::string& account_id, const std::string& msgId, const std::string& from, const std::map<std::string, std::string>& payloads) { + Q_EMIT this->incomingAccountMessage(QString(account_id.c_str()), QString(msgId.c_str()), QString(from.c_str()), convertMap(payloads)); }), exportable_callback<ConfigurationSignal::MediaParametersChanged>( [this] (const std::string& account_id) { @@ -722,7 +722,7 @@ Q_SIGNALS: // SIGNALS void incomingTrustRequest(const QString& accountId, const QString& from, const QByteArray& payload, qulonglong timeStamp); void knownDevicesChanged(const QString& accountId, const MapStringString& devices); void exportOnRingEnded(const QString& accountId, int status, const QString& pin); - void incomingAccountMessage(const QString& accountId, const QString& from, const MapStringString& payloads); + void incomingAccountMessage(const QString& accountId, const QString msgId, const QString& from, const MapStringString& payloads); void mediaParametersChanged(const QString& accountId); void audioDeviceEvent(); void audioMeter(const QString& id, float level);