diff --git a/src/historykeeper.cpp b/src/historykeeper.cpp index e39aed3bf..acd5d297d 100644 --- a/src/historykeeper.cpp +++ b/src/historykeeper.cpp @@ -120,15 +120,14 @@ HistoryKeeper::~HistoryKeeper() delete db; } -int HistoryKeeper::addChatEntry(const QString& chat, const QString& message, const QString& sender, const QDateTime &dt) +int HistoryKeeper::addChatEntry(const QString& chat, const QString& message, const QString& sender, const QDateTime &dt, bool isSent) { int chat_id = getChatID(chat, ctSingle).first; int sender_id = getAliasID(sender); - bool status = sender != Core::getInstance()->getSelfId().publicKey; db->exec(QString("INSERT INTO history (timestamp, chat_id, sender, sent_ok, message)") + QString("VALUES (%1, %2, %3, %4, '%5');") - .arg(dt.toMSecsSinceEpoch()).arg(chat_id).arg(sender_id).arg(status).arg(wrapMessage(message))); + .arg(dt.toMSecsSinceEpoch()).arg(chat_id).arg(sender_id).arg(isSent).arg(wrapMessage(message))); messageID++; return messageID; diff --git a/src/historykeeper.h b/src/historykeeper.h index 55f0810e4..e2d1b8b02 100644 --- a/src/historykeeper.h +++ b/src/historykeeper.h @@ -46,7 +46,7 @@ public: static bool checkPassword(); static void renameHistory(QString from, QString to); - int addChatEntry(const QString& chat, const QString& message, const QString& sender, const QDateTime &dt); + int addChatEntry(const QString& chat, const QString& message, const QString& sender, const QDateTime &dt, bool isSent); int addGroupChatEntry(const QString& chat, const QString& message, const QString& sender, const QDateTime &dt); QList getChatHistory(ChatType ct, const QString &chat, const QDateTime &time_from, const QDateTime &time_to); void markAsSent(int m_id); diff --git a/src/misc/settings.cpp b/src/misc/settings.cpp index caa2493dd..887e3b5fd 100644 --- a/src/misc/settings.cpp +++ b/src/misc/settings.cpp @@ -121,6 +121,7 @@ void Settings::load() autoAwayTime = s.value("autoAwayTime", 10).toInt(); checkUpdates = s.value("checkUpdates", false).toBool(); showInFront = s.value("showInFront", false).toBool(); + fauxOfflineMessaging = s.value("fauxOfflineMessaging", false).toBool(); s.endGroup(); s.beginGroup("Widgets"); @@ -259,6 +260,7 @@ void Settings::save(QString path) s.setValue("autoAwayTime", autoAwayTime); s.setValue("checkUpdates", checkUpdates); s.setValue("showInFront", showInFront); + s.setValue("fauxOfflineMessaging", fauxOfflineMessaging); s.endGroup(); s.beginGroup("Widgets"); @@ -849,3 +851,13 @@ void Settings::setFriendAlias(const ToxID &id, const QString &alias) it->alias = alias; } } + +bool Settings::getFauxOfflineMessaging() const +{ + return fauxOfflineMessaging; +} + +void Settings::setFauxOfflineMessaging(bool value) +{ + fauxOfflineMessaging = value; +} diff --git a/src/misc/settings.h b/src/misc/settings.h index 15131e34a..36143de26 100644 --- a/src/misc/settings.h +++ b/src/misc/settings.h @@ -199,6 +199,9 @@ public: QString getFriendAlias(const ToxID &id) const; void setFriendAlias(const ToxID &id, const QString &alias); + bool getFauxOfflineMessaging() const; + void setFauxOfflineMessaging(bool value); + public: void save(); void save(QString path); @@ -218,6 +221,7 @@ private: int dhtServerId; bool dontShowDhtDialog; + bool fauxOfflineMessaging; bool enableIPv6; QString translation; static bool makeToxPortable; @@ -281,6 +285,7 @@ private: QHash friendLst; + signals: //void dataChanged(); void dhtServerListChanged(); diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index ab4d1860b..9850e4c36 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -77,6 +77,7 @@ ChatForm::ChatForm(Friend* chatFriend) connect(volButton, SIGNAL(clicked()), this, SLOT(onVolMuteToggle())); connect(chatWidget, &ChatAreaWidget::onFileTranfertInterract, this, &ChatForm::onFileTansBtnClicked); connect(Core::getInstance(), &Core::fileSendFailed, this, &ChatForm::onFileSendFailed); + connect(this, SIGNAL(chatAreaCleared()), this, SLOT(clearReciepts())); setAcceptDrops(true); @@ -115,10 +116,10 @@ void ChatForm::onSendTriggered() if (isAction) qt_msg_hist = "/me " + qt_msg; - int id = HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, qt_msg_hist, - Core::getInstance()->getSelfId().publicKey, timestamp); + bool status = !Settings::getInstance().getFauxOfflineMessaging(); - qDebug() << "db id:" << id; + int id = HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, qt_msg_hist, + Core::getInstance()->getSelfId().publicKey, timestamp, status); MessageActionPtr ma = addSelfMessage(msg, isAction, timestamp, false); @@ -128,7 +129,6 @@ void ChatForm::onSendTriggered() else rec = Core::getInstance()->sendMessage(f->getFriendID(), msg); - qDebug() << "receipt:" << rec; registerReceipt(rec, id, ma); } @@ -846,7 +846,6 @@ void ChatForm::registerReceipt(int receipt, int messageID, MessageActionPtr msg) { receipts[receipt] = messageID; undeliveredMsgs[messageID] = msg; - qDebug() << "linking: rec" << receipt << "with" << messageID; } void ChatForm::dischargeReceipt(int receipt) @@ -864,7 +863,6 @@ void ChatForm::dischargeReceipt(int receipt) undeliveredMsgs.erase(msgIt); } receipts.erase(it); - qDebug() << "receipt" << receipt << "delivered"; } } @@ -876,6 +874,9 @@ void ChatForm::clearReciepts() void ChatForm::deliverOfflineMsgs() { + if (!Settings::getInstance().getFauxOfflineMessaging()) + return; + QMap msgs = undeliveredMsgs; clearReciepts(); diff --git a/src/widget/form/chatform.h b/src/widget/form/chatform.h index b64793663..2a051f84e 100644 --- a/src/widget/form/chatform.h +++ b/src/widget/form/chatform.h @@ -38,7 +38,6 @@ public: void setStatusMessage(QString newMessage); void dischargeReceipt(int receipt); - void clearReciepts(); signals: void sendFile(int32_t friendId, QString, QString, long long); @@ -52,6 +51,7 @@ signals: public slots: void deliverOfflineMsgs(); + void clearReciepts(); void startFileSend(ToxFile file); void onFileRecvRequest(ToxFile file); void onAvInvite(int FriendId, int CallId, bool video); diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 8610c96aa..ffe6f8ecb 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -305,6 +305,8 @@ void GenericChatForm::clearChatArea(bool notinform) delete earliestMessage; earliestMessage = nullptr; } + + emit chatAreaCleared(); } /** diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index 833aab106..ddd451ca7 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -60,6 +60,7 @@ public: signals: void sendMessage(int, QString); void sendAction(int, QString); + void chatAreaCleared(); public slots: void focusInput(); diff --git a/src/widget/form/settings/generalform.cpp b/src/widget/form/settings/generalform.cpp index 3785f8afc..496dccc9f 100644 --- a/src/widget/form/settings/generalform.cpp +++ b/src/widget/form/settings/generalform.cpp @@ -59,6 +59,7 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) : bodyUI->autoacceptFiles->setChecked(Settings::getInstance().getAutoSaveEnabled()); bodyUI->autoSaveFilesDir->setText(Settings::getInstance().getGlobalAutoAcceptDir()); bodyUI->showInFront->setChecked(Settings::getInstance().getShowInFront()); + bodyUI->cbFauxOfflineMessaging->setChecked(Settings::getInstance().getFauxOfflineMessaging()); for (auto entry : SmileyPack::listSmileyPacks()) { @@ -125,6 +126,7 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) : connect(bodyUI->proxyAddr, &QLineEdit::editingFinished, this, &GeneralForm::onProxyAddrEdited); connect(bodyUI->proxyPort, SIGNAL(valueChanged(int)), this, SLOT(onProxyPortEdited(int))); connect(bodyUI->reconnectButton, &QPushButton::clicked, this, &GeneralForm::onReconnectClicked); + connect(bodyUI->cbFauxOfflineMessaging, &QCheckBox::stateChanged, this, &GeneralForm::onFauxOfflineMessaging); } GeneralForm::~GeneralForm() @@ -300,3 +302,7 @@ void GeneralForm::onSetShowInFront() Settings::getInstance().setShowInFront(bodyUI->showInFront->isChecked()); } +void GeneralForm::onFauxOfflineMessaging() +{ + Settings::getInstance().setFauxOfflineMessaging(bodyUI->cbFauxOfflineMessaging->isChecked()); +} diff --git a/src/widget/form/settings/generalform.h b/src/widget/form/settings/generalform.h index 29e818bde..493cdd499 100644 --- a/src/widget/form/settings/generalform.h +++ b/src/widget/form/settings/generalform.h @@ -53,6 +53,7 @@ private slots: void onAutoSaveDirChange(); void onCheckUpdateChanged(); void onSetShowInFront(); + void onFauxOfflineMessaging(); private: Ui::GeneralSettings *bodyUI; diff --git a/src/widget/form/settings/generalsettings.ui b/src/widget/form/settings/generalsettings.ui index c41631c5b..19a18c8cd 100644 --- a/src/widget/form/settings/generalsettings.ui +++ b/src/widget/form/settings/generalsettings.ui @@ -40,7 +40,7 @@ 0 0 511 - 796 + 698 @@ -97,41 +97,41 @@ - - Start in tray - 0 0 + + Start in tray + - - Close to tray - 0 0 + + Close to tray + - - Minimize to tray - 0 0 + + Minimize to tray + @@ -157,6 +157,13 @@ + + + + Faux offline messaging + + + diff --git a/src/widget/form/settings/privacyform.cpp b/src/widget/form/settings/privacyform.cpp index 80748a084..8345f0299 100644 --- a/src/widget/form/settings/privacyform.cpp +++ b/src/widget/form/settings/privacyform.cpp @@ -52,6 +52,7 @@ void PrivacyForm::onEnableLoggingUpdated() Settings::getInstance().setEnableLogging(bodyUI->cbKeepHistory->isChecked()); bodyUI->cbEncryptHistory->setEnabled(bodyUI->cbKeepHistory->isChecked()); HistoryKeeper::getInstance()->resetInstance(); + Widget::getInstance()->clearAllReceipts(); } void PrivacyForm::onTypingNotificationEnabledUpdated() diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 1b0325319..cb60a1491 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -746,9 +746,9 @@ void Widget::onFriendMessageReceived(int friendId, const QString& message, bool f->getChatForm()->addMessage(f->getToxID(), message, isAction, timestamp, true); if (isAction) - HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, "/me " + message, f->getToxID().publicKey, timestamp); + HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, "/me " + message, f->getToxID().publicKey, timestamp, true); else - HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, message, f->getToxID().publicKey, timestamp); + HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, message, f->getToxID().publicKey, timestamp, true); if (activeChatroomWidget != nullptr) { @@ -773,7 +773,6 @@ void Widget::onReceiptRecieved(int friendId, int receipt) if (!f) return; - qDebug() << "Receipt Recieved" << friendId << "receipt" << receipt; f->getChatForm()->dischargeReceipt(receipt); } @@ -1143,3 +1142,12 @@ bool Widget::askMsgboxQuestion(const QString& title, const QString& msg) return QMessageBox::question(this, title, msg) == QMessageBox::StandardButton::Yes; } } + +void Widget::clearAllReceipts() +{ + QList frnds = FriendList::getAllFriends(); + for (Friend *f : frnds) + { + f->getChatForm()->clearReciepts(); + } +} diff --git a/src/widget/widget.h b/src/widget/widget.h index 9c9a92733..9a45277da 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -73,6 +73,7 @@ public: virtual void closeEvent(QCloseEvent *event); virtual void changeEvent(QEvent *event); + void clearAllReceipts(); public slots: void onSettingsClicked();