2017-04-06 02:06:42 +03:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2018-01-03 19:05:49 +03:00
|
|
|
#include <QContextMenuEvent>
|
2017-06-05 02:14:05 +03:00
|
|
|
#include <QFontDatabase>
|
2018-01-03 19:05:49 +03:00
|
|
|
#include <QMenu>
|
2018-05-08 18:43:56 +03:00
|
|
|
#include <QTimer>
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2018-05-08 18:43:56 +03:00
|
|
|
#include "ChatPage.h"
|
2017-07-15 17:11:46 +03:00
|
|
|
#include "Config.h"
|
2018-07-17 16:37:25 +03:00
|
|
|
#include "Logging.h"
|
2018-07-20 12:02:35 +03:00
|
|
|
#include "MainWindow.h"
|
2018-07-17 16:37:25 +03:00
|
|
|
#include "Olm.h"
|
|
|
|
#include "ui/Avatar.h"
|
|
|
|
#include "ui/Painter.h"
|
2017-11-30 14:53:28 +03:00
|
|
|
|
|
|
|
#include "timeline/TimelineItem.h"
|
2017-12-01 16:39:50 +03:00
|
|
|
#include "timeline/widgets/AudioItem.h"
|
2017-11-30 14:53:28 +03:00
|
|
|
#include "timeline/widgets/FileItem.h"
|
|
|
|
#include "timeline/widgets/ImageItem.h"
|
2017-12-01 19:28:26 +03:00
|
|
|
#include "timeline/widgets/VideoItem.h"
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2018-04-29 20:39:22 +03:00
|
|
|
constexpr int MSG_RIGHT_MARGIN = 7;
|
|
|
|
constexpr int MSG_PADDING = 20;
|
2018-03-19 21:26:14 +03:00
|
|
|
|
2018-08-28 00:19:39 +03:00
|
|
|
TextLabel::TextLabel(const QString &text, QWidget *parent)
|
|
|
|
: QTextBrowser(parent)
|
|
|
|
{
|
|
|
|
setText(text);
|
|
|
|
setOpenExternalLinks(true);
|
|
|
|
|
|
|
|
// Make it look and feel like an ordinary label.
|
|
|
|
setReadOnly(true);
|
|
|
|
setFrameStyle(QFrame::NoFrame);
|
|
|
|
QPalette pal = palette();
|
|
|
|
pal.setColor(QPalette::Base, Qt::transparent);
|
|
|
|
setPalette(pal);
|
|
|
|
|
|
|
|
// Wrap anywhere but prefer words, adjust minimum height on the fly.
|
|
|
|
setLineWrapMode(QTextEdit::WidgetWidth);
|
|
|
|
setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
|
|
|
|
connect(document()->documentLayout(),
|
|
|
|
&QAbstractTextDocumentLayout::documentSizeChanged,
|
|
|
|
this,
|
|
|
|
&TextLabel::adjustHeight);
|
|
|
|
document()->setDocumentMargin(0);
|
|
|
|
|
|
|
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
|
|
|
setFixedHeight(0);
|
|
|
|
}
|
|
|
|
|
2018-07-01 19:40:53 +03:00
|
|
|
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");
|
2018-07-17 23:50:18 +03:00
|
|
|
doubleCheckmarkIcon_.addFile(":/icons/icons/ui/double-tick-indicator.png");
|
2018-07-01 19:40:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2018-07-17 23:50:18 +03:00
|
|
|
case StatusIndicatorState::Read: {
|
|
|
|
paintIcon(p, doubleCheckmarkIcon_);
|
|
|
|
break;
|
|
|
|
}
|
2018-07-01 19:40:53 +03:00
|
|
|
case StatusIndicatorState::Empty:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StatusIndicator::setState(StatusIndicatorState state)
|
|
|
|
{
|
|
|
|
state_ = state;
|
2018-08-08 12:57:50 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-07-01 19:40:53 +03:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimelineItem::adjustMessageLayoutForWidget()
|
|
|
|
{
|
|
|
|
messageLayout_->addLayout(widgetLayout_, 1);
|
|
|
|
messageLayout_->addWidget(statusIndicator_);
|
|
|
|
messageLayout_->addWidget(timestamp_);
|
|
|
|
|
|
|
|
messageLayout_->setAlignment(statusIndicator_, Qt::AlignTop);
|
|
|
|
messageLayout_->setAlignment(timestamp_, Qt::AlignTop);
|
|
|
|
|
|
|
|
mainLayout_->addLayout(messageLayout_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimelineItem::adjustMessageLayout()
|
|
|
|
{
|
|
|
|
messageLayout_->addWidget(body_, 1);
|
|
|
|
messageLayout_->addWidget(statusIndicator_);
|
|
|
|
messageLayout_->addWidget(timestamp_);
|
|
|
|
|
|
|
|
messageLayout_->setAlignment(statusIndicator_, Qt::AlignTop);
|
|
|
|
messageLayout_->setAlignment(timestamp_, Qt::AlignTop);
|
|
|
|
|
|
|
|
mainLayout_->addLayout(messageLayout_);
|
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
TimelineItem::init()
|
2017-06-05 02:14:05 +03:00
|
|
|
{
|
2017-08-26 11:33:26 +03:00
|
|
|
userAvatar_ = nullptr;
|
|
|
|
timestamp_ = nullptr;
|
|
|
|
userName_ = nullptr;
|
|
|
|
body_ = nullptr;
|
2017-06-05 02:14:05 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
font_.setPixelSize(conf::fontSize);
|
2018-03-17 22:23:46 +03:00
|
|
|
usernameFont_ = font_;
|
|
|
|
usernameFont_.setWeight(60);
|
2017-06-05 02:14:05 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
QFontMetrics fm(font_);
|
2017-07-01 14:03:00 +03:00
|
|
|
|
2018-03-11 18:56:40 +03:00
|
|
|
contextMenu_ = new QMenu(this);
|
2018-01-03 19:05:49 +03:00
|
|
|
showReadReceipts_ = new QAction("Read receipts", this);
|
2018-03-11 18:56:40 +03:00
|
|
|
markAsRead_ = new QAction("Mark as read", this);
|
2018-03-17 22:23:46 +03:00
|
|
|
redactMsg_ = new QAction("Redact message", this);
|
2018-03-11 18:56:40 +03:00
|
|
|
contextMenu_->addAction(showReadReceipts_);
|
|
|
|
contextMenu_->addAction(markAsRead_);
|
2018-03-17 22:23:46 +03:00
|
|
|
contextMenu_->addAction(redactMsg_);
|
2018-03-11 18:56:40 +03:00
|
|
|
|
2018-02-20 18:09:11 +03:00
|
|
|
connect(showReadReceipts_, &QAction::triggered, this, [this]() {
|
2018-01-03 19:05:49 +03:00
|
|
|
if (!event_id_.isEmpty())
|
2018-08-11 13:50:56 +03:00
|
|
|
MainWindow::instance()->openReadReceiptsDialog(event_id_);
|
2018-01-03 19:05:49 +03:00
|
|
|
});
|
|
|
|
|
2018-06-09 16:03:14 +03:00
|
|
|
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);
|
|
|
|
});
|
2018-03-17 22:23:46 +03:00
|
|
|
connect(redactMsg_, &QAction::triggered, this, [this]() {
|
|
|
|
if (!event_id_.isEmpty())
|
2018-07-15 19:09:08 +03:00
|
|
|
http::client()->redact_event(
|
2018-06-09 16:03:14 +03:00
|
|
|
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_);
|
|
|
|
});
|
2018-03-17 22:23:46 +03:00
|
|
|
});
|
|
|
|
|
2018-03-11 18:56:40 +03:00
|
|
|
connect(markAsRead_, &QAction::triggered, this, [this]() { sendReadReceipt(); });
|
|
|
|
|
2018-01-14 13:29:54 +03:00
|
|
|
topLayout_ = new QHBoxLayout(this);
|
|
|
|
mainLayout_ = new QVBoxLayout;
|
|
|
|
messageLayout_ = new QHBoxLayout;
|
2018-04-29 20:39:22 +03:00
|
|
|
messageLayout_->setContentsMargins(0, 0, MSG_RIGHT_MARGIN, 0);
|
2018-03-19 21:26:14 +03:00
|
|
|
messageLayout_->setSpacing(MSG_PADDING);
|
2017-06-05 02:14:05 +03:00
|
|
|
|
2018-04-29 20:39:22 +03:00
|
|
|
topLayout_->setContentsMargins(
|
|
|
|
conf::timeline::msgLeftMargin, conf::timeline::msgTopMargin, 0, 0);
|
2017-08-26 11:33:26 +03:00
|
|
|
topLayout_->setSpacing(0);
|
2018-07-23 21:54:13 +03:00
|
|
|
topLayout_->addLayout(mainLayout_);
|
2017-07-01 12:46:58 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
mainLayout_->setContentsMargins(conf::timeline::headerLeftMargin, 0, 0, 0);
|
|
|
|
mainLayout_->setSpacing(0);
|
2018-02-05 04:22:55 +03:00
|
|
|
|
2018-07-01 19:40:53 +03:00
|
|
|
QFont timestampFont;
|
|
|
|
timestampFont.setPixelSize(conf::timeline::fonts::indicator);
|
|
|
|
QFontMetrics tsFm(timestampFont);
|
2018-02-07 07:52:21 +03:00
|
|
|
|
2018-07-01 19:40:53 +03:00
|
|
|
statusIndicator_ = new StatusIndicator(this);
|
|
|
|
statusIndicator_->setFixedWidth(tsFm.height() - tsFm.leading());
|
|
|
|
statusIndicator_->setFixedHeight(tsFm.height() - tsFm.leading());
|
2018-07-23 21:54:13 +03:00
|
|
|
|
|
|
|
parentWidget()->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
|
|
|
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
|
2017-06-05 02:14:05 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
/*
|
2017-09-03 11:43:45 +03:00
|
|
|
* For messages created locally.
|
2017-07-01 12:46:58 +03:00
|
|
|
*/
|
2017-12-04 19:41:19 +03:00
|
|
|
TimelineItem::TimelineItem(mtx::events::MessageType ty,
|
2017-09-03 11:43:45 +03:00
|
|
|
const QString &userid,
|
|
|
|
QString body,
|
|
|
|
bool withSender,
|
2018-04-21 16:34:50 +03:00
|
|
|
const QString &room_id,
|
2017-09-03 11:43:45 +03:00
|
|
|
QWidget *parent)
|
2017-08-20 13:47:22 +03:00
|
|
|
: QWidget(parent)
|
2018-04-21 16:34:50 +03:00
|
|
|
, room_id_{room_id}
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-08-26 11:33:26 +03:00
|
|
|
init();
|
2018-06-30 15:13:15 +03:00
|
|
|
addReplyAction();
|
2017-06-05 02:14:05 +03:00
|
|
|
|
2018-04-21 16:34:50 +03:00
|
|
|
auto displayName = Cache::displayName(room_id_, userid);
|
2017-09-03 11:43:45 +03:00
|
|
|
auto timestamp = QDateTime::currentDateTime();
|
2017-05-11 01:28:06 +03:00
|
|
|
|
2017-12-04 19:41:19 +03:00
|
|
|
if (ty == mtx::events::MessageType::Emote) {
|
2017-09-03 11:43:45 +03:00
|
|
|
body = QString("* %1 %2").arg(displayName).arg(body);
|
2018-01-05 01:27:32 +03:00
|
|
|
descriptionMsg_ = {"", userid, body, utils::descriptiveTime(timestamp), timestamp};
|
2017-09-03 11:43:45 +03:00
|
|
|
} else {
|
2018-01-05 01:27:32 +03:00
|
|
|
descriptionMsg_ = {
|
|
|
|
"You: ", userid, body, utils::descriptiveTime(timestamp), timestamp};
|
2017-09-03 11:43:45 +03:00
|
|
|
}
|
2017-06-05 02:14:05 +03:00
|
|
|
|
2017-09-22 22:12:36 +03:00
|
|
|
body = body.toHtmlEscaped();
|
2017-12-24 14:13:07 +03:00
|
|
|
body.replace(conf::strings::url_regex, conf::strings::url_html);
|
2017-11-06 03:23:19 +03:00
|
|
|
body.replace("\n", "<br/>");
|
2017-09-03 11:43:45 +03:00
|
|
|
generateTimestamp(timestamp);
|
|
|
|
|
|
|
|
if (withSender) {
|
2018-05-26 22:44:49 +03:00
|
|
|
generateBody(userid, displayName, body);
|
2017-09-03 11:43:45 +03:00
|
|
|
setupAvatarLayout(displayName);
|
2018-01-14 13:29:54 +03:00
|
|
|
|
2018-03-25 15:59:47 +03:00
|
|
|
AvatarProvider::resolve(
|
2018-04-21 16:34:50 +03:00
|
|
|
room_id_, userid, this, [this](const QImage &img) { setUserAvatar(img); });
|
2017-09-03 11:43:45 +03:00
|
|
|
} else {
|
|
|
|
generateBody(body);
|
|
|
|
setupSimpleLayout();
|
|
|
|
}
|
2017-06-05 02:14:05 +03:00
|
|
|
|
2018-07-01 19:40:53 +03:00
|
|
|
adjustMessageLayout();
|
2017-04-13 04:11:22 +03:00
|
|
|
}
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:58:00 +03:00
|
|
|
TimelineItem::TimelineItem(ImageItem *image,
|
|
|
|
const QString &userid,
|
|
|
|
bool withSender,
|
2018-04-21 16:34:50 +03:00
|
|
|
const QString &room_id,
|
2017-09-10 12:58:00 +03:00
|
|
|
QWidget *parent)
|
2017-11-06 00:04:55 +03:00
|
|
|
: QWidget{parent}
|
2018-04-21 16:34:50 +03:00
|
|
|
, room_id_{room_id}
|
2017-09-10 12:58:00 +03:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
|
2018-04-29 15:42:40 +03:00
|
|
|
setupLocalWidgetLayout<ImageItem>(image, userid, withSender);
|
2018-03-14 22:31:09 +03:00
|
|
|
|
|
|
|
addSaveImageAction(image);
|
2017-11-30 00:39:35 +03:00
|
|
|
}
|
2017-09-10 12:58:00 +03:00
|
|
|
|
2018-04-21 16:34:50 +03:00
|
|
|
TimelineItem::TimelineItem(FileItem *file,
|
|
|
|
const QString &userid,
|
|
|
|
bool withSender,
|
|
|
|
const QString &room_id,
|
|
|
|
QWidget *parent)
|
2017-11-30 00:39:35 +03:00
|
|
|
: QWidget{parent}
|
2018-04-21 16:34:50 +03:00
|
|
|
, room_id_{room_id}
|
2017-11-30 00:39:35 +03:00
|
|
|
{
|
|
|
|
init();
|
2017-09-10 12:58:00 +03:00
|
|
|
|
2018-04-29 15:42:40 +03:00
|
|
|
setupLocalWidgetLayout<FileItem>(file, userid, withSender);
|
2017-09-10 12:58:00 +03:00
|
|
|
}
|
|
|
|
|
2017-12-01 16:39:50 +03:00
|
|
|
TimelineItem::TimelineItem(AudioItem *audio,
|
|
|
|
const QString &userid,
|
|
|
|
bool withSender,
|
2018-04-21 16:34:50 +03:00
|
|
|
const QString &room_id,
|
2017-12-01 16:39:50 +03:00
|
|
|
QWidget *parent)
|
|
|
|
: QWidget{parent}
|
2018-04-21 16:34:50 +03:00
|
|
|
, room_id_{room_id}
|
2017-12-01 16:39:50 +03:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
|
2018-04-29 15:42:40 +03:00
|
|
|
setupLocalWidgetLayout<AudioItem>(audio, userid, withSender);
|
2017-12-01 16:39:50 +03:00
|
|
|
}
|
|
|
|
|
2017-12-01 19:28:26 +03:00
|
|
|
TimelineItem::TimelineItem(VideoItem *video,
|
|
|
|
const QString &userid,
|
|
|
|
bool withSender,
|
2018-04-21 16:34:50 +03:00
|
|
|
const QString &room_id,
|
2017-12-01 19:28:26 +03:00
|
|
|
QWidget *parent)
|
|
|
|
: QWidget{parent}
|
2018-04-21 16:34:50 +03:00
|
|
|
, room_id_{room_id}
|
2017-12-01 19:28:26 +03:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
|
2018-04-29 15:42:40 +03:00
|
|
|
setupLocalWidgetLayout<VideoItem>(video, userid, withSender);
|
2017-12-01 19:28:26 +03:00
|
|
|
}
|
|
|
|
|
2017-07-01 12:46:58 +03:00
|
|
|
TimelineItem::TimelineItem(ImageItem *image,
|
2017-12-04 19:41:19 +03:00
|
|
|
const mtx::events::RoomEvent<mtx::events::msg::Image> &event,
|
2017-08-26 11:33:26 +03:00
|
|
|
bool with_sender,
|
2018-04-21 16:34:50 +03:00
|
|
|
const QString &room_id,
|
2017-08-26 11:33:26 +03:00
|
|
|
QWidget *parent)
|
2017-08-20 13:47:22 +03:00
|
|
|
: QWidget(parent)
|
2018-04-21 16:34:50 +03:00
|
|
|
, room_id_{room_id}
|
2017-04-28 14:56:45 +03:00
|
|
|
{
|
2017-12-04 19:41:19 +03:00
|
|
|
setupWidgetLayout<mtx::events::RoomEvent<mtx::events::msg::Image>, ImageItem>(
|
2018-04-29 15:42:40 +03:00
|
|
|
image, event, with_sender);
|
2018-03-14 22:31:09 +03:00
|
|
|
|
2018-07-17 23:50:18 +03:00
|
|
|
markOwnMessagesAsReceived(event.sender);
|
|
|
|
|
2018-03-14 22:31:09 +03:00
|
|
|
addSaveImageAction(image);
|
2017-04-28 14:56:45 +03:00
|
|
|
}
|
|
|
|
|
2018-04-27 22:15:44 +03:00
|
|
|
TimelineItem::TimelineItem(StickerItem *image,
|
|
|
|
const mtx::events::Sticker &event,
|
|
|
|
bool with_sender,
|
|
|
|
const QString &room_id,
|
|
|
|
QWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
, room_id_{room_id}
|
|
|
|
{
|
2018-04-29 15:42:40 +03:00
|
|
|
setupWidgetLayout<mtx::events::Sticker, StickerItem>(image, event, with_sender);
|
2018-04-27 22:15:44 +03:00
|
|
|
|
2018-07-17 23:50:18 +03:00
|
|
|
markOwnMessagesAsReceived(event.sender);
|
|
|
|
|
2018-04-27 22:15:44 +03:00
|
|
|
addSaveImageAction(image);
|
|
|
|
}
|
|
|
|
|
2017-11-28 03:01:37 +03:00
|
|
|
TimelineItem::TimelineItem(FileItem *file,
|
2017-12-04 19:41:19 +03:00
|
|
|
const mtx::events::RoomEvent<mtx::events::msg::File> &event,
|
2017-11-28 03:01:37 +03:00
|
|
|
bool with_sender,
|
2018-04-21 16:34:50 +03:00
|
|
|
const QString &room_id,
|
2017-11-28 03:01:37 +03:00
|
|
|
QWidget *parent)
|
|
|
|
: QWidget(parent)
|
2018-04-21 16:34:50 +03:00
|
|
|
, room_id_{room_id}
|
2017-11-28 03:01:37 +03:00
|
|
|
{
|
2017-12-04 19:41:19 +03:00
|
|
|
setupWidgetLayout<mtx::events::RoomEvent<mtx::events::msg::File>, FileItem>(
|
2018-04-29 15:42:40 +03:00
|
|
|
file, event, with_sender);
|
2018-07-17 23:50:18 +03:00
|
|
|
|
|
|
|
markOwnMessagesAsReceived(event.sender);
|
2017-12-01 16:39:50 +03:00
|
|
|
}
|
2017-11-28 03:01:37 +03:00
|
|
|
|
2017-12-01 16:39:50 +03:00
|
|
|
TimelineItem::TimelineItem(AudioItem *audio,
|
2017-12-04 19:41:19 +03:00
|
|
|
const mtx::events::RoomEvent<mtx::events::msg::Audio> &event,
|
2017-12-01 16:39:50 +03:00
|
|
|
bool with_sender,
|
2018-04-21 16:34:50 +03:00
|
|
|
const QString &room_id,
|
2017-12-01 16:39:50 +03:00
|
|
|
QWidget *parent)
|
|
|
|
: QWidget(parent)
|
2018-04-21 16:34:50 +03:00
|
|
|
, room_id_{room_id}
|
2017-12-01 16:39:50 +03:00
|
|
|
{
|
2017-12-04 19:41:19 +03:00
|
|
|
setupWidgetLayout<mtx::events::RoomEvent<mtx::events::msg::Audio>, AudioItem>(
|
2018-04-29 15:42:40 +03:00
|
|
|
audio, event, with_sender);
|
2018-07-17 23:50:18 +03:00
|
|
|
|
|
|
|
markOwnMessagesAsReceived(event.sender);
|
2017-11-28 03:01:37 +03:00
|
|
|
}
|
|
|
|
|
2017-12-01 19:28:26 +03:00
|
|
|
TimelineItem::TimelineItem(VideoItem *video,
|
2017-12-04 19:41:19 +03:00
|
|
|
const mtx::events::RoomEvent<mtx::events::msg::Video> &event,
|
2017-12-01 19:28:26 +03:00
|
|
|
bool with_sender,
|
2018-04-21 16:34:50 +03:00
|
|
|
const QString &room_id,
|
2017-12-01 19:28:26 +03:00
|
|
|
QWidget *parent)
|
|
|
|
: QWidget(parent)
|
2018-04-21 16:34:50 +03:00
|
|
|
, room_id_{room_id}
|
2017-12-01 19:28:26 +03:00
|
|
|
{
|
2017-12-04 19:41:19 +03:00
|
|
|
setupWidgetLayout<mtx::events::RoomEvent<mtx::events::msg::Video>, VideoItem>(
|
2018-04-29 15:42:40 +03:00
|
|
|
video, event, with_sender);
|
2018-07-17 23:50:18 +03:00
|
|
|
|
|
|
|
markOwnMessagesAsReceived(event.sender);
|
2017-12-01 19:28:26 +03:00
|
|
|
}
|
|
|
|
|
2017-07-01 12:46:58 +03:00
|
|
|
/*
|
|
|
|
* Used to display remote notice messages.
|
|
|
|
*/
|
2017-12-04 19:41:19 +03:00
|
|
|
TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Notice> &event,
|
2017-08-26 11:33:26 +03:00
|
|
|
bool with_sender,
|
2018-04-21 16:34:50 +03:00
|
|
|
const QString &room_id,
|
2017-08-26 11:33:26 +03:00
|
|
|
QWidget *parent)
|
2017-08-20 13:47:22 +03:00
|
|
|
: QWidget(parent)
|
2018-04-21 16:34:50 +03:00
|
|
|
, room_id_{room_id}
|
2017-04-13 04:11:22 +03:00
|
|
|
{
|
2017-08-26 11:33:26 +03:00
|
|
|
init();
|
2018-06-30 15:13:15 +03:00
|
|
|
addReplyAction();
|
2017-11-24 01:10:58 +03:00
|
|
|
|
2018-07-17 23:50:18 +03:00
|
|
|
markOwnMessagesAsReceived(event.sender);
|
|
|
|
|
2017-12-26 00:02:33 +03:00
|
|
|
event_id_ = QString::fromStdString(event.event_id);
|
|
|
|
const auto sender = QString::fromStdString(event.sender);
|
|
|
|
const auto timestamp = QDateTime::fromMSecsSinceEpoch(event.origin_server_ts);
|
2018-09-06 22:34:41 +03:00
|
|
|
|
2018-09-07 14:52:29 +03:00
|
|
|
auto formatted_body = utils::linkifyMessage(utils::getMessageBody(event).trimmed());
|
2018-09-06 22:34:41 +03:00
|
|
|
auto body = QString::fromStdString(event.content.body).trimmed();
|
2017-11-24 01:10:58 +03:00
|
|
|
|
2018-04-21 16:34:50 +03:00
|
|
|
descriptionMsg_ = {Cache::displayName(room_id_, sender),
|
2017-12-04 19:41:19 +03:00
|
|
|
sender,
|
2017-11-06 00:04:55 +03:00
|
|
|
" sent a notification",
|
2018-01-05 01:27:32 +03:00
|
|
|
utils::descriptiveTime(timestamp),
|
2017-12-26 00:02:33 +03:00
|
|
|
timestamp};
|
2017-04-13 04:11:22 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
generateTimestamp(timestamp);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2018-09-06 22:34:41 +03:00
|
|
|
formatted_body = "<i>" + formatted_body + "</i>";
|
2017-05-07 17:15:38 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
if (with_sender) {
|
2018-04-21 16:34:50 +03:00
|
|
|
auto displayName = Cache::displayName(room_id_, sender);
|
2017-06-05 02:14:05 +03:00
|
|
|
|
2018-09-06 22:34:41 +03:00
|
|
|
generateBody(sender, displayName, formatted_body);
|
2017-08-26 11:33:26 +03:00
|
|
|
setupAvatarLayout(displayName);
|
2017-06-05 02:14:05 +03:00
|
|
|
|
2018-03-25 15:59:47 +03:00
|
|
|
AvatarProvider::resolve(
|
2018-04-21 16:34:50 +03:00
|
|
|
room_id_, sender, this, [this](const QImage &img) { setUserAvatar(img); });
|
2017-08-26 11:33:26 +03:00
|
|
|
} else {
|
2018-09-06 22:34:41 +03:00
|
|
|
generateBody(formatted_body);
|
2017-08-26 11:33:26 +03:00
|
|
|
setupSimpleLayout();
|
|
|
|
}
|
2017-07-01 12:46:58 +03:00
|
|
|
|
2018-07-01 19:40:53 +03:00
|
|
|
adjustMessageLayout();
|
2017-05-07 17:15:38 +03:00
|
|
|
}
|
|
|
|
|
2017-09-02 16:47:59 +03:00
|
|
|
/*
|
|
|
|
* Used to display remote emote messages.
|
|
|
|
*/
|
2017-12-04 19:41:19 +03:00
|
|
|
TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Emote> &event,
|
2017-09-02 16:47:59 +03:00
|
|
|
bool with_sender,
|
2018-04-21 16:34:50 +03:00
|
|
|
const QString &room_id,
|
2017-09-02 16:47:59 +03:00
|
|
|
QWidget *parent)
|
|
|
|
: QWidget(parent)
|
2018-04-21 16:34:50 +03:00
|
|
|
, room_id_{room_id}
|
2017-09-02 16:47:59 +03:00
|
|
|
{
|
|
|
|
init();
|
2018-06-30 15:13:15 +03:00
|
|
|
addReplyAction();
|
2017-09-02 16:47:59 +03:00
|
|
|
|
2018-07-17 23:50:18 +03:00
|
|
|
markOwnMessagesAsReceived(event.sender);
|
|
|
|
|
2017-12-04 19:41:19 +03:00
|
|
|
event_id_ = QString::fromStdString(event.event_id);
|
|
|
|
const auto sender = QString::fromStdString(event.sender);
|
2017-11-24 01:10:58 +03:00
|
|
|
|
2018-09-07 14:52:29 +03:00
|
|
|
auto formatted_body = utils::linkifyMessage(utils::getMessageBody(event).trimmed());
|
2018-09-06 22:34:41 +03:00
|
|
|
auto body = QString::fromStdString(event.content.body).trimmed();
|
|
|
|
|
2017-12-04 19:41:19 +03:00
|
|
|
auto timestamp = QDateTime::fromMSecsSinceEpoch(event.origin_server_ts);
|
2018-04-21 16:34:50 +03:00
|
|
|
auto displayName = Cache::displayName(room_id_, sender);
|
2018-09-06 22:34:41 +03:00
|
|
|
auto emoteMsg = QString("* %1 %2").arg(displayName).arg(formatted_body);
|
2017-09-02 16:47:59 +03:00
|
|
|
|
2018-01-05 01:27:32 +03:00
|
|
|
descriptionMsg_ = {"", sender, emoteMsg, utils::descriptiveTime(timestamp), timestamp};
|
2017-09-02 16:47:59 +03:00
|
|
|
|
|
|
|
generateTimestamp(timestamp);
|
|
|
|
|
|
|
|
if (with_sender) {
|
2018-09-06 22:34:41 +03:00
|
|
|
generateBody(sender, displayName, formatted_body);
|
2017-09-02 16:47:59 +03:00
|
|
|
setupAvatarLayout(displayName);
|
2018-01-14 13:29:54 +03:00
|
|
|
|
2018-03-25 15:59:47 +03:00
|
|
|
AvatarProvider::resolve(
|
2018-04-21 16:34:50 +03:00
|
|
|
room_id_, sender, this, [this](const QImage &img) { setUserAvatar(img); });
|
2017-09-02 16:47:59 +03:00
|
|
|
} else {
|
2018-09-06 22:34:41 +03:00
|
|
|
generateBody(formatted_body);
|
2017-09-02 16:47:59 +03:00
|
|
|
setupSimpleLayout();
|
|
|
|
}
|
|
|
|
|
2018-07-01 19:40:53 +03:00
|
|
|
adjustMessageLayout();
|
2017-09-02 16:47:59 +03:00
|
|
|
}
|
|
|
|
|
2017-07-01 12:46:58 +03:00
|
|
|
/*
|
|
|
|
* Used to display remote text messages.
|
|
|
|
*/
|
2017-12-04 19:41:19 +03:00
|
|
|
TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Text> &event,
|
2017-08-26 11:33:26 +03:00
|
|
|
bool with_sender,
|
2018-04-21 16:34:50 +03:00
|
|
|
const QString &room_id,
|
2017-08-26 11:33:26 +03:00
|
|
|
QWidget *parent)
|
2017-08-20 13:47:22 +03:00
|
|
|
: QWidget(parent)
|
2018-04-21 16:34:50 +03:00
|
|
|
, room_id_{room_id}
|
2017-05-07 17:15:38 +03:00
|
|
|
{
|
2017-08-26 11:33:26 +03:00
|
|
|
init();
|
2018-06-30 15:13:15 +03:00
|
|
|
addReplyAction();
|
2017-06-05 02:14:05 +03:00
|
|
|
|
2018-07-17 23:50:18 +03:00
|
|
|
markOwnMessagesAsReceived(event.sender);
|
|
|
|
|
2017-12-04 19:41:19 +03:00
|
|
|
event_id_ = QString::fromStdString(event.event_id);
|
|
|
|
const auto sender = QString::fromStdString(event.sender);
|
2017-11-24 01:10:58 +03:00
|
|
|
|
2018-09-07 14:52:29 +03:00
|
|
|
auto formatted_body = utils::linkifyMessage(utils::getMessageBody(event).trimmed());
|
2018-09-06 22:34:41 +03:00
|
|
|
auto body = QString::fromStdString(event.content.body).trimmed();
|
|
|
|
|
2017-12-04 19:41:19 +03:00
|
|
|
auto timestamp = QDateTime::fromMSecsSinceEpoch(event.origin_server_ts);
|
2018-04-21 16:34:50 +03:00
|
|
|
auto displayName = Cache::displayName(room_id_, sender);
|
2017-05-07 17:15:38 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
QSettings settings;
|
2017-12-04 19:41:19 +03:00
|
|
|
descriptionMsg_ = {sender == settings.value("auth/user_id") ? "You" : displayName,
|
|
|
|
sender,
|
2017-11-06 00:04:55 +03:00
|
|
|
QString(": %1").arg(body),
|
2018-01-05 01:27:32 +03:00
|
|
|
utils::descriptiveTime(timestamp),
|
2017-12-26 00:02:33 +03:00
|
|
|
timestamp};
|
2017-08-06 18:53:31 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
generateTimestamp(timestamp);
|
2017-04-12 00:52:56 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
if (with_sender) {
|
2018-09-06 22:34:41 +03:00
|
|
|
generateBody(sender, displayName, formatted_body);
|
2017-08-26 11:33:26 +03:00
|
|
|
setupAvatarLayout(displayName);
|
2017-06-05 02:14:05 +03:00
|
|
|
|
2018-03-25 15:59:47 +03:00
|
|
|
AvatarProvider::resolve(
|
2018-04-21 16:34:50 +03:00
|
|
|
room_id_, sender, this, [this](const QImage &img) { setUserAvatar(img); });
|
2017-08-26 11:33:26 +03:00
|
|
|
} else {
|
2018-09-06 22:34:41 +03:00
|
|
|
generateBody(formatted_body);
|
2017-08-26 11:33:26 +03:00
|
|
|
setupSimpleLayout();
|
|
|
|
}
|
2017-07-01 12:46:58 +03:00
|
|
|
|
2018-07-01 19:40:53 +03:00
|
|
|
adjustMessageLayout();
|
2017-04-13 04:11:22 +03:00
|
|
|
}
|
|
|
|
|
2018-01-14 13:54:17 +03:00
|
|
|
void
|
2018-07-01 19:40:53 +03:00
|
|
|
TimelineItem::markSent()
|
|
|
|
{
|
|
|
|
statusIndicator_->setState(StatusIndicatorState::Sent);
|
|
|
|
}
|
|
|
|
|
2018-07-17 23:50:18 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-07-01 19:40:53 +03:00
|
|
|
void
|
|
|
|
TimelineItem::markReceived(bool isEncrypted)
|
2018-01-14 13:54:17 +03:00
|
|
|
{
|
2018-06-17 02:29:19 +03:00
|
|
|
isReceived_ = true;
|
2018-07-01 19:40:53 +03:00
|
|
|
|
|
|
|
if (isEncrypted)
|
|
|
|
statusIndicator_->setState(StatusIndicatorState::Encrypted);
|
|
|
|
else
|
|
|
|
statusIndicator_->setState(StatusIndicatorState::Received);
|
2018-03-11 18:56:40 +03:00
|
|
|
|
|
|
|
sendReadReceipt();
|
2018-01-14 13:54:17 +03:00
|
|
|
}
|
|
|
|
|
2017-06-05 02:14:05 +03:00
|
|
|
// Only the body is displayed.
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
TimelineItem::generateBody(const QString &body)
|
2017-04-13 04:11:22 +03:00
|
|
|
{
|
2018-05-26 17:05:57 +03:00
|
|
|
if (body.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2018-01-23 19:14:13 +03:00
|
|
|
QString content("<span>%1</span>");
|
2017-06-05 02:14:05 +03:00
|
|
|
|
2018-05-23 16:33:30 +03:00
|
|
|
body_ = new TextLabel(content.arg(replaceEmoji(body)), this);
|
2017-08-26 11:33:26 +03:00
|
|
|
body_->setFont(font_);
|
|
|
|
body_->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextBrowserInteraction);
|
2017-04-13 04:11:22 +03:00
|
|
|
}
|
|
|
|
|
2017-06-05 02:14:05 +03:00
|
|
|
// The username/timestamp is displayed along with the message body.
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
2018-05-26 22:44:49 +03:00
|
|
|
TimelineItem::generateBody(const QString &user_id, const QString &displayname, const QString &body)
|
2018-07-20 12:02:35 +03:00
|
|
|
{
|
|
|
|
generateUserName(user_id, displayname);
|
|
|
|
generateBody(body);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimelineItem::generateUserName(const QString &user_id, const QString &displayname)
|
2017-04-13 04:11:22 +03:00
|
|
|
{
|
2018-05-26 22:44:49 +03:00
|
|
|
auto sender = displayname;
|
2017-05-08 19:44:01 +03:00
|
|
|
|
2018-05-26 22:44:49 +03:00
|
|
|
if (displayname.startsWith("@")) {
|
2017-09-28 22:26:24 +03:00
|
|
|
// TODO: Fix this by using a UserId type.
|
2018-05-26 22:44:49 +03:00
|
|
|
if (displayname.split(":")[0].split("@").size() > 1)
|
|
|
|
sender = displayname.split(":")[0].split("@")[1];
|
2017-09-28 22:26:24 +03:00
|
|
|
}
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2018-03-17 22:23:46 +03:00
|
|
|
QFontMetrics fm(usernameFont_);
|
2017-12-23 15:06:59 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
userName_ = new QLabel(this);
|
2018-03-17 22:23:46 +03:00
|
|
|
userName_->setFont(usernameFont_);
|
2017-12-23 15:06:59 +03:00
|
|
|
userName_->setText(fm.elidedText(sender, Qt::ElideRight, 500));
|
2018-05-26 22:44:49 +03:00
|
|
|
userName_->setToolTip(user_id);
|
|
|
|
userName_->setToolTipDuration(1500);
|
|
|
|
userName_->setAttribute(Qt::WA_Hover);
|
2018-07-23 21:54:13 +03:00
|
|
|
userName_->setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
2018-05-26 22:44:49 +03:00
|
|
|
userName_->setFixedWidth(QFontMetrics(userName_->font()).width(userName_->text()));
|
|
|
|
|
|
|
|
auto filter = new UserProfileFilter(user_id, userName_);
|
|
|
|
userName_->installEventFilter(filter);
|
2018-08-29 16:00:07 +03:00
|
|
|
userName_->setCursor(Qt::PointingHandCursor);
|
2018-05-26 22:44:49 +03:00
|
|
|
|
|
|
|
connect(filter, &UserProfileFilter::hoverOn, this, [this]() {
|
|
|
|
QFont f = userName_->font();
|
|
|
|
f.setUnderline(true);
|
|
|
|
userName_->setFont(f);
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(filter, &UserProfileFilter::hoverOff, this, [this]() {
|
|
|
|
QFont f = userName_->font();
|
|
|
|
f.setUnderline(false);
|
|
|
|
userName_->setFont(f);
|
|
|
|
});
|
2017-04-13 04:11:22 +03:00
|
|
|
|
2018-07-20 12:02:35 +03:00
|
|
|
connect(filter, &UserProfileFilter::clicked, this, [this, user_id]() {
|
|
|
|
MainWindow::instance()->openUserProfile(user_id, room_id_);
|
|
|
|
});
|
2017-06-05 02:14:05 +03:00
|
|
|
}
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
TimelineItem::generateTimestamp(const QDateTime &time)
|
2017-06-05 02:14:05 +03:00
|
|
|
{
|
2017-08-26 11:33:26 +03:00
|
|
|
QFont timestampFont;
|
|
|
|
timestampFont.setPixelSize(conf::timeline::fonts::timestamp);
|
2017-07-01 12:46:58 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
timestamp_ = new QLabel(this);
|
|
|
|
timestamp_->setFont(timestampFont);
|
2018-01-14 13:29:54 +03:00
|
|
|
timestamp_->setText(
|
|
|
|
QString("<span style=\"color: #999\"> %1 </span>").arg(time.toString("HH:mm")));
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
QString
|
|
|
|
TimelineItem::replaceEmoji(const QString &body)
|
2017-04-19 19:38:39 +03:00
|
|
|
{
|
2017-08-26 11:33:26 +03:00
|
|
|
QString fmtBody = "";
|
|
|
|
|
2017-10-02 20:52:21 +03:00
|
|
|
QVector<uint> utf32_string = body.toUcs4();
|
2017-08-26 11:33:26 +03:00
|
|
|
|
2017-10-02 20:52:21 +03:00
|
|
|
for (auto &code : utf32_string) {
|
2017-08-26 11:33:26 +03:00
|
|
|
// TODO: Be more precise here.
|
|
|
|
if (code > 9000)
|
|
|
|
fmtBody += QString("<span style=\"font-family: Emoji "
|
|
|
|
"One; font-size: %1px\">")
|
|
|
|
.arg(conf::emojiSize) +
|
2017-10-02 20:52:21 +03:00
|
|
|
QString::fromUcs4(&code, 1) + "</span>";
|
2017-08-26 11:33:26 +03:00
|
|
|
else
|
2017-10-02 20:52:21 +03:00
|
|
|
fmtBody += QString::fromUcs4(&code, 1);
|
2017-08-26 11:33:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return fmtBody;
|
2017-04-19 19:38:39 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
TimelineItem::setupAvatarLayout(const QString &userName)
|
2017-06-05 02:14:05 +03:00
|
|
|
{
|
2018-04-29 20:39:22 +03:00
|
|
|
topLayout_->setContentsMargins(
|
|
|
|
conf::timeline::msgLeftMargin, conf::timeline::msgAvatarTopMargin, 0, 0);
|
2017-06-05 02:14:05 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
userAvatar_ = new Avatar(this);
|
|
|
|
userAvatar_->setLetter(QChar(userName[0]).toUpper());
|
|
|
|
userAvatar_->setSize(conf::timeline::avatarSize);
|
2017-06-05 02:14:05 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
// TODO: The provided user name should be a UserId class
|
|
|
|
if (userName[0] == '@' && userName.size() > 1)
|
|
|
|
userAvatar_->setLetter(QChar(userName[1]).toUpper());
|
2017-06-05 02:14:05 +03:00
|
|
|
|
2018-03-17 22:23:46 +03:00
|
|
|
topLayout_->insertWidget(0, userAvatar_);
|
2018-07-23 21:54:13 +03:00
|
|
|
topLayout_->setAlignment(userAvatar_, Qt::AlignTop | Qt::AlignLeft);
|
2017-06-05 02:14:05 +03:00
|
|
|
|
2018-05-26 17:05:57 +03:00
|
|
|
if (userName_)
|
2018-07-23 21:54:13 +03:00
|
|
|
mainLayout_->insertWidget(0, userName_, Qt::AlignTop | Qt::AlignLeft);
|
2017-06-05 02:14:05 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
TimelineItem::setupSimpleLayout()
|
2017-06-05 02:14:05 +03:00
|
|
|
{
|
2018-04-29 20:39:22 +03:00
|
|
|
topLayout_->setContentsMargins(conf::timeline::msgLeftMargin + conf::timeline::avatarSize +
|
|
|
|
2,
|
|
|
|
conf::timeline::msgTopMargin,
|
2018-01-14 13:29:54 +03:00
|
|
|
0,
|
|
|
|
0);
|
2017-06-05 02:14:05 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
TimelineItem::setUserAvatar(const QImage &avatar)
|
2017-06-05 02:14:05 +03:00
|
|
|
{
|
2017-08-26 11:33:26 +03:00
|
|
|
if (userAvatar_ == nullptr)
|
|
|
|
return;
|
2017-06-05 02:14:05 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
userAvatar_->setImage(avatar);
|
2017-06-05 02:14:05 +03:00
|
|
|
}
|
|
|
|
|
2018-01-03 19:05:49 +03:00
|
|
|
void
|
|
|
|
TimelineItem::contextMenuEvent(QContextMenuEvent *event)
|
|
|
|
{
|
2018-03-11 18:56:40 +03:00
|
|
|
if (contextMenu_)
|
|
|
|
contextMenu_->exec(event->globalPos());
|
2018-01-03 19:05:49 +03:00
|
|
|
}
|
|
|
|
|
2017-11-16 17:33:52 +03:00
|
|
|
void
|
|
|
|
TimelineItem::paintEvent(QPaintEvent *)
|
|
|
|
{
|
|
|
|
QStyleOption opt;
|
|
|
|
opt.init(this);
|
|
|
|
QPainter p(this);
|
|
|
|
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
|
|
|
}
|
2018-03-14 22:31:09 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
TimelineItem::addSaveImageAction(ImageItem *image)
|
|
|
|
{
|
|
|
|
if (contextMenu_) {
|
|
|
|
auto saveImage = new QAction("Save image", this);
|
|
|
|
contextMenu_->addAction(saveImage);
|
|
|
|
|
|
|
|
connect(saveImage, &QAction::triggered, image, &ImageItem::saveAs);
|
|
|
|
}
|
|
|
|
}
|
2018-03-17 22:23:46 +03:00
|
|
|
|
2018-06-30 15:13:15 +03:00
|
|
|
void
|
|
|
|
TimelineItem::addReplyAction()
|
|
|
|
{
|
|
|
|
if (contextMenu_) {
|
|
|
|
auto replyAction = new QAction("Reply", this);
|
|
|
|
contextMenu_->addAction(replyAction);
|
|
|
|
|
|
|
|
connect(replyAction, &QAction::triggered, this, [this]() {
|
|
|
|
if (!body_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
emit ChatPage::instance()->messageReply(
|
|
|
|
Cache::displayName(room_id_, descriptionMsg_.userid),
|
|
|
|
body_->toPlainText());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-07 23:59:23 +03:00
|
|
|
void
|
|
|
|
TimelineItem::addKeyRequestAction()
|
|
|
|
{
|
|
|
|
if (contextMenu_) {
|
|
|
|
auto requestKeys = new QAction("Request encryption keys", this);
|
|
|
|
contextMenu_->addAction(requestKeys);
|
|
|
|
|
|
|
|
connect(requestKeys, &QAction::triggered, this, [this]() {
|
|
|
|
olm::request_keys(room_id_.toStdString(), event_id_.toStdString());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-17 22:23:46 +03:00
|
|
|
void
|
|
|
|
TimelineItem::addAvatar()
|
|
|
|
{
|
|
|
|
if (userAvatar_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// TODO: should be replaced with the proper event struct.
|
|
|
|
auto userid = descriptionMsg_.userid;
|
2018-04-21 16:34:50 +03:00
|
|
|
auto displayName = Cache::displayName(room_id_, userid);
|
2018-03-17 22:23:46 +03:00
|
|
|
|
2018-07-20 12:02:35 +03:00
|
|
|
generateUserName(userid, displayName);
|
2018-03-17 22:23:46 +03:00
|
|
|
|
|
|
|
setupAvatarLayout(displayName);
|
|
|
|
|
2018-04-21 16:34:50 +03:00
|
|
|
AvatarProvider::resolve(
|
|
|
|
room_id_, userid, this, [this](const QImage &img) { setUserAvatar(img); });
|
2018-03-17 22:23:46 +03:00
|
|
|
}
|
2018-06-14 02:28:35 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
TimelineItem::sendReadReceipt() const
|
|
|
|
{
|
|
|
|
if (!event_id_.isEmpty())
|
2018-07-15 19:09:08 +03:00
|
|
|
http::client()->read_event(room_id_.toStdString(),
|
|
|
|
event_id_.toStdString(),
|
|
|
|
[this](mtx::http::RequestErr err) {
|
|
|
|
if (err) {
|
|
|
|
nhlog::net()->warn(
|
|
|
|
"failed to read_event ({}, {})",
|
|
|
|
room_id_.toStdString(),
|
|
|
|
event_id_.toStdString());
|
|
|
|
}
|
|
|
|
});
|
2018-06-14 02:28:35 +03:00
|
|
|
}
|