summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2019-11-09 03:06:10 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2019-11-23 20:07:15 +0100
commit91d1f19058a31cc35ca1212f042a9dd6f501a7b7 (patch)
treec37888c720cce2d1736afbd071cf9dd75e1a9391 /src
parente8f8182844a91a8ae5838f06a41968e95386904c (diff)
Remove old timeline
Diffstat (limited to 'src')
-rw-r--r--src/ChatPage.cpp2
-rw-r--r--src/Utils.h14
-rw-r--r--src/dialogs/MemberList.cpp1
-rw-r--r--src/timeline/DelegateChooser.cpp (renamed from src/timeline2/DelegateChooser.cpp)0
-rw-r--r--src/timeline/DelegateChooser.h (renamed from src/timeline2/DelegateChooser.h)0
-rw-r--r--src/timeline/TimelineItem.cpp960
-rw-r--r--src/timeline/TimelineItem.h389
-rw-r--r--src/timeline/TimelineModel.cpp (renamed from src/timeline2/TimelineModel.cpp)0
-rw-r--r--src/timeline/TimelineModel.h (renamed from src/timeline2/TimelineModel.h)0
-rw-r--r--src/timeline/TimelineView.cpp1627
-rw-r--r--src/timeline/TimelineView.h449
-rw-r--r--src/timeline/TimelineViewManager.cpp564
-rw-r--r--src/timeline/TimelineViewManager.h111
-rw-r--r--src/timeline/widgets/AudioItem.cpp236
-rw-r--r--src/timeline/widgets/AudioItem.h104
-rw-r--r--src/timeline/widgets/FileItem.cpp221
-rw-r--r--src/timeline/widgets/FileItem.h79
-rw-r--r--src/timeline/widgets/ImageItem.cpp267
-rw-r--r--src/timeline/widgets/ImageItem.h104
-rw-r--r--src/timeline/widgets/VideoItem.cpp65
-rw-r--r--src/timeline/widgets/VideoItem.h51
-rw-r--r--src/timeline2/TimelineViewManager.cpp400
-rw-r--r--src/timeline2/TimelineViewManager.h117
23 files changed, 384 insertions, 5377 deletions
diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp
index b8f312ac..091a9fa0 100644
--- a/src/ChatPage.cpp
+++ b/src/ChatPage.cpp
@@ -44,7 +44,7 @@
#include "dialogs/ReadReceipts.h"
#include "popups/UserMentions.h"
-#include "timeline2/TimelineViewManager.h"
+#include "timeline/TimelineViewManager.h"
// TODO: Needs to be updated with an actual secret.
static const std::string STORAGE_SECRET_KEY("secret");
diff --git a/src/Utils.h b/src/Utils.h
index 007126c3..bdb51844 100644
--- a/src/Utils.h
+++ b/src/Utils.h
@@ -4,10 +4,6 @@
#include "Cache.h"
#include "RoomInfoListItem.h"
-#include "timeline/widgets/AudioItem.h"
-#include "timeline/widgets/FileItem.h"
-#include "timeline/widgets/ImageItem.h"
-#include "timeline/widgets/VideoItem.h"
#include <QCoreApplication>
#include <QDateTime>
@@ -94,7 +90,7 @@ messageDescription(const QString &username = "",
using Video = mtx::events::RoomEvent<mtx::events::msg::Video>;
using Encrypted = mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>;
- if (std::is_same<T, AudioItem>::value || std::is_same<T, Audio>::value) {
+ if (std::is_same<T, Audio>::value) {
if (isLocal)
return QCoreApplication::translate("message-description sent:",
"You sent an audio clip");
@@ -102,7 +98,7 @@ messageDescription(const QString &username = "",
return QCoreApplication::translate("message-description sent:",
"%1 sent an audio clip")
.arg(username);
- } else if (std::is_same<T, ImageItem>::value || std::is_same<T, Image>::value) {
+ } else if (std::is_same<T, Image>::value) {
if (isLocal)
return QCoreApplication::translate("message-description sent:",
"You sent an image");
@@ -110,7 +106,7 @@ messageDescription(const QString &username = "",
return QCoreApplication::translate("message-description sent:",
"%1 sent an image")
.arg(username);
- } else if (std::is_same<T, FileItem>::value || std::is_same<T, File>::value) {
+ } else if (std::is_same<T, File>::value) {
if (isLocal)
return QCoreApplication::translate("message-description sent:",
"You sent a file");
@@ -118,7 +114,7 @@ messageDescription(const QString &username = "",
return QCoreApplication::translate("message-description sent:",
"%1 sent a file")
.arg(username);
- } else if (std::is_same<T, VideoItem>::value || std::is_same<T, Video>::value) {
+ } else if (std::is_same<T, Video>::value) {
if (isLocal)
return QCoreApplication::translate("message-description sent:",
"You sent a video");
@@ -126,7 +122,7 @@ messageDescription(const QString &username = "",
return QCoreApplication::translate("message-description sent:",
"%1 sent a video")
.arg(username);
- } else if (std::is_same<T, StickerItem>::value || std::is_same<T, Sticker>::value) {
+ } else if (std::is_same<T, Sticker>::value) {
if (isLocal)
return QCoreApplication::translate("message-description sent:",
"You sent a sticker");
diff --git a/src/dialogs/MemberList.cpp b/src/dialogs/MemberList.cpp
index 9e973efa..f62cf9fe 100644
--- a/src/dialogs/MemberList.cpp
+++ b/src/dialogs/MemberList.cpp
@@ -1,4 +1,5 @@
#include <QAbstractSlider>
+#include <QLabel>
#include <QListWidgetItem>
#include <QPainter>
#include <QPushButton>
diff --git a/src/timeline2/DelegateChooser.cpp b/src/timeline/DelegateChooser.cpp
index 632a2a64..632a2a64 100644
--- a/src/timeline2/DelegateChooser.cpp
+++ b/src/timeline/DelegateChooser.cpp
diff --git a/src/timeline2/DelegateChooser.h b/src/timeline/DelegateChooser.h
index 68ebeb04..68ebeb04 100644
--- a/src/timeline2/DelegateChooser.h
+++ b/src/timeline/DelegateChooser.h
diff --git a/src/timeline/TimelineItem.cpp b/src/timeline/TimelineItem.cpp
deleted file mode 100644
index 7916bd80..00000000
--- a/src/timeline/TimelineItem.cpp
+++ /dev/null
@@ -1,960 +0,0 @@
-/*
- * nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-#include <functional>
-
-#include <QContextMenuEvent>
-#include <QDesktopServices>
-#include <QFontDatabase>
-#include <QMenu>
-#include <QTimer>
-#include <QtGlobal>
-
-#include "ChatPage.h"
-#include "Config.h"
-#include "Logging.h"
-#include "MainWindow.h"
-#include "Olm.h"
-#include "ui/Avatar.h"
-#include "ui/Painter.h"
-#include "ui/TextLabel.h"
-
-#include "timeline/TimelineItem.h"
-#include "timeline/widgets/AudioItem.h"
-#include "timeline/widgets/FileItem.h"
-#include "timeline/widgets/ImageItem.h"
-#include "timeline/widgets/VideoItem.h"
-
-#include "dialogs/RawMessage.h"
-#include "mtx/identifiers.hpp"
-
-constexpr int MSG_RIGHT_MARGIN = 7;
-constexpr int MSG_PADDING = 20;
-
-StatusIndicator::StatusIndicator(QWidget *parent)
- : QWidget(parent)
-{
- lockIcon_.addFile(":/icons/icons/ui/lock.png");
- clockIcon_.addFile(":/icons/icons/ui/clock.png");
- checkmarkIcon_.addFile(":/icons/icons/ui/checkmark.png");
- doubleCheckmarkIcon_.addFile(":/icons/icons/ui/double-tick-indicator.png");
-}
-
-void
-StatusIndicator::paintIcon(QPainter &p, QIcon &icon)
-{
- auto pixmap = icon.pixmap(width());
-
- QPainter painter(&pixmap);
- painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
- painter.fillRect(pixmap.rect(), p.pen().color());
-
- QIcon(pixmap).paint(&p, rect(), Qt::AlignCenter, QIcon::Normal);
-}
-
-void
-StatusIndicator::paintEvent(QPaintEvent *)
-{
- if (state_ == StatusIndicatorState::Empty)
- return;
-
- Painter p(this);
- PainterHighQualityEnabler hq(p);
-
- p.setPen(iconColor_);
-
- switch (state_) {
- case StatusIndicatorState::Sent: {
- paintIcon(p, clockIcon_);
- break;
- }
- case StatusIndicatorState::Encrypted:
- paintIcon(p, lockIcon_);
- break;
- case StatusIndicatorState::Received: {
- paintIcon(p, checkmarkIcon_);
- break;
- }
- case StatusIndicatorState::Read: {
- paintIcon(p, doubleCheckmarkIcon_);
- break;
- }
- case StatusIndicatorState::Empty:
- break;
- }
-}
-
-void
-StatusIndicator::setState(StatusIndicatorState state)
-{
- state_ = state;
-
- switch (state) {
- case StatusIndicatorState::Encrypted:
- setToolTip(tr("Encrypted"));
- break;
- case StatusIndicatorState::Received:
- setToolTip(tr("Delivered"));
- break;
- case StatusIndicatorState::Read:
- setToolTip(tr("Seen"));
- break;
- case StatusIndicatorState::Sent:
- setToolTip(tr("Sent"));
- break;
- case StatusIndicatorState::Empty:
- setToolTip("");
- break;
- }
-
- update();
-}
-
-void
-TimelineItem::adjustMessageLayoutForWidget()
-{
- messageLayout_->addLayout(widgetLayout_, 1);
- actionLayout_->addWidget(replyBtn_);
- actionLayout_->addWidget(contextBtn_);
- messageLayout_->addLayout(actionLayout_);
- messageLayout_->addWidget(statusIndicator_);
- messageLayout_->addWidget(timestamp_);
-
- actionLayout_->setAlignment(replyBtn_, Qt::AlignTop | Qt::AlignRight);
- actionLayout_->setAlignment(contextBtn_, Qt::AlignTop | Qt::AlignRight);
- messageLayout_->setAlignment(statusIndicator_, Qt::AlignTop);
- messageLayout_->setAlignment(timestamp_, Qt::AlignTop);
- messageLayout_->setAlignment(actionLayout_, Qt::AlignTop);
-
- mainLayout_->addLayout(messageLayout_);
-}
-
-void
-TimelineItem::adjustMessageLayout()
-{
- messageLayout_->addWidget(body_, 1);
- actionLayout_->addWidget(replyBtn_);
- actionLayout_->addWidget(contextBtn_);
- messageLayout_->addLayout(actionLayout_);
- messageLayout_->addWidget(statusIndicator_);
- messageLayout_->addWidget(timestamp_);
-
- actionLayout_->setAlignment(replyBtn_, Qt::AlignTop | Qt::AlignRight);
- actionLayout_->setAlignment(contextBtn_, Qt::AlignTop | Qt::AlignRight);
- messageLayout_->setAlignment(statusIndicator_, Qt::AlignTop);
- messageLayout_->setAlignment(timestamp_, Qt::AlignTop);
- messageLayout_->setAlignment(actionLayout_, Qt::AlignTop);
-
- mainLayout_->addLayout(messageLayout_);
-}
-
-void
-TimelineItem::init()
-{
- userAvatar_ = nullptr;
- timestamp_ = nullptr;
- userName_ = nullptr;
- body_ = nullptr;
- auto buttonSize_ = 32;
-
- contextMenu_ = new QMenu(this);
- showReadReceipts_ = new QAction("Read receipts", this);
- markAsRead_ = new QAction("Mark as read", this);
- viewRawMessage_ = new QAction("View raw message", this);
- redactMsg_ = new QAction("Redact message", this);
- contextMenu_->addAction(showReadReceipts_);
- contextMenu_->addAction(viewRawMessage_);
- contextMenu_->addAction(markAsRead_);
- contextMenu_->addAction(redactMsg_);
-
- connect(showReadReceipts_, &QAction::triggered, this, [this]() {
- if (!event_id_.isEmpty())
- MainWindow::instance()->openReadReceiptsDialog(event_id_);
- });
-
- connect(this, &TimelineItem::eventRedacted, this, [this](const QString &event_id) {
- emit ChatPage::instance()->removeTimelineEvent(room_id_, event_id);
- });
- connect(this, &TimelineItem::redactionFailed, this, [](const QString &msg) {
- emit ChatPage::instance()->showNotification(msg);
- });
- connect(redactMsg_, &QAction::triggered, this, [this]() {
- if (!event_id_.isEmpty())
- http::client()->redact_event(
- room_id_.toStdString(),
- event_id_.toStdString(),
- [this](const mtx::responses::EventId &, mtx::http::RequestErr err) {
- if (err) {
- emit redactionFailed(tr("Message redaction failed: %1")
- .arg(QString::fromStdString(
- err->matrix_error.error)));
- return;
- }
-
- emit eventRedacted(event_id_);
- });
- });
- connect(
- ChatPage::instance(), &ChatPage::themeChanged, this, &TimelineItem::refreshAuthorColor);
- connect(markAsRead_, &QAction::triggered, this, &TimelineItem::sendReadReceipt);
- connect(viewRawMessage_, &QAction::triggered, this, &TimelineItem::openRawMessageViewer);
-
- colorGenerating_ = new QFutureWatcher<QString>(this);
- connect(colorGenerating_,
- &QFutureWatcher<QString>::finished,
- this,
- &TimelineItem::finishedGeneratingColor);
-
- topLayout_ = new QHBoxLayout(this);
- mainLayout_ = new QVBoxLayout;
- messageLayout_ = new QHBoxLayout;
- actionLayout_ = new QHBoxLayout;
- messageLayout_->setContentsMargins(0, 0, MSG_RIGHT_MARGIN, 0);
- messageLayout_->setSpacing(MSG_PADDING);
-
- actionLayout_->setContentsMargins(13, 1, 13, 0);
- actionLayout_->setSpacing(0);
-
- topLayout_->setContentsMargins(
- conf::timeline::msgLeftMargin, conf::timeline::msgTopMargin, 0, 0);
- topLayout_->setSpacing(0);
- topLayout_->addLayout(mainLayout_);
-
- mainLayout_->setContentsMargins(conf::timeline::headerLeftMargin, 0, 0, 0);
- mainLayout_->setSpacing(0);
-
- replyBtn_ = new FlatButton(this);
- replyBtn_->setToolTip(tr("Reply"));
- replyBtn_->setFixedSize(buttonSize_, buttonSize_);
- replyBtn_->setCornerRadius(buttonSize_ / 2);
-
- QIcon reply_icon;
- reply_icon.addFile(":/icons/icons/ui/mail-reply.png");
- replyBtn_->setIcon(reply_icon);
- replyBtn_->setIconSize(QSize(buttonSize_ / 2, buttonSize_ / 2));
- connect(replyBtn_, &FlatButton::clicked, this, &TimelineItem::replyAction);
-
- contextBtn_ = new FlatButton(this);
- contextBtn_->setToolTip(tr("Options"));
- contextBtn_->setFixedSize(buttonSize_, buttonSize_);
- contextBtn_->setCornerRadius(buttonSize_ / 2);
-
- QIcon context_icon;
- context_icon.addFile(":/icons/icons/ui/vertical-ellipsis.png");
- contextBtn_->setIcon(context_icon);
- contextBtn_->setIconSize(QSize(buttonSize_ / 2, buttonSize_ / 2));
- contextBtn_->setMenu(contextMenu_);
-
- timestampFont_.setPointSizeF(timestampFont_.pointSizeF() * 0.9);
- timestampFont_.setFamily("Monospace");
- timestampFont_.setStyleHint(QFont::Monospace);
-
- QFontMetrics tsFm(timestampFont_);
-
- statusIndicator_ = new StatusIndicator(this);
- statusIndicator_->setFixedWidth(tsFm.height() - tsFm.leading());
- statusIndicator_->setFixedHeight(tsFm.height() - tsFm.leading());
-
- parentWidget()->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
- setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
-}
-
-/*
- * For messages created locally.
- */
-TimelineItem::TimelineItem(mtx::events::MessageType ty,
- const QString &userid,
- QString body,
- bool withSender,
- const QString &room_id,
- QWidget *parent)
- : QWidget(parent)
- , message_type_(ty)
- , room_id_{room_id}
-{
- init();
- addReplyAction();
-
- auto displayName = Cache::displayName(room_id_, userid);
- auto timestamp = QDateTime::currentDateTime();
-
- // Generate the html body to be rendered.
- auto formatted_body = utils::markdownToHtml(body);
-
- // Escape html if the input is not formatted.
- if (formatted_body == body.trimmed().toHtmlEscaped())
- formatted_body = body.toHtmlEscaped();
-
- QString emptyEventId;
-
- if (ty == mtx::events::MessageType::Emote) {
- formatted_body = QString("<em>%1</em>").arg(formatted_body);
- descriptionMsg_ = {emptyEventId,
- "",
- userid,
- QString("* %1 %2").arg(displayName).arg(body),
- utils::descriptiveTime(timestamp),
- timestamp};
- } else {
- descriptionMsg_ = {emptyEventId,
- "You: ",
- userid,
- body,
- utils::descriptiveTime(timestamp),
- timestamp};
- }
-
- formatted_body = utils::linkifyMessage(formatted_body);
- formatted_body.replace("mx-reply", "div");
-
- generateTimestamp(timestamp);
-
- if (withSender) {
- generateBody(userid, displayName, formatted_body);
- setupAvatarLayout(displayName);
-
- setUserAvatar(userid);
- } else {
- generateBody(formatted_body);
- setupSimpleLayout();
- }
-
- adjustMessageLayout();
-}
-
-TimelineItem::TimelineItem(ImageItem *image,
- const QString &userid,
- bool withSender,
- const QString &room_id,
- QWidget *parent)
- : QWidget{parent}
- , message_type_(mtx::events::MessageType::Image)
- , room_id_{room_id}
-{
- init();
-
- setupLocalWidgetLayout<ImageItem>(image, userid, withSender);
-
- addSaveImageAction(image);
-}
-
-TimelineItem::TimelineItem(FileItem *file,
- const QString &userid,
- bool withSender,
- const QString &room_id,
- QWidget *parent)
- : QWidget{parent}
- , message_type_(mtx::events::MessageType::File)
- , room_id_{room_id}
-{
- init();
-
- setupLocalWidgetLayout<FileItem>(file, userid, withSender);
-}
-
-TimelineItem::TimelineItem(AudioItem *audio,
- const QString &userid,
- bool withSender,
- const QString &room_id,
- QWidget *parent)
- : QWidget{parent}
- , message_type_(mtx::events::MessageType::Audio)
- , room_id_{room_id}
-{
- init();
-
- setupLocalWidgetLayout<AudioItem>(audio, userid, withSender);
-}
-
-TimelineItem::TimelineItem(VideoItem *video,
- const QString &userid,
- bool withSender,
- const QString &room_id,
- QWidget *parent)
- : QWidget{parent}
- , message_type_(mtx::events::MessageType::Video)
- , room_id_{room_id}
-{
- init();
-
- setupLocalWidgetLayout<VideoItem>(video, userid, withSender);
-}
-
-TimelineItem::TimelineItem(ImageItem *image,
- const mtx::events::RoomEvent<mtx::events::msg::Image> &event,
- bool with_sender,
- const QString &room_id,
- QWidget *parent)
- : QWidget(parent)
- , message_type_(mtx::events::MessageType::Image)
- , room_id_{room_id}
-{
- setupWidgetLayout<mtx::events::RoomEvent<mtx::events::msg::Image>, ImageItem>(
- image, event, with_sender);
-
- markOwnMessagesAsReceived(event.sender);
-
- 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, with_sender);
-
- markOwnMessagesAsReceived(event.sender);
-
- addSaveImageAction(image);
-}
-
-TimelineItem::TimelineItem(FileItem *file,
- const mtx::events::RoomEvent<mtx::events::msg::File> &event,
- bool with_sender,
- const QString &room_id,
- QWidget *parent)
- : QWidget(parent)
- , message_type_(mtx::events::MessageType::File)
- , room_id_{room_id}
-{
- setupWidgetLayout<mtx::events::RoomEvent<mtx::events::msg::File>, FileItem>(
- file, event, with_sender);
-
- markOwnMessagesAsReceived(event.sender);
-}
-
-TimelineItem::TimelineItem(AudioItem *audio,
- const mtx::events::RoomEvent<mtx::events::msg::Audio> &event,
- bool with_sender,
- const QString &room_id,
- QWidget *parent)
- : QWidget(parent)
- , message_type_(mtx::events::MessageType::Audio)
- , room_id_{room_id}
-{
- setupWidgetLayout<mtx::events::RoomEvent<mtx::events::msg::Audio>, AudioItem>(
- audio, event, with_sender);
-
- markOwnMessagesAsReceived(event.sender);
-}
-
-TimelineItem::TimelineItem(VideoItem *video,
- const mtx::events::RoomEvent<mtx::events::msg::Video> &event,
- bool with_sender,
- const QString &room_id,
- QWidget *parent)
- : QWidget(parent)
- , message_type_(mtx::events::MessageType::Video)
- , room_id_{room_id}
-{
- setupWidgetLayout<mtx::events::RoomEvent<mtx::events::msg::Video>, VideoItem>(
- video, event, with_sender);
-
- markOwnMessagesAsReceived(event.sender);
-}
-
-/*
- * Used to display remote notice messages.
- */
-TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Notice> &event,
- bool with_sender,
- const QString &room_id,
- QWidget *parent)
- : QWidget(parent)
- , message_type_(mtx::events::MessageType::Notice)
- , room_id_{room_id}
-{
- init();
- addReplyAction();
-
- markOwnMessagesAsReceived(event.sender);
-
- event_id_ = QString::fromStdString(event.event_id);
- const auto sender = QString::fromStdString(event.sender);
- const auto timestamp = QDateTime::fromMSecsSinceEpoch(event.origin_server_ts);
-
- auto formatted_body = utils::linkifyMessage(utils::getMessageBody(event).trimmed());
- auto body = QString::fromStdString(event.content.body).trimmed().toHtmlEscaped();
-
- descriptionMsg_ = {event_id_,
- Cache::displayName(room_id_, sender),
- sender,
- " sent a notification",
- utils::descriptiveTime(timestamp),
- timestamp};
-
- generateTimestamp(timestamp);
-
- if (with_sender) {
- auto displayName = Cache::displayName(room_id_, sender);
-
- generateBody(sender, displayName, formatted_body);
- setupAvatarLayout(displayName);
-
- setUserAvatar(sender);
- } else {
- generateBody(formatted_body);
- setupSimpleLayout();
- }
-
- adjustMessageLayout();
-}
-
-/*
- * Used to display remote emote messages.
- */
-TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Emote> &event,
- bool with_sender,
- const QString &room_id,
- QWidget *parent)
- : QWidget(parent)
- , message_type_(mtx::events::MessageType::Emote)
- , room_id_{room_id}
-{
- init();
- addReplyAction();
-
- markOwnMessagesAsReceived(event.sender);
-
- event_id_ = QString::fromStdString(event.event_id);
- const auto sender = QString::fromStdString(event.sender);
-
- auto formatted_body = utils::linkifyMessage(utils::getMessageBody(event).trimmed());
- auto body = QString::fromStdString(event.content.body).trimmed().toHtmlEscaped();
-
- auto timestamp = QDateTime::fromMSecsSinceEpoch(event.origin_server_ts);
- auto displayName = Cache::displayName(room_id_, sender);
- formatted_body = QString("<em>%1</em>").arg(formatted_body);
-
- descriptionMsg_ = {event_id_,
- "",
- sender,
- QString("* %1 %2").arg(displayName).arg(body),
- utils::descriptiveTime(timestamp),
- timestamp};
-
- generateTimestamp(timestamp);
-
- if (with_sender) {
- generateBody(sender, displayName, formatted_body);
- setupAvatarLayout(displayName);
-
- setUserAvatar(sender);
- } else {
- generateBody(formatted_body);
- setupSimpleLayout();
- }
-
- adjustMessageLayout();
-}
-
-/*
- * Used to display remote text messages.
- */
-TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Text> &event,
- bool with_sender,
- const QString &room_id,
- QWidget *parent)
- : QWidget(parent)
- , message_type_(mtx::events::MessageType::Text)
- , room_id_{room_id}
-{
- init();
- addReplyAction();
-
- markOwnMessagesAsReceived(event.sender);
-
- event_id_ = QString::fromStdString(event.event_id);
- const auto sender = QString::fromStdString(event.sender);
-
- auto formatted_body = utils::linkifyMessage(utils::getMessageBody(event).trimmed());
- auto body = QString::fromStdString(event.content.body).trimmed().toHtmlEscaped();
-
- auto timestamp = QDateTime::fromMSecsSinceEpoch(event.origin_server_ts);
- auto displayName = Cache::displayName(room_id_, sender);
-
- QSettings settings;
- descriptionMsg_ = {event_id_,
- sender == settings.value("auth/user_id") ? "You" : displayName,
- sender,
- QString(": %1").arg(body),
- utils::descriptiveTime(timestamp),
- timestamp};
-
- generateTimestamp(timestamp);
-
- if (with_sender) {
- generateBody(sender, displayName, formatted_body);
- setupAvatarLayout(displayName);
-
- setUserAvatar(sender);
- } else {
- generateBody(formatted_body);
- setupSimpleLayout();
- }
-
- adjustMessageLayout();
-}
-
-TimelineItem::~TimelineItem()
-{
- colorGenerating_->cancel();
- colorGenerating_->waitForFinished();
-}
-
-void
-TimelineItem::markSent()
-{
- statusIndicator_->setState(StatusIndicatorState::Sent);
-}
-
-void
-TimelineItem::markOwnMessagesAsReceived(const std::string &sender)
-{
- QSettings settings;
- if (sender == settings.value("auth/user_id").toString().toStdString())
- statusIndicator_->setState(StatusIndicatorState::Received);
-}
-
-void
-TimelineItem::markRead()
-{
- if (statusIndicator_->state() != StatusIndicatorState::Encrypted)
- statusIndicator_->setState(StatusIndicatorState::Read);
-}
-
-void
-TimelineItem::markReceived(bool isEncrypted)
-{
- isReceived_ = true;
-
- if (isEncrypted)
- statusIndicator_->setState(StatusIndicatorState::Encrypted);
- else
- statusIndicator_->setState(StatusIndicatorState::Received);
-
- sendReadReceipt();
-}
-
-// Only the body is displayed.