mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Prevent queue from getting blocked (#142)
Try sending a message when all the sent messages have been received through /sync.
This commit is contained in:
parent
65a2743bf1
commit
c1d0bbaf0b
2 changed files with 9 additions and 4 deletions
|
@ -300,7 +300,6 @@ MatrixClient::sendRoomMessage(mtx::events::MessageType ty,
|
||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||||
|
|
||||||
if (status == 0 || status >= 400) {
|
if (status == 0 || status >= 400) {
|
||||||
qWarning() << reply->errorString();
|
|
||||||
emit messageSendFailed(roomid, txnId);
|
emit messageSendFailed(roomid, txnId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -372,11 +372,13 @@ TimelineView::addTimelineItem(TimelineItem *item, TimelineDirection direction)
|
||||||
void
|
void
|
||||||
TimelineView::updatePendingMessage(int txn_id, QString event_id)
|
TimelineView::updatePendingMessage(int txn_id, QString event_id)
|
||||||
{
|
{
|
||||||
if (pending_msgs_.head().txn_id == txn_id) { // We haven't received it yet
|
if (!pending_msgs_.isEmpty() &&
|
||||||
|
pending_msgs_.head().txn_id == txn_id) { // We haven't received it yet
|
||||||
auto msg = pending_msgs_.dequeue();
|
auto msg = pending_msgs_.dequeue();
|
||||||
msg.event_id = event_id;
|
msg.event_id = event_id;
|
||||||
pending_sent_msgs_.append(msg);
|
pending_sent_msgs_.append(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendNextPendingMessage();
|
sendNextPendingMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,7 +407,7 @@ void
|
||||||
TimelineView::handleNewUserMessage(PendingMessage msg)
|
TimelineView::handleNewUserMessage(PendingMessage msg)
|
||||||
{
|
{
|
||||||
pending_msgs_.enqueue(msg);
|
pending_msgs_.enqueue(msg);
|
||||||
if (pending_msgs_.size() == 1 && pending_sent_msgs_.size() == 0)
|
if (pending_msgs_.size() == 1 && pending_sent_msgs_.isEmpty())
|
||||||
sendNextPendingMessage();
|
sendNextPendingMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -474,6 +476,10 @@ TimelineView::removePendingMessage(const QString &txnid)
|
||||||
if (QString::number(it->txn_id) == txnid) {
|
if (QString::number(it->txn_id) == txnid) {
|
||||||
int index = std::distance(pending_sent_msgs_.begin(), it);
|
int index = std::distance(pending_sent_msgs_.begin(), it);
|
||||||
pending_sent_msgs_.removeAt(index);
|
pending_sent_msgs_.removeAt(index);
|
||||||
|
|
||||||
|
if (pending_sent_msgs_.isEmpty())
|
||||||
|
sendNextPendingMessage();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -491,7 +497,7 @@ TimelineView::handleFailedMessage(int txnid)
|
||||||
{
|
{
|
||||||
Q_UNUSED(txnid);
|
Q_UNUSED(txnid);
|
||||||
// Note: We do this even if the message has already been echoed.
|
// Note: We do this even if the message has already been echoed.
|
||||||
QTimer::singleShot(500, this, SLOT(sendNextPendingMessage()));
|
QTimer::singleShot(2000, this, SLOT(sendNextPendingMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue