diff --git a/include/timeline/TimelineItem.h b/include/timeline/TimelineItem.h
index 9997ec1d..4dcca1a5 100644
--- a/include/timeline/TimelineItem.h
+++ b/include/timeline/TimelineItem.h
@@ -197,12 +197,24 @@ public:
void sendReadReceipt() const
{
if (!event_id_.isEmpty())
- http::client()->readEvent(room_id_, event_id_);
+ http::v2::client()->read_event(
+ room_id_.toStdString(),
+ event_id_.toStdString(),
+ [this](mtx::http::RequestErr err) {
+ if (err) {
+ qWarning() << QString("failed to read_event (%1, %2)")
+ .arg(room_id_, event_id_);
+ }
+ });
}
//! Add a user avatar for this event.
void addAvatar();
+signals:
+ void eventRedacted(const QString &event_id);
+ void redactionFailed(const QString &msg);
+
protected:
void paintEvent(QPaintEvent *event) override;
void contextMenuEvent(QContextMenuEvent *event) override;
diff --git a/include/timeline/TimelineView.h b/include/timeline/TimelineView.h
index e6e35ccb..30af97fb 100644
--- a/include/timeline/TimelineView.h
+++ b/include/timeline/TimelineView.h
@@ -18,7 +18,6 @@
#pragma once
#include <QApplication>
-#include <QDebug>
#include <QLayout>
#include <QList>
#include <QQueue>
@@ -42,31 +41,13 @@ struct DescInfo;
struct PendingMessage
{
mtx::events::MessageType ty;
- int txn_id;
+ std::string txn_id;
QString body;
QString filename;
QString mime;
uint64_t media_size;
QString event_id;
TimelineItem *widget;
-
- PendingMessage(mtx::events::MessageType ty,
- int txn_id,
- QString body,
- QString filename,
- QString mime,
- uint64_t media_size,
- QString event_id,
- TimelineItem *widget)
- : ty(ty)
- , txn_id(txn_id)
- , body(body)
- , filename(filename)
- , mime(mime)
- , media_size(media_size)
- , event_id(event_id)
- , widget(widget)
- {}
};
// In which place new TimelineItems should be inserted.
@@ -129,7 +110,7 @@ public:
const QString &filename,
const QString &mime,
uint64_t size);
- void updatePendingMessage(int txn_id, QString event_id);
+ void updatePendingMessage(const std::string &txn_id, const QString &event_id);
void scrollDown();
QLabel *createDateSeparator(QDateTime datetime);
@@ -142,18 +123,21 @@ public slots:
void fetchHistory();
// Add old events at the top of the timeline.
- void addBackwardsEvents(const QString &room_id, const mtx::responses::Messages &msgs);
+ void addBackwardsEvents(const mtx::responses::Messages &msgs);
// Whether or not the initial batch has been loaded.
bool hasLoaded() { return scroll_layout_->count() > 1 || isTimelineFinished; }
- void handleFailedMessage(int txnid);
+ void handleFailedMessage(const std::string &txn_id);
private slots:
void sendNextPendingMessage();
signals:
void updateLastTimelineMessage(const QString &user, const DescInfo &info);
+ void messagesRetrieved(const mtx::responses::Messages &res);
+ void messageFailed(const std::string &txn_id);
+ void messageSent(const std::string &txn_id, const QString &event_id);
protected:
void paintEvent(QPaintEvent *event) override;
@@ -165,6 +149,13 @@ private:
QWidget *relativeWidget(TimelineItem *item, int dt) const;
+ //! Callback for all message sending.
+ void sendRoomMessageHandler(const std::string &txn_id,
+ const mtx::responses::EventId &res,
+ mtx::http::RequestErr err);
+
+ //! Call the /messages endpoint to fill the timeline.
+ void getMessages();
//! HACK: Fixing layout flickering when adding to the bottom
//! of the timeline.
void pushTimelineItem(TimelineItem *item)
@@ -230,8 +221,10 @@ private:
uint64_t origin_server_ts,
TimelineDirection direction);
- bool isPendingMessage(const QString &txnid, const QString &sender, const QString &userid);
- void removePendingMessage(const QString &txnid);
+ bool isPendingMessage(const std::string &txn_id,
+ const QString &sender,
+ const QString &userid);
+ void removePendingMessage(const std::string &txn_id);
bool isDuplicate(const QString &event_id) { return eventIds_.contains(event_id); }
@@ -320,9 +313,15 @@ TimelineView::addUserMessage(const QString &url,
// Keep track of the sender and the timestamp of the current message.
saveLastMessageInfo(local_user_, QDateTime::currentDateTime());
- int txn_id = http::client()->incrementTransactionId();
+ PendingMessage message;
+ message.ty = MsgType;
+ message.txn_id = mtx::client::utils::random_token();
+ message.body = url;
+ message.filename = trimmed;
+ message.mime = mime;
+ message.media_size = size;
+ message.widget = view_item;
- PendingMessage message(MsgType, txn_id, url, trimmed, mime, size, "", view_item);
handleNewUserMessage(message);
}
@@ -351,10 +350,10 @@ TimelineView::processMessageEvent(const Event &event, TimelineDirection directio
const auto event_id = QString::fromStdString(event.event_id);
const auto sender = QString::fromStdString(event.sender);
- const QString txnid = QString::fromStdString(event.unsigned_data.transaction_id);
- if ((!txnid.isEmpty() && isPendingMessage(txnid, sender, local_user_)) ||
+ const auto txn_id = event.unsigned_data.transaction_id;
+ if ((!txn_id.empty() && isPendingMessage(txn_id, sender, local_user_)) ||
isDuplicate(event_id)) {
- removePendingMessage(txnid);
+ removePendingMessage(txn_id);
return nullptr;
}
@@ -376,10 +375,10 @@ TimelineView::processMessageEvent(const Event &event, TimelineDirection directio
const auto event_id = QString::fromStdString(event.event_id);
const auto sender = QString::fromStdString(event.sender);
- const QString txnid = QString::fromStdString(event.unsigned_data.transaction_id);
- if ((!txnid.isEmpty() && isPendingMessage(txnid, sender, local_user_)) ||
+ const auto txn_id = event.unsigned_data.transaction_id;
+ if ((!txn_id.empty() && isPendingMessage(txn_id, sender, local_user_)) ||
isDuplicate(event_id)) {
- removePendingMessage(txnid);
+ removePendingMessage(txn_id);
return nullptr;
}
diff --git a/include/timeline/TimelineViewManager.h b/include/timeline/TimelineViewManager.h
index 308b83aa..9e31ecbf 100644
--- a/include/timeline/TimelineViewManager.h
+++ b/include/timeline/TimelineViewManager.h
@@ -56,6 +56,8 @@ signals:
void updateRoomsLastMessage(const QString &user, const DescInfo &info);
public slots:
+ void removeTimelineEvent(const QString &room_id, const QString &event_id);
+
void setHistoryView(const QString &room_id);
void queueTextMessage(const QString &msg);
void queueEmoteMessage(const QString &msg);
@@ -80,10 +82,6 @@ public slots:
const QString &mime,
uint64_t dsize);
-private slots:
- void messageSent(const QString &eventid, const QString &roomid, int txnid);
- void messageSendFailed(const QString &roomid, int txnid);
-
private:
//! Check if the given room id is managed by a TimelineView.
bool timelineViewExists(const QString &id) { return views_.find(id) != views_.end(); }
diff --git a/include/timeline/widgets/AudioItem.h b/include/timeline/widgets/AudioItem.h
index b31385d1..7b0781a2 100644
--- a/include/timeline/widgets/AudioItem.h
+++ b/include/timeline/widgets/AudioItem.h
@@ -69,9 +69,14 @@ protected:
void resizeEvent(QResizeEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
+signals:
+ void fileDownloadedCb(const QByteArray &data);
+
+private slots:
+ void fileDownloaded(const QByteArray &data);
+
private:
void init();
- void fileDownloaded(const QByteArray &data);
enum class AudioState
{
diff --git a/include/timeline/widgets/FileItem.h b/include/timeline/widgets/FileItem.h
index 09181d32..66543e79 100644
--- a/include/timeline/widgets/FileItem.h
+++ b/include/timeline/widgets/FileItem.h
@@ -52,15 +52,20 @@ public:
QColor iconColor() const { return iconColor_; }
QColor backgroundColor() const { return backgroundColor_; }
+signals:
+ void fileDownloadedCb(const QByteArray &data);
+
protected:
void paintEvent(QPaintEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
+private slots:
+ void fileDownloaded(const QByteArray &data);
+
private:
void openUrl();
void init();
- void fileDownloaded(const QByteArray &data);
QUrl url_;
QString text_;
diff --git a/include/timeline/widgets/ImageItem.h b/include/timeline/widgets/ImageItem.h
index b17b2d8b..e9d823f4 100644
--- a/include/timeline/widgets/ImageItem.h
+++ b/include/timeline/widgets/ImageItem.h
@@ -40,13 +40,17 @@ public:
uint64_t size,
QWidget *parent = nullptr);
- void setImage(const QPixmap &image);
-
QSize sizeHint() const override;
public slots:
//! Show a save as dialog for the image.
void saveAs();
+ void setImage(const QPixmap &image);
+ void saveImage(const QString &filename, const QByteArray &data);
+
+signals:
+ void imageDownloaded(const QPixmap &img);
+ void imageSaved(const QString &filename, const QByteArray &data);
protected:
void paintEvent(QPaintEvent *event) override;
@@ -57,7 +61,9 @@ protected:
bool isInteractive_ = true;
private:
+ void init();
void openUrl();
+ void downloadMedia(const QUrl &url);
int max_width_ = 500;
int max_height_ = 300;
|