Add support for displaying m.sticker events

fixes #291
remotes/origin/HEAD
Konstantinos Sideris 7 years ago
parent c971602b2d
commit 3f80725c33
  1. 2
      cmake/MatrixStructs.cmake
  2. 6
      include/timeline/TimelineItem.h
  3. 28
      include/timeline/widgets/ImageItem.h
  4. 8
      src/RoomList.cc
  5. 12
      src/Utils.cc
  6. 14
      src/timeline/TimelineItem.cc
  7. 3
      src/timeline/TimelineView.cc
  8. 7
      src/timeline/widgets/ImageItem.cc

@ -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}

@ -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,

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

@ -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());
});
}

@ -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{};

@ -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,

@ -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;

@ -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);

Loading…
Cancel
Save