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_; };
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;

View file

@ -50,7 +50,12 @@ struct PendingMessage
QString event_id;
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)
, txn_id(txn_id)
, body(body)
@ -125,9 +130,7 @@ private:
// sender's name.
bool isSenderRendered(const QString &user_id, TimelineDirection direction);
bool isPendingMessage(const QString &txnid,
const QString &sender,
const QString &userid);
bool isPendingMessage(const QString &txnid, const QString &sender, const QString &userid);
void removePendingMessage(const QString &txnid);
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;
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);
return nullptr;
}
@ -293,7 +294,8 @@ TimelineView::parseMessageEvent(const QJsonObject &event, TimelineDirection dire
eventIds_[img.eventId()] = true;
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);
return nullptr;
}
@ -319,7 +321,8 @@ TimelineView::parseMessageEvent(const QJsonObject &event, TimelineDirection dire
eventIds_[emote.eventId()] = true;
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);
return nullptr;
}
@ -499,7 +502,7 @@ void
TimelineView::updatePendingMessage(int txn_id, QString event_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;
pending_sent_msgs_.append(msg);
}
@ -546,7 +549,8 @@ TimelineView::addUserMessage(const QString &url, const QString &filename)
lastSender_ = user_id;
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);
}
@ -567,7 +571,8 @@ TimelineView::sendNextPendingMessage()
PendingMessage &m = pending_msgs_.head();
switch (m.ty) {
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;
default:
client_->sendRoomMessage(m.ty, m.txn_id, room_id_, m.body);

View file

@ -36,9 +36,10 @@ TimelineViewManager::TimelineViewManager(QSharedPointer<MatrixClient> client, QW
connect(
client_.data(), &MatrixClient::messageSent, this, &TimelineViewManager::messageSent);
connect(
client_.data(), &MatrixClient::messageSendFailed,
this, &TimelineViewManager::messageSendFailed);
connect(client_.data(),
&MatrixClient::messageSendFailed,
this,
&TimelineViewManager::messageSendFailed);
}
TimelineViewManager::~TimelineViewManager() {}
@ -81,8 +82,8 @@ TimelineViewManager::queueEmoteMessage(const QString &msg)
void
TimelineViewManager::queueImageMessage(const QString &roomid,
const QString &filename,
const QString &url)
const QString &filename,
const QString &url)
{
if (!views_.contains(roomid)) {
qDebug() << "Cannot send m.image message to a non-managed view";