diff --git a/cmake/MatrixStructs.cmake b/cmake/MatrixStructs.cmake index 134fdbd..02c0c9d 100644 --- a/cmake/MatrixStructs.cmake +++ b/cmake/MatrixStructs.cmake @@ -21,7 +21,7 @@ ExternalProject_Add( MatrixStructs GIT_REPOSITORY https://github.com/mujx/matrix-structs - GIT_TAG e6ce4fee893d7db8c6e9ece366d8184e009f003c + GIT_TAG 690080daa3bc1984297c4d7103cde9ea07e2e0b7 BUILD_IN_SOURCE 1 SOURCE_DIR ${MATRIX_STRUCTS_ROOT} diff --git a/include/timeline/TimelineItem.h b/include/timeline/TimelineItem.h index 952fb66..ac512ab 100644 --- a/include/timeline/TimelineItem.h +++ b/include/timeline/TimelineItem.h @@ -32,6 +32,7 @@ #include "Utils.h" class ImageItem; +class StickerItem; class AudioItem; class VideoItem; class FileItem; @@ -89,6 +90,11 @@ public: bool with_sender, const QString &room_id, QWidget *parent); + TimelineItem(StickerItem *img, + const mtx::events::Sticker &e, + bool with_sender, + const QString &room_id, + QWidget *parent); TimelineItem(FileItem *file, const mtx::events::RoomEvent &e, bool with_sender, diff --git a/include/timeline/widgets/ImageItem.h b/include/timeline/widgets/ImageItem.h index d8a12c2..146aa7f 100644 --- a/include/timeline/widgets/ImageItem.h +++ b/include/timeline/widgets/ImageItem.h @@ -57,6 +57,9 @@ protected: void mousePressEvent(QMouseEvent *event) override; void resizeEvent(QResizeEvent *event) override; + //! Whether the user can interact with the displayed image. + bool isInteractive_ = true; + private: void openUrl(); @@ -81,3 +84,28 @@ private: QSharedPointer client_; }; + +class StickerItem : public ImageItem +{ + Q_OBJECT + +public: + StickerItem(QSharedPointer client, + const mtx::events::Sticker &event, + QWidget *parent = nullptr) + : ImageItem{client, + QString::fromStdString(event.content.url), + QString::fromStdString(event.content.body), + event.content.info.size, + parent} + , event_{event} + { + isInteractive_ = false; + setCursor(Qt::ArrowCursor); + setMouseTracking(false); + setAttribute(Qt::WA_Hover, false); + } + +private: + mtx::events::Sticker event_; +}; diff --git a/src/RoomList.cc b/src/RoomList.cc index 61b3e4b..a319519 100644 --- a/src/RoomList.cc +++ b/src/RoomList.cc @@ -187,7 +187,13 @@ RoomList::cleanupInvites(const std::map &invites) return; utils::erase_if(rooms_, [invites](auto &room) { - return room.second->isInvite() && (invites.find(room.first) == invites.end()); + auto room_id = room.first; + auto item = room.second; + + if (!item) + return false; + + return item->isInvite() && (invites.find(room_id) == invites.end()); }); } diff --git a/src/Utils.cc b/src/Utils.cc index fd88d51..0aca830 100644 --- a/src/Utils.cc +++ b/src/Utils.cc @@ -118,6 +118,18 @@ utils::getMessageDescription(const TimelineEvent &event, " sent a video clip", utils::descriptiveTime(ts), ts}; + } else if (mpark::holds_alternative(event)) { + const auto msg = mpark::get(event); + QString sender = QString::fromStdString(msg.sender); + + const auto username = Cache::displayName(room_id, sender); + const auto ts = QDateTime::fromMSecsSinceEpoch(msg.origin_server_ts); + + return DescInfo{sender == localUser ? "You" : username, + sender, + " sent a sticker", + utils::descriptiveTime(ts), + ts}; } return DescInfo{}; diff --git a/src/timeline/TimelineItem.cc b/src/timeline/TimelineItem.cc index cd1dac6..ce82ebd 100644 --- a/src/timeline/TimelineItem.cc +++ b/src/timeline/TimelineItem.cc @@ -210,6 +210,20 @@ TimelineItem::TimelineItem(ImageItem *image, addSaveImageAction(image); } +TimelineItem::TimelineItem(StickerItem *image, + const mtx::events::Sticker &event, + bool with_sender, + const QString &room_id, + QWidget *parent) + : QWidget(parent) + , room_id_{room_id} +{ + setupWidgetLayout( + image, event, " sent a sticker", with_sender); + + addSaveImageAction(image); +} + TimelineItem::TimelineItem(FileItem *file, const mtx::events::RoomEvent &event, bool with_sender, diff --git a/src/timeline/TimelineView.cc b/src/timeline/TimelineView.cc index 679aa17..d7f674d 100644 --- a/src/timeline/TimelineView.cc +++ b/src/timeline/TimelineView.cc @@ -281,6 +281,9 @@ TimelineView::parseMessageEvent(const mtx::events::collections::TimelineEvents & } else if (mpark::holds_alternative>(event)) { auto video = mpark::get>(event); return processMessageEvent(video, direction); + } else if (mpark::holds_alternative(event)) { + return processMessageEvent( + mpark::get(event), direction); } return nullptr; diff --git a/src/timeline/widgets/ImageItem.cc b/src/timeline/widgets/ImageItem.cc index 3aae63c..03f9741 100644 --- a/src/timeline/widgets/ImageItem.cc +++ b/src/timeline/widgets/ImageItem.cc @@ -138,6 +138,11 @@ ImageItem::setImage(const QPixmap &image) void ImageItem::mousePressEvent(QMouseEvent *event) { + if (!isInteractive_) { + event->accept(); + return; + } + if (event->button() != Qt::LeftButton) return; @@ -204,7 +209,7 @@ ImageItem::paintEvent(QPaintEvent *event) painter.drawPath(path); // Bottom text section - if (underMouse()) { + if (isInteractive_ && underMouse()) { const int textBoxHeight = fontHeight / 2 + 6; textRegion_ = QRectF(0, height_ - textBoxHeight, width_, textBoxHeight);