summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--cmake/MatrixStructs.cmake2
-rw-r--r--include/timeline/TimelineItem.h6
-rw-r--r--include/timeline/widgets/ImageItem.h28
-rw-r--r--src/RoomList.cc8
-rw-r--r--src/Utils.cc12
-rw-r--r--src/timeline/TimelineItem.cc14
-rw-r--r--src/timeline/TimelineView.cc3
-rw-r--r--src/timeline/widgets/ImageItem.cc7
8 files changed, 77 insertions, 3 deletions
diff --git a/cmake/MatrixStructs.cmake b/cmake/MatrixStructs.cmake
index 134fdbd1..02c0c9d0 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 952fb661..ac512ab8 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<mtx::events::msg::File> &e,
                      bool with_sender,
diff --git a/include/timeline/widgets/ImageItem.h b/include/timeline/widgets/ImageItem.h
index d8a12c22..146aa7f6 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<MatrixClient> client_;
 };
+
+class StickerItem : public ImageItem
+{
+        Q_OBJECT
+
+public:
+        StickerItem(QSharedPointer<MatrixClient> 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 61b3e4bc..a3195196 100644
--- a/src/RoomList.cc
+++ b/src/RoomList.cc
@@ -187,7 +187,13 @@ RoomList::cleanupInvites(const std::map<QString, bool> &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 fd88d51c..0aca8303 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<mtx::events::Sticker>(event)) {
+                const auto msg = mpark::get<mtx::events::Sticker>(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 cd1dac67..ce82ebd8 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<mtx::events::Sticker, StickerItem>(
+          image, event, " sent a sticker", with_sender);
+
+        addSaveImageAction(image);
+}
+
 TimelineItem::TimelineItem(FileItem *file,
                            const mtx::events::RoomEvent<mtx::events::msg::File> &event,
                            bool with_sender,
diff --git a/src/timeline/TimelineView.cc b/src/timeline/TimelineView.cc
index 679aa173..d7f674d4 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<mtx::events::RoomEvent<msg::Video>>(event)) {
                 auto video = mpark::get<mtx::events::RoomEvent<msg::Video>>(event);
                 return processMessageEvent<VideoEvent, VideoItem>(video, direction);
+        } else if (mpark::holds_alternative<mtx::events::Sticker>(event)) {
+                return processMessageEvent<mtx::events::Sticker, StickerItem>(
+                  mpark::get<mtx::events::Sticker>(event), direction);
         }
 
         return nullptr;
diff --git a/src/timeline/widgets/ImageItem.cc b/src/timeline/widgets/ImageItem.cc
index 3aae63c8..03f9741b 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);