Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(offlinemsg): make faux offline messages purely event based
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
anthonybilinski committed Mar 21, 2018
1 parent 0170ccd commit 4951f90
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 58 deletions.
26 changes: 2 additions & 24 deletions src/persistence/offlinemsgengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,12 @@
#include <QTimer>
#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)
: mutex(QMutex::Recursive)
, f(frnd)
{
}

OfflineMsgEngine::~OfflineMsgEngine()
{
}

void OfflineMsgEngine::dischargeReceipt(int receipt)
{
QMutexLocker ml(&mutex);
Expand All @@ -63,8 +47,7 @@ void OfflineMsgEngine::dischargeReceipt(int receipt)
processReceipt(receipt);
}

void OfflineMsgEngine::registerReceipt(int receipt, int64_t messageID, ChatMessage::Ptr msg,
const QDateTime& timestamp)
void OfflineMsgEngine::registerReceipt(int receipt, int64_t messageID, ChatMessage::Ptr msg)
{
QMutexLocker ml(&mutex);

Expand All @@ -76,7 +59,7 @@ void OfflineMsgEngine::registerReceipt(int receipt, int64_t messageID, ChatMessa
}
it->rowId = messageID;
it->bRowValid = true;
undeliveredMsgs[messageID] = {msg, timestamp, receipt};
undeliveredMsgs[messageID] = {msg, receipt};
processReceipt(receipt);
}

Expand All @@ -100,11 +83,6 @@ void OfflineMsgEngine::deliverOfflineMsgs()
for (auto iter = msgs.begin(); iter != msgs.end(); ++iter) {
auto val = iter.value();
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();
int rec;
if (val.msg->isAction()) {
Expand Down
10 changes: 3 additions & 7 deletions src/persistence/offlinemsgengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,19 @@
#include <QSet>

class Friend;
class QTimer;

class OfflineMsgEngine : public QObject
{
Q_OBJECT
public:
explicit OfflineMsgEngine(Friend*);
virtual ~OfflineMsgEngine();
static QMutex globalMutex;
virtual ~OfflineMsgEngine() = default;

void dischargeReceipt(int receipt);
void registerReceipt(int receipt, int64_t messageID, ChatMessage::Ptr msg,
const QDateTime& timestamp = QDateTime::currentDateTime());
void registerReceipt(int receipt, int64_t messageID, ChatMessage::Ptr msg);
void deliverOfflineMsgs();

public slots:
void deliverOfflineMsgs();
void removeAllReceipts();
void updateTimestamp(int receiptId);

Expand All @@ -59,7 +56,6 @@ public slots:
struct MsgPtr
{
ChatMessage::Ptr msg;
QDateTime timestamp;
int receipt;
};
QMutex mutex;
Expand Down
8 changes: 1 addition & 7 deletions src/widget/form/chatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
*/

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 TYPING_NOTIFICATION_DURATION = 3000;

Expand Down Expand Up @@ -559,7 +558,7 @@ void ChatForm::onFriendStatusChanged(uint32_t friendId, Status status)
// Hide the "is typing" message when a friend goes offline
setFriendTyping(false);
} else {
QTimer::singleShot(DELIVER_OFFLINE_MESSAGES_DELAY, this, SLOT(onDeliverOfflineMessages()));
offlineEngine->deliverOfflineMsgs();
}

updateCallButtons();
Expand Down Expand Up @@ -695,11 +694,6 @@ void ChatForm::clearChatArea(bool notInForm)
offlineEngine->removeAllReceipts();
}

void ChatForm::onDeliverOfflineMessages()
{
offlineEngine->deliverOfflineMsgs();
}

void ChatForm::onLoadChatHistory()
{
if (sender() == f) {
Expand Down
1 change: 0 additions & 1 deletion src/widget/form/chatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ private slots:
void onAttachClicked() override;
void onScreenshotClicked() override;

void onDeliverOfflineMessages();
void onLoadChatHistory();
void onTextEditChanged();
void onCallTriggered();
Expand Down
17 changes: 0 additions & 17 deletions src/widget/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ void Widget::init()

timer = new QTimer();
timer->start(1000);
offlineMsgTimer = new QTimer();
// FIXME: ↓ make a proper fix instead of increasing timeout into ∞
offlineMsgTimer->start(2 * 60 * 1000);

icon_size = 15;

Expand Down Expand Up @@ -259,7 +256,6 @@ void Widget::init()
connect(timer, &QTimer::timeout, this, &Widget::onUserAwayCheck);
connect(timer, &QTimer::timeout, this, &Widget::onEventIconTick);
connect(timer, &QTimer::timeout, this, &Widget::onTryCreateTrayIcon);
connect(offlineMsgTimer, &QTimer::timeout, this, &Widget::processOfflineMsgs);
connect(ui->searchContactText, &QLineEdit::textChanged, this, &Widget::searchContacts);
connect(filterGroup, &QActionGroup::triggered, this, &Widget::searchContacts);
connect(filterDisplayGroup, &QActionGroup::triggered, this, &Widget::changeDisplayMode);
Expand Down Expand Up @@ -537,7 +533,6 @@ Widget::~Widget()
delete groupInviteForm;
delete filesForm;
delete timer;
delete offlineMsgTimer;
delete contentLayout;

FriendList::clear();
Expand Down Expand Up @@ -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()
{
QList<Friend*> frnds = FriendList::getAllFriends();
Expand Down
3 changes: 1 addition & 2 deletions src/widget/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ private slots:
void onTryCreateTrayIcon();
void onSetShowSystemTray(bool newValue);
void onSplitterMoved(int pos, int index);
void processOfflineMsgs();
void friendListContextMenu(const QPoint& pos);
void friendRequestsUpdate();
void groupInvitesUpdate();
Expand Down Expand Up @@ -293,7 +292,7 @@ private slots:
MaskablePixmapWidget* profilePicture;
bool notify(QObject* receiver, QEvent* event);
bool autoAwayActive = false;
QTimer *timer, *offlineMsgTimer;
QTimer *timer;
QRegExp nameMention, sanitizedNameMention;
bool eventFlag;
bool eventIcon;
Expand Down

0 comments on commit 4951f90

Please sign in to comment.