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:
parent
0170ccd6f7
commit
4951f90964
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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()) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
@ -59,7 +56,6 @@ private:
|
|||
struct MsgPtr
|
||||
{
|
||||
ChatMessage::Ptr msg;
|
||||
QDateTime timestamp;
|
||||
int receipt;
|
||||
};
|
||||
QMutex mutex;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -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();
|
||||
|
@ -695,11 +694,6 @@ void ChatForm::clearChatArea(bool notInForm)
|
|||
offlineEngine->removeAllReceipts();
|
||||
}
|
||||
|
||||
void ChatForm::onDeliverOfflineMessages()
|
||||
{
|
||||
offlineEngine->deliverOfflineMsgs();
|
||||
}
|
||||
|
||||
void ChatForm::onLoadChatHistory()
|
||||
{
|
||||
if (sender() == f) {
|
||||
|
|
|
@ -82,7 +82,6 @@ private slots:
|
|||
void onAttachClicked() override;
|
||||
void onScreenshotClicked() override;
|
||||
|
||||
void onDeliverOfflineMessages();
|
||||
void onLoadChatHistory();
|
||||
void onTextEditChanged();
|
||||
void onCallTriggered();
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -537,7 +533,6 @@ Widget::~Widget()
|
|||
delete groupInviteForm;
|
||||
delete filesForm;
|
||||
delete timer;
|
||||
delete offlineMsgTimer;
|
||||
delete contentLayout;
|
||||
|
||||
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()
|
||||
{
|
||||
QList<Friend*> frnds = FriendList::getAllFriends();
|
||||
|
|
|
@ -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();
|
||||
|
@ -293,7 +292,7 @@ private:
|
|||
MaskablePixmapWidget* profilePicture;
|
||||
bool notify(QObject* receiver, QEvent* event);
|
||||
bool autoAwayActive = false;
|
||||
QTimer *timer, *offlineMsgTimer;
|
||||
QTimer *timer;
|
||||
QRegExp nameMention, sanitizedNameMention;
|
||||
bool eventFlag;
|
||||
bool eventIcon;
|
||||
|
|
Loading…
Reference in New Issue
Block a user