1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Faux offline messaging: enable/disable

This commit is contained in:
apprb 2014-11-10 22:06:35 +09:00
parent cee1bcc8d1
commit 5d50ea36d0
No known key found for this signature in database
GPG Key ID: B001911B5B22FB9B
14 changed files with 68 additions and 24 deletions

View File

@ -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;

View File

@ -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<HistMessage> getChatHistory(ChatType ct, const QString &chat, const QDateTime &time_from, const QDateTime &time_to);
void markAsSent(int m_id);

View File

@ -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;
}

View File

@ -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<QString, friendProp> friendLst;
signals:
//void dataChanged();
void dhtServerListChanged();

View File

@ -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<int, MessageActionPtr> msgs = undeliveredMsgs;
clearReciepts();

View File

@ -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);

View File

@ -305,6 +305,8 @@ void GenericChatForm::clearChatArea(bool notinform)
delete earliestMessage;
earliestMessage = nullptr;
}
emit chatAreaCleared();
}
/**

View File

@ -60,6 +60,7 @@ public:
signals:
void sendMessage(int, QString);
void sendAction(int, QString);
void chatAreaCleared();
public slots:
void focusInput();

View File

@ -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());
}

View File

@ -53,6 +53,7 @@ private slots:
void onAutoSaveDirChange();
void onCheckUpdateChanged();
void onSetShowInFront();
void onFauxOfflineMessaging();
private:
Ui::GeneralSettings *bodyUI;

View File

@ -40,7 +40,7 @@
<x>0</x>
<y>0</y>
<width>511</width>
<height>796</height>
<height>698</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4" stretch="0,0,1">
@ -97,41 +97,41 @@
<layout class="QHBoxLayout" name="trayLayout">
<item>
<widget class="QCheckBox" name="startInTray">
<property name="text">
<string>Start in tray</string>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Start in tray</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="closeToTray">
<property name="text">
<string>Close to tray</string>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Close to tray</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="minimizeToTray">
<property name="text">
<string>Minimize to tray</string>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Minimize to tray</string>
</property>
</widget>
</item>
</layout>
@ -157,6 +157,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbFauxOfflineMessaging">
<property name="text">
<string>Faux offline messaging</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item alignment="Qt::AlignLeft">

View File

@ -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()

View File

@ -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<Friend*> frnds = FriendList::getAllFriends();
for (Friend *f : frnds)
{
f->getChatForm()->clearReciepts();
}
}

View File

@ -73,6 +73,7 @@ public:
virtual void closeEvent(QCloseEvent *event);
virtual void changeEvent(QEvent *event);
void clearAllReceipts();
public slots:
void onSettingsClicked();