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

fix(offlinemsg): make faux offline messages purely event based

Since real offline message reliability issue was fixed in PR #4607, now removing all the workarounds that had been added. Offline messages are now sent as soon as we see our friend come online, and at no other time. Fixes 2 minute wait time before attempting to send if message is entered while you or friend is offline, removes 2 minute constant retry timer, removes 250ms delay between seeing friend come online and sending offline messages.
This commit is contained in:
Anthony Bilinski 2018-03-21 13:02:20 -07:00
parent 0170ccd6f7
commit 4951f90964
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
6 changed files with 7 additions and 58 deletions

View File

@ -27,28 +27,12 @@
#include <QTimer> #include <QTimer>
#include <QCoreApplication> #include <QCoreApplication>
/**
* @var static const int OfflineMsgEngine::offlineTimeout
* @brief timeout after which faux offline messages get to be re-sent.
* Originally was 2s, but since that was causing lots of duplicated
* messages on receiving end, make qTox be more lazy about re-sending
* should be 20s.
*/
const int OfflineMsgEngine::offlineTimeout = 20000;
QMutex OfflineMsgEngine::globalMutex;
OfflineMsgEngine::OfflineMsgEngine(Friend* frnd) OfflineMsgEngine::OfflineMsgEngine(Friend* frnd)
: mutex(QMutex::Recursive) : mutex(QMutex::Recursive)
, f(frnd) , f(frnd)
{ {
} }
OfflineMsgEngine::~OfflineMsgEngine()
{
}
void OfflineMsgEngine::dischargeReceipt(int receipt) void OfflineMsgEngine::dischargeReceipt(int receipt)
{ {
QMutexLocker ml(&mutex); QMutexLocker ml(&mutex);
@ -63,8 +47,7 @@ void OfflineMsgEngine::dischargeReceipt(int receipt)
processReceipt(receipt); processReceipt(receipt);
} }
void OfflineMsgEngine::registerReceipt(int receipt, int64_t messageID, ChatMessage::Ptr msg, void OfflineMsgEngine::registerReceipt(int receipt, int64_t messageID, ChatMessage::Ptr msg)
const QDateTime& timestamp)
{ {
QMutexLocker ml(&mutex); QMutexLocker ml(&mutex);
@ -76,7 +59,7 @@ void OfflineMsgEngine::registerReceipt(int receipt, int64_t messageID, ChatMessa
} }
it->rowId = messageID; it->rowId = messageID;
it->bRowValid = true; it->bRowValid = true;
undeliveredMsgs[messageID] = {msg, timestamp, receipt}; undeliveredMsgs[messageID] = {msg, receipt};
processReceipt(receipt); processReceipt(receipt);
} }
@ -100,11 +83,6 @@ void OfflineMsgEngine::deliverOfflineMsgs()
for (auto iter = msgs.begin(); iter != msgs.end(); ++iter) { for (auto iter = msgs.begin(); iter != msgs.end(); ++iter) {
auto val = iter.value(); auto val = iter.value();
auto key = iter.key(); auto key = iter.key();
if (val.timestamp.msecsTo(QDateTime::currentDateTime()) < offlineTimeout) {
registerReceipt(val.receipt, key, val.msg, val.timestamp);
continue;
}
QString messageText = val.msg->toString(); QString messageText = val.msg->toString();
int rec; int rec;
if (val.msg->isAction()) { if (val.msg->isAction()) {

View File

@ -28,22 +28,19 @@
#include <QSet> #include <QSet>
class Friend; class Friend;
class QTimer;
class OfflineMsgEngine : public QObject class OfflineMsgEngine : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit OfflineMsgEngine(Friend*); explicit OfflineMsgEngine(Friend*);
virtual ~OfflineMsgEngine(); virtual ~OfflineMsgEngine() = default;
static QMutex globalMutex;
void dischargeReceipt(int receipt); void dischargeReceipt(int receipt);
void registerReceipt(int receipt, int64_t messageID, ChatMessage::Ptr msg, void registerReceipt(int receipt, int64_t messageID, ChatMessage::Ptr msg);
const QDateTime& timestamp = QDateTime::currentDateTime()); void deliverOfflineMsgs();
public slots: public slots:
void deliverOfflineMsgs();
void removeAllReceipts(); void removeAllReceipts();
void updateTimestamp(int receiptId); void updateTimestamp(int receiptId);
@ -59,7 +56,6 @@ private:
struct MsgPtr struct MsgPtr
{ {
ChatMessage::Ptr msg; ChatMessage::Ptr msg;
QDateTime timestamp;
int receipt; int receipt;
}; };
QMutex mutex; QMutex mutex;

View File

@ -64,7 +64,6 @@
*/ */
static const int CHAT_WIDGET_MIN_HEIGHT = 50; static const int CHAT_WIDGET_MIN_HEIGHT = 50;
static const int DELIVER_OFFLINE_MESSAGES_DELAY = 250;
static const int SCREENSHOT_GRABBER_OPENING_DELAY = 500; static const int SCREENSHOT_GRABBER_OPENING_DELAY = 500;
static const int TYPING_NOTIFICATION_DURATION = 3000; static const int TYPING_NOTIFICATION_DURATION = 3000;
@ -559,7 +558,7 @@ void ChatForm::onFriendStatusChanged(uint32_t friendId, Status status)
// Hide the "is typing" message when a friend goes offline // Hide the "is typing" message when a friend goes offline
setFriendTyping(false); setFriendTyping(false);
} else { } else {
QTimer::singleShot(DELIVER_OFFLINE_MESSAGES_DELAY, this, SLOT(onDeliverOfflineMessages())); offlineEngine->deliverOfflineMsgs();
} }
updateCallButtons(); updateCallButtons();
@ -695,11 +694,6 @@ void ChatForm::clearChatArea(bool notInForm)
offlineEngine->removeAllReceipts(); offlineEngine->removeAllReceipts();
} }
void ChatForm::onDeliverOfflineMessages()
{
offlineEngine->deliverOfflineMsgs();
}
void ChatForm::onLoadChatHistory() void ChatForm::onLoadChatHistory()
{ {
if (sender() == f) { if (sender() == f) {

View File

@ -82,7 +82,6 @@ private slots:
void onAttachClicked() override; void onAttachClicked() override;
void onScreenshotClicked() override; void onScreenshotClicked() override;
void onDeliverOfflineMessages();
void onLoadChatHistory(); void onLoadChatHistory();
void onTextEditChanged(); void onTextEditChanged();
void onCallTriggered(); void onCallTriggered();

View File

@ -112,9 +112,6 @@ void Widget::init()
timer = new QTimer(); timer = new QTimer();
timer->start(1000); timer->start(1000);
offlineMsgTimer = new QTimer();
// FIXME: ↓ make a proper fix instead of increasing timeout into ∞
offlineMsgTimer->start(2 * 60 * 1000);
icon_size = 15; icon_size = 15;
@ -259,7 +256,6 @@ void Widget::init()
connect(timer, &QTimer::timeout, this, &Widget::onUserAwayCheck); connect(timer, &QTimer::timeout, this, &Widget::onUserAwayCheck);
connect(timer, &QTimer::timeout, this, &Widget::onEventIconTick); connect(timer, &QTimer::timeout, this, &Widget::onEventIconTick);
connect(timer, &QTimer::timeout, this, &Widget::onTryCreateTrayIcon); connect(timer, &QTimer::timeout, this, &Widget::onTryCreateTrayIcon);
connect(offlineMsgTimer, &QTimer::timeout, this, &Widget::processOfflineMsgs);
connect(ui->searchContactText, &QLineEdit::textChanged, this, &Widget::searchContacts); connect(ui->searchContactText, &QLineEdit::textChanged, this, &Widget::searchContacts);
connect(filterGroup, &QActionGroup::triggered, this, &Widget::searchContacts); connect(filterGroup, &QActionGroup::triggered, this, &Widget::searchContacts);
connect(filterDisplayGroup, &QActionGroup::triggered, this, &Widget::changeDisplayMode); connect(filterDisplayGroup, &QActionGroup::triggered, this, &Widget::changeDisplayMode);
@ -537,7 +533,6 @@ Widget::~Widget()
delete groupInviteForm; delete groupInviteForm;
delete filesForm; delete filesForm;
delete timer; delete timer;
delete offlineMsgTimer;
delete contentLayout; delete contentLayout;
FriendList::clear(); FriendList::clear();
@ -2180,18 +2175,6 @@ bool Widget::filterOnline(FilterCriteria index)
} }
} }
void Widget::processOfflineMsgs()
{
if (OfflineMsgEngine::globalMutex.tryLock()) {
QList<Friend*> frnds = FriendList::getAllFriends();
for (Friend* f : frnds) {
chatForms[f->getId()]->getOfflineMsgEngine()->deliverOfflineMsgs();
}
OfflineMsgEngine::globalMutex.unlock();
}
}
void Widget::clearAllReceipts() void Widget::clearAllReceipts()
{ {
QList<Friend*> frnds = FriendList::getAllFriends(); QList<Friend*> frnds = FriendList::getAllFriends();

View File

@ -212,7 +212,6 @@ private slots:
void onTryCreateTrayIcon(); void onTryCreateTrayIcon();
void onSetShowSystemTray(bool newValue); void onSetShowSystemTray(bool newValue);
void onSplitterMoved(int pos, int index); void onSplitterMoved(int pos, int index);
void processOfflineMsgs();
void friendListContextMenu(const QPoint& pos); void friendListContextMenu(const QPoint& pos);
void friendRequestsUpdate(); void friendRequestsUpdate();
void groupInvitesUpdate(); void groupInvitesUpdate();
@ -293,7 +292,7 @@ private:
MaskablePixmapWidget* profilePicture; MaskablePixmapWidget* profilePicture;
bool notify(QObject* receiver, QEvent* event); bool notify(QObject* receiver, QEvent* event);
bool autoAwayActive = false; bool autoAwayActive = false;
QTimer *timer, *offlineMsgTimer; QTimer *timer;
QRegExp nameMention, sanitizedNameMention; QRegExp nameMention, sanitizedNameMention;
bool eventFlag; bool eventFlag;
bool eventIcon; bool eventIcon;