diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index c6d861908..d3c47a197 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -832,8 +832,8 @@ QString ChatForm::secondsToDHMS(quint32 duration) void ChatForm::registerReceipt(int receipt, int messageID, MessageActionPtr msg) { - receipts[receipt] = {messageID, msg}; - undeliveredIDs.insert(messageID); + receipts[receipt] = messageID; + undeliveredMsgs[messageID] = msg; qDebug() << "linking: rec" << receipt << "with" << messageID; } @@ -842,13 +842,15 @@ void ChatForm::dischargeReceipt(int receipt) auto it = receipts.find(receipt); if (it != receipts.end()) { - int mID = it.value().first; - if (undeliveredIDs.remove(mID)) + int mID = it.value(); + auto msgIt = undeliveredMsgs.find(mID); + if (msgIt != undeliveredMsgs.end()) { HistoryKeeper::getInstance()->markAsSent(mID); + msgIt.value()->markAsSent(); + msgIt.value()->featureUpdate(); + undeliveredMsgs.erase(msgIt); } - it.value().second->markAsSent(); - it.value().second->featureUpdate(); receipts.erase(it); qDebug() << "receipt" << receipt << "delivered"; } @@ -857,5 +859,5 @@ void ChatForm::dischargeReceipt(int receipt) void ChatForm::clearReciepts() { receipts.clear(); - undeliveredIDs.clear(); + undeliveredMsgs.clear(); } diff --git a/src/widget/form/chatform.h b/src/widget/form/chatform.h index 40f2ea8a1..315a922d4 100644 --- a/src/widget/form/chatform.h +++ b/src/widget/form/chatform.h @@ -104,8 +104,8 @@ private: void startCounter(); void stopCounter(); QString secondsToDHMS(quint32 duration); - QHash> receipts; - QSet undeliveredIDs; + QHash receipts; + QHash undeliveredMsgs; }; #endif // CHATFORM_H diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index d302c211b..8610c96aa 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -201,7 +201,8 @@ void GenericChatForm::onSaveLogClicked() */ void GenericChatForm::addMessage(const QString& author, const QString &message, bool isAction, const QDateTime &datetime) { - ChatActionPtr ca = genMessageActionAction(author, message, isAction, datetime); + MessageActionPtr ca = genMessageActionAction(author, message, isAction, datetime); + ca->markAsSent(); chatWidget->insertMessage(ca); } @@ -230,7 +231,9 @@ MessageActionPtr GenericChatForm::addSelfMessage(const QString &message, bool is void GenericChatForm::addAlertMessage(const QString& author, QString message, QDateTime datetime) { QString date = datetime.toString(Settings::getInstance().getTimestampFormat()); - chatWidget->insertMessage(ChatActionPtr(new AlertAction(author, message, date))); + AlertAction *alact = new AlertAction(author, message, date); + alact->markAsSent(); + chatWidget->insertMessage(ChatActionPtr(alact)); previousId.publicKey = author; } @@ -307,7 +310,8 @@ void GenericChatForm::clearChatArea(bool notinform) /** * @deprecated The only reason it's still alive is because the groupchat API is a bit limited */ -ChatActionPtr GenericChatForm::genMessageActionAction(const QString &author, QString message, bool isAction, const QDateTime &datetime) +MessageActionPtr GenericChatForm::genMessageActionAction(const QString &author, QString message, bool isAction, + const QDateTime &datetime) { if (earliestMessage == nullptr) { @@ -326,14 +330,14 @@ ChatActionPtr GenericChatForm::genMessageActionAction(const QString &author, QSt if (isAction) { previousId = ToxID(); // next msg has a name regardless - return ChatActionPtr(new ActionAction (getElidedName(author), message, date, isMe)); + return MessageActionPtr(new ActionAction (getElidedName(author), message, date, isMe)); } - ChatActionPtr res; + MessageActionPtr res; if (previousId.publicKey == author) - res = ChatActionPtr(new MessageAction(QString(), message, date, isMe)); + res = MessageActionPtr(new MessageAction(QString(), message, date, isMe)); else - res = ChatActionPtr(new MessageAction(getElidedName(author), message, date, isMe)); + res = MessageActionPtr(new MessageAction(getElidedName(author), message, date, isMe)); previousId.publicKey = author; return res; diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index fa9ab355d..833aab106 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -73,7 +73,7 @@ protected slots: protected: QString getElidedName(const QString& name); - ChatActionPtr genMessageActionAction(const QString& author, QString message, bool isAction, const QDateTime &datetime); ///< Deprecated + MessageActionPtr genMessageActionAction(const QString& author, QString message, bool isAction, const QDateTime &datetime); ///< Deprecated MessageActionPtr genMessageActionAction(const ToxID& author, QString message, bool isAction, const QDateTime &datetime); MessageActionPtr genSelfActionAction(QString message, bool isAction, const QDateTime &datetime); ChatActionPtr genSystemInfoAction(const QString &message, const QString &type, const QDateTime &datetime);