Handle server echo that is received before a message send is completed
This commit is contained in:
parent
16ebc0bb73
commit
1c6470ea03
@ -125,10 +125,10 @@ private:
|
|||||||
// sender's name.
|
// sender's name.
|
||||||
bool isSenderRendered(const QString &user_id, TimelineDirection direction);
|
bool isSenderRendered(const QString &user_id, TimelineDirection direction);
|
||||||
|
|
||||||
bool isPendingMessage(const QString &eventid,
|
bool isPendingMessage(const QString &txnid,
|
||||||
const QString &sender,
|
const QString &sender,
|
||||||
const QString &userid);
|
const QString &userid);
|
||||||
void removePendingMessage(const QString &eventid);
|
void removePendingMessage(const QString &txnid);
|
||||||
|
|
||||||
bool isDuplicate(const QString &event_id) { return eventIds_.contains(event_id); };
|
bool isDuplicate(const QString &event_id) { return eventIds_.contains(event_id); };
|
||||||
|
|
||||||
|
@ -246,8 +246,9 @@ TimelineView::parseMessageEvent(const QJsonObject &event, TimelineDirection dire
|
|||||||
|
|
||||||
eventIds_[text.eventId()] = true;
|
eventIds_[text.eventId()] = true;
|
||||||
|
|
||||||
if (isPendingMessage(text.eventId(), text.sender(), local_user_)) {
|
QString txnid = text.unsignedData().transactionId();
|
||||||
removePendingMessage(text.eventId());
|
if (!txnid.isEmpty() && isPendingMessage(txnid, text.sender(), local_user_)) {
|
||||||
|
removePendingMessage(txnid);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,8 +292,9 @@ TimelineView::parseMessageEvent(const QJsonObject &event, TimelineDirection dire
|
|||||||
|
|
||||||
eventIds_[img.eventId()] = true;
|
eventIds_[img.eventId()] = true;
|
||||||
|
|
||||||
if (isPendingMessage(img.eventId(), img.sender(), local_user_)) {
|
QString txnid = img.unsignedData().transactionId();
|
||||||
removePendingMessage(img.eventId());
|
if (!txnid.isEmpty() && isPendingMessage(txnid, img.sender(), local_user_)) {
|
||||||
|
removePendingMessage(txnid);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,8 +318,9 @@ TimelineView::parseMessageEvent(const QJsonObject &event, TimelineDirection dire
|
|||||||
|
|
||||||
eventIds_[emote.eventId()] = true;
|
eventIds_[emote.eventId()] = true;
|
||||||
|
|
||||||
if (isPendingMessage(emote.eventId(), emote.sender(), local_user_)) {
|
QString txnid = emote.unsignedData().transactionId();
|
||||||
removePendingMessage(emote.eventId());
|
if (!txnid.isEmpty() && isPendingMessage(txnid, emote.sender(), local_user_)) {
|
||||||
|
removePendingMessage(txnid);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -495,10 +498,11 @@ TimelineView::addTimelineItem(TimelineItem *item, TimelineDirection direction)
|
|||||||
void
|
void
|
||||||
TimelineView::updatePendingMessage(int txn_id, QString event_id)
|
TimelineView::updatePendingMessage(int txn_id, QString event_id)
|
||||||
{
|
{
|
||||||
Q_ASSERT(pending_msgs_.head().txn_id == txn_id);
|
if (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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -582,7 +586,7 @@ TimelineView::notifyForLastEvent()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
TimelineView::isPendingMessage(const QString &eventid,
|
TimelineView::isPendingMessage(const QString &txnid,
|
||||||
const QString &sender,
|
const QString &sender,
|
||||||
const QString &local_userid)
|
const QString &local_userid)
|
||||||
{
|
{
|
||||||
@ -590,12 +594,12 @@ TimelineView::isPendingMessage(const QString &eventid,
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (const auto &msg : pending_msgs_) {
|
for (const auto &msg : pending_msgs_) {
|
||||||
if (msg.event_id == eventid)
|
if (QString::number(msg.txn_id) == txnid)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &msg : pending_sent_msgs_) {
|
for (const auto &msg : pending_sent_msgs_) {
|
||||||
if (msg.event_id == eventid)
|
if (QString::number(msg.txn_id) == txnid)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -603,13 +607,20 @@ TimelineView::isPendingMessage(const QString &eventid,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TimelineView::removePendingMessage(const QString &eventid)
|
TimelineView::removePendingMessage(const QString &txnid)
|
||||||
{
|
{
|
||||||
for (auto it = pending_sent_msgs_.begin(); it != pending_sent_msgs_.end(); ++it) {
|
for (auto it = pending_sent_msgs_.begin(); it != pending_sent_msgs_.end(); ++it) {
|
||||||
if (it->event_id == eventid) {
|
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);
|
||||||
break;
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (auto it = pending_msgs_.begin(); it != pending_msgs_.end(); ++it) {
|
||||||
|
if (QString::number(it->txn_id) == txnid) {
|
||||||
|
int index = std::distance(pending_msgs_.begin(), it);
|
||||||
|
pending_msgs_.removeAt(index);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -617,6 +628,7 @@ TimelineView::removePendingMessage(const QString &eventid)
|
|||||||
void
|
void
|
||||||
TimelineView::handleFailedMessage(int txnid)
|
TimelineView::handleFailedMessage(int txnid)
|
||||||
{
|
{
|
||||||
Q_ASSERT(pending_msgs_.head().txn_id == txnid);
|
// Note: We do this even if the message has already been echoed.
|
||||||
|
(void)txnid; // We don't need it.
|
||||||
QTimer::singleShot(500, this, SLOT(sendNextPendingMessage()));
|
QTimer::singleShot(500, this, SLOT(sendNextPendingMessage()));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user