This commit is contained in:
Konstantinos Sideris 2017-11-15 18:42:21 +02:00
parent 4e1c8dd663
commit 4166a863b4
4 changed files with 25 additions and 16 deletions

View file

@ -62,7 +62,7 @@ public:
QUrl getHomeServer() { return server_; }; QUrl getHomeServer() { return server_; };
int transactionId() { return txn_id_; }; int transactionId() { return txn_id_; };
int incrementTransactionId() { return ++txn_id_; }; // It is incredibly important that it's incremented first. int incrementTransactionId() { return ++txn_id_; };
void reset() noexcept; void reset() noexcept;

View file

@ -50,7 +50,12 @@ struct PendingMessage
QString event_id; QString event_id;
TimelineItem *widget; TimelineItem *widget;
PendingMessage(matrix::events::MessageEventType ty, int txn_id, QString body, QString filename, QString event_id, TimelineItem *widget) PendingMessage(matrix::events::MessageEventType ty,
int txn_id,
QString body,
QString filename,
QString event_id,
TimelineItem *widget)
: ty(ty) : ty(ty)
, txn_id(txn_id) , txn_id(txn_id)
, body(body) , body(body)
@ -125,9 +130,7 @@ 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 &txnid, bool isPendingMessage(const QString &txnid, const QString &sender, const QString &userid);
const QString &sender,
const QString &userid);
void removePendingMessage(const QString &txnid); 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); };

View file

@ -247,7 +247,8 @@ TimelineView::parseMessageEvent(const QJsonObject &event, TimelineDirection dire
eventIds_[text.eventId()] = true; eventIds_[text.eventId()] = true;
QString txnid = text.unsignedData().transactionId(); QString txnid = text.unsignedData().transactionId();
if (!txnid.isEmpty() && isPendingMessage(txnid, text.sender(), local_user_)) { if (!txnid.isEmpty() &&
isPendingMessage(txnid, text.sender(), local_user_)) {
removePendingMessage(txnid); removePendingMessage(txnid);
return nullptr; return nullptr;
} }
@ -293,7 +294,8 @@ TimelineView::parseMessageEvent(const QJsonObject &event, TimelineDirection dire
eventIds_[img.eventId()] = true; eventIds_[img.eventId()] = true;
QString txnid = img.unsignedData().transactionId(); QString txnid = img.unsignedData().transactionId();
if (!txnid.isEmpty() && isPendingMessage(txnid, img.sender(), local_user_)) { if (!txnid.isEmpty() &&
isPendingMessage(txnid, img.sender(), local_user_)) {
removePendingMessage(txnid); removePendingMessage(txnid);
return nullptr; return nullptr;
} }
@ -319,7 +321,8 @@ TimelineView::parseMessageEvent(const QJsonObject &event, TimelineDirection dire
eventIds_[emote.eventId()] = true; eventIds_[emote.eventId()] = true;
QString txnid = emote.unsignedData().transactionId(); QString txnid = emote.unsignedData().transactionId();
if (!txnid.isEmpty() && isPendingMessage(txnid, emote.sender(), local_user_)) { if (!txnid.isEmpty() &&
isPendingMessage(txnid, emote.sender(), local_user_)) {
removePendingMessage(txnid); removePendingMessage(txnid);
return nullptr; return nullptr;
} }
@ -546,7 +549,8 @@ TimelineView::addUserMessage(const QString &url, const QString &filename)
lastSender_ = user_id; lastSender_ = user_id;
int txn_id = client_->incrementTransactionId(); int txn_id = client_->incrementTransactionId();
PendingMessage message(matrix::events::MessageEventType::Image, txn_id, url, filename, "", view_item); PendingMessage message(
matrix::events::MessageEventType::Image, txn_id, url, filename, "", view_item);
handleNewUserMessage(message); handleNewUserMessage(message);
} }
@ -567,7 +571,8 @@ TimelineView::sendNextPendingMessage()
PendingMessage &m = pending_msgs_.head(); PendingMessage &m = pending_msgs_.head();
switch (m.ty) { switch (m.ty) {
case matrix::events::MessageEventType::Image: case matrix::events::MessageEventType::Image:
client_->sendRoomMessage(m.ty, m.txn_id, room_id_, QFileInfo(m.filename).fileName(), m.body); client_->sendRoomMessage(
m.ty, m.txn_id, room_id_, QFileInfo(m.filename).fileName(), m.body);
break; break;
default: default:
client_->sendRoomMessage(m.ty, m.txn_id, room_id_, m.body); client_->sendRoomMessage(m.ty, m.txn_id, room_id_, m.body);

View file

@ -36,9 +36,10 @@ TimelineViewManager::TimelineViewManager(QSharedPointer<MatrixClient> client, QW
connect( connect(
client_.data(), &MatrixClient::messageSent, this, &TimelineViewManager::messageSent); client_.data(), &MatrixClient::messageSent, this, &TimelineViewManager::messageSent);
connect( connect(client_.data(),
client_.data(), &MatrixClient::messageSendFailed, &MatrixClient::messageSendFailed,
this, &TimelineViewManager::messageSendFailed); this,
&TimelineViewManager::messageSendFailed);
} }
TimelineViewManager::~TimelineViewManager() {} TimelineViewManager::~TimelineViewManager() {}