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/>.
|
|
|
|
*/
|
|
|
|
|
2017-10-21 18:53:15 +03:00
|
|
|
#include <QApplication>
|
2017-11-15 19:38:50 +03:00
|
|
|
#include <QFileInfo>
|
2017-10-28 15:46:39 +03:00
|
|
|
#include <QTimer>
|
2017-05-07 17:15:38 +03:00
|
|
|
|
2017-12-26 00:02:33 +03:00
|
|
|
#include "Config.h"
|
2017-10-27 22:20:33 +03:00
|
|
|
#include "FloatingButton.h"
|
2017-10-28 15:46:39 +03:00
|
|
|
#include "RoomMessages.h"
|
2018-01-05 01:27:32 +03:00
|
|
|
#include "Utils.h"
|
2017-11-30 14:53:28 +03:00
|
|
|
|
|
|
|
#include "timeline/TimelineView.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 16:39:50 +03:00
|
|
|
#include "timeline/widgets/VideoItem.h"
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2018-01-05 01:27:32 +03:00
|
|
|
using TimelineEvent = mtx::events::collections::TimelineEvents;
|
|
|
|
|
2017-12-04 19:41:19 +03:00
|
|
|
TimelineView::TimelineView(const mtx::responses::Timeline &timeline,
|
2017-08-26 11:33:26 +03:00
|
|
|
QSharedPointer<MatrixClient> client,
|
|
|
|
const QString &room_id,
|
|
|
|
QWidget *parent)
|
2017-08-20 13:47:22 +03:00
|
|
|
: QWidget(parent)
|
2017-11-06 00:04:55 +03:00
|
|
|
, room_id_{room_id}
|
|
|
|
, client_{client}
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-08-26 11:33:26 +03:00
|
|
|
init();
|
|
|
|
addEvents(timeline);
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
TimelineView::TimelineView(QSharedPointer<MatrixClient> client,
|
|
|
|
const QString &room_id,
|
|
|
|
QWidget *parent)
|
2017-08-20 13:47:22 +03:00
|
|
|
: QWidget(parent)
|
2017-11-06 00:04:55 +03:00
|
|
|
, room_id_{room_id}
|
|
|
|
, client_{client}
|
2017-07-29 11:49:00 +03:00
|
|
|
{
|
2017-08-26 11:33:26 +03:00
|
|
|
init();
|
2017-12-30 19:16:11 +03:00
|
|
|
client_->messages(room_id_, "");
|
2017-07-29 11:49:00 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
TimelineView::sliderRangeChanged(int min, int max)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-08-26 11:33:26 +03:00
|
|
|
Q_UNUSED(min);
|
2017-05-12 15:43:35 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
if (!scroll_area_->verticalScrollBar()->isVisible()) {
|
|
|
|
scroll_area_->verticalScrollBar()->setValue(max);
|
|
|
|
return;
|
|
|
|
}
|
2017-05-12 15:43:35 +03:00
|
|
|
|
2017-09-30 22:26:33 +03:00
|
|
|
// If the scrollbar is close to the bottom and a new message
|
|
|
|
// is added we move the scrollbar.
|
2017-10-09 13:59:44 +03:00
|
|
|
if (max - scroll_area_->verticalScrollBar()->value() < SCROLL_BAR_GAP) {
|
2017-08-26 11:33:26 +03:00
|
|
|
scroll_area_->verticalScrollBar()->setValue(max);
|
2017-10-09 13:59:44 +03:00
|
|
|
return;
|
|
|
|
}
|
2017-06-05 19:21:19 +03:00
|
|
|
|
2017-10-09 01:32:25 +03:00
|
|
|
int currentHeight = scroll_widget_->size().height();
|
|
|
|
int diff = currentHeight - oldHeight_;
|
|
|
|
int newPosition = oldPosition_ + diff;
|
2017-06-05 19:21:19 +03:00
|
|
|
|
2017-10-09 01:32:25 +03:00
|
|
|
// Keep the scroll bar to the bottom if it hasn't been activated yet.
|
|
|
|
if (oldPosition_ == 0 && !scroll_area_->verticalScrollBar()->isVisible())
|
|
|
|
newPosition = max;
|
2017-07-29 11:49:00 +03:00
|
|
|
|
2017-10-27 13:36:26 +03:00
|
|
|
if (lastMessageDirection_ == TimelineDirection::Top)
|
|
|
|
scroll_area_->verticalScrollBar()->setValue(newPosition);
|
2017-07-29 11:49:00 +03:00
|
|
|
}
|
2017-06-05 19:21:19 +03:00
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
TimelineView::fetchHistory()
|
2017-07-29 11:49:00 +03:00
|
|
|
{
|
2017-12-23 14:50:11 +03:00
|
|
|
if (!isScrollbarActivated() && !isTimelineFinished) {
|
|
|
|
if (!isVisible()) {
|
|
|
|
// Check again later if the timeline became visible.
|
|
|
|
// TODO: Use a backoff strategy.
|
|
|
|
paginationTimer_->start(3000);
|
|
|
|
return;
|
|
|
|
}
|
2017-07-29 11:49:00 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
isPaginationInProgress_ = true;
|
|
|
|
client_->messages(room_id_, prev_batch_token_);
|
2017-12-23 14:50:11 +03:00
|
|
|
paginationTimer_->start(1500);
|
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
return;
|
|
|
|
}
|
2017-08-05 15:59:24 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
paginationTimer_->stop();
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
TimelineView::scrollDown()
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-08-26 11:33:26 +03:00
|
|
|
int current = scroll_area_->verticalScrollBar()->value();
|
|
|
|
int max = scroll_area_->verticalScrollBar()->maximum();
|
|
|
|
|
|
|
|
// The first time we enter the room move the scroll bar to the bottom.
|
|
|
|
if (!isInitialized) {
|
|
|
|
scroll_area_->verticalScrollBar()->setValue(max);
|
|
|
|
isInitialized = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the gap is small enough move the scroll bar down. e.g when a new
|
|
|
|
// message appears.
|
|
|
|
if (max - current < SCROLL_BAR_GAP)
|
|
|
|
scroll_area_->verticalScrollBar()->setValue(max);
|
2017-05-12 15:43:35 +03:00
|
|
|
}
|
2017-04-15 02:56:04 +03:00
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
TimelineView::sliderMoved(int position)
|
2017-05-12 15:43:35 +03:00
|
|
|
{
|
2017-08-26 11:33:26 +03:00
|
|
|
if (!scroll_area_->verticalScrollBar()->isVisible())
|
|
|
|
return;
|
|
|
|
|
2017-10-27 22:20:33 +03:00
|
|
|
const int maxScroll = scroll_area_->verticalScrollBar()->maximum();
|
|
|
|
const int currentScroll = scroll_area_->verticalScrollBar()->value();
|
|
|
|
|
|
|
|
if (maxScroll - currentScroll > SCROLL_BAR_GAP) {
|
|
|
|
scrollDownBtn_->show();
|
|
|
|
scrollDownBtn_->raise();
|
|
|
|
} else {
|
|
|
|
scrollDownBtn_->hide();
|
|
|
|
}
|
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
// The scrollbar is high enough so we can start retrieving old events.
|
|
|
|
if (position < SCROLL_BAR_GAP) {
|
|
|
|
if (isTimelineFinished)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Prevent user from moving up when there is pagination in
|
|
|
|
// progress.
|
|
|
|
// TODO: Keep a map of the event ids to filter out duplicates.
|
|
|
|
if (isPaginationInProgress_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
isPaginationInProgress_ = true;
|
|
|
|
|
|
|
|
// FIXME: Maybe move this to TimelineViewManager to remove the
|
|
|
|
// extra calls?
|
|
|
|
client_->messages(room_id_, prev_batch_token_);
|
|
|
|
}
|
2017-05-12 15:43:35 +03:00
|
|
|
}
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
2017-12-04 19:41:19 +03:00
|
|
|
TimelineView::addBackwardsEvents(const QString &room_id, const mtx::responses::Messages &msgs)
|
2017-05-12 15:43:35 +03:00
|
|
|
{
|
2017-08-26 11:33:26 +03:00
|
|
|
if (room_id_ != room_id)
|
|
|
|
return;
|
2017-04-15 02:56:04 +03:00
|
|
|
|
2017-12-04 19:41:19 +03:00
|
|
|
if (msgs.chunk.size() == 0) {
|
2017-08-26 11:33:26 +03:00
|
|
|
isTimelineFinished = true;
|
|
|
|
return;
|
|
|
|
}
|
2017-05-12 15:43:35 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
isTimelineFinished = false;
|
|
|
|
QList<TimelineItem *> items;
|
2017-05-12 15:43:35 +03:00
|
|
|
|
2017-11-03 15:25:01 +03:00
|
|
|
// Reset the sender of the first message in the timeline
|
|
|
|
// cause we're about to insert a new one.
|
|
|
|
firstSender_.clear();
|
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
// Parse in reverse order to determine where we should not show sender's
|
|
|
|
// name.
|
2017-12-04 19:41:19 +03:00
|
|
|
auto ii = msgs.chunk.size();
|
2017-09-22 21:34:31 +03:00
|
|
|
while (ii != 0) {
|
|
|
|
--ii;
|
2017-05-12 15:43:35 +03:00
|
|
|
|
2017-12-04 19:41:19 +03:00
|
|
|
TimelineItem *item = parseMessageEvent(msgs.chunk[ii], TimelineDirection::Top);
|
2017-05-12 15:43:35 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
if (item != nullptr)
|
|
|
|
items.push_back(item);
|
|
|
|
}
|
2017-05-12 15:43:35 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
// Reverse again to render them.
|
|
|
|
std::reverse(items.begin(), items.end());
|
2017-05-12 15:43:35 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
oldPosition_ = scroll_area_->verticalScrollBar()->value();
|
|
|
|
oldHeight_ = scroll_widget_->size().height();
|
2017-06-05 19:21:19 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
for (const auto &item : items)
|
|
|
|
addTimelineItem(item, TimelineDirection::Top);
|
2017-04-28 14:56:45 +03:00
|
|
|
|
2017-10-27 13:36:26 +03:00
|
|
|
lastMessageDirection_ = TimelineDirection::Top;
|
|
|
|
|
2017-10-21 18:53:15 +03:00
|
|
|
QApplication::processEvents();
|
|
|
|
|
2017-12-04 19:41:19 +03:00
|
|
|
prev_batch_token_ = QString::fromStdString(msgs.end);
|
2017-10-09 01:32:25 +03:00
|
|
|
isPaginationInProgress_ = false;
|
2017-08-06 18:53:31 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
// Exclude the top stretch.
|
2017-12-04 19:41:19 +03:00
|
|
|
if (msgs.chunk.size() != 0 && scroll_layout_->count() > 1)
|
2017-08-26 11:33:26 +03:00
|
|
|
notifyForLastEvent();
|
2017-08-14 00:26:57 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
// If this batch is the first being rendered (i.e the first and the last
|
|
|
|
// events originate from this batch), set the last sender.
|
|
|
|
if (lastSender_.isEmpty() && !items.isEmpty())
|
|
|
|
lastSender_ = items.constFirst()->descriptionMessage().userid;
|
2017-05-12 15:43:35 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
TimelineItem *
|
2017-12-04 19:41:19 +03:00
|
|
|
TimelineView::parseMessageEvent(const mtx::events::collections::TimelineEvents &event,
|
|
|
|
TimelineDirection direction)
|
2017-05-12 15:43:35 +03:00
|
|
|
{
|
2017-12-04 19:41:19 +03:00
|
|
|
namespace msg = mtx::events::msg;
|
|
|
|
using AudioEvent = mtx::events::RoomEvent<msg::Audio>;
|
|
|
|
using EmoteEvent = mtx::events::RoomEvent<msg::Emote>;
|
|
|
|
using FileEvent = mtx::events::RoomEvent<msg::File>;
|
|
|
|
using ImageEvent = mtx::events::RoomEvent<msg::Image>;
|
|
|
|
using NoticeEvent = mtx::events::RoomEvent<msg::Notice>;
|
|
|
|
using TextEvent = mtx::events::RoomEvent<msg::Text>;
|
|
|
|
using VideoEvent = mtx::events::RoomEvent<msg::Video>;
|
|
|
|
|
|
|
|
if (mpark::holds_alternative<mtx::events::RoomEvent<msg::Audio>>(event)) {
|
|
|
|
auto audio = mpark::get<mtx::events::RoomEvent<msg::Audio>>(event);
|
|
|
|
return processMessageEvent<AudioEvent, AudioItem>(audio, direction);
|
|
|
|
} else if (mpark::holds_alternative<mtx::events::RoomEvent<msg::Emote>>(event)) {
|
|
|
|
auto emote = mpark::get<mtx::events::RoomEvent<msg::Emote>>(event);
|
|
|
|
return processMessageEvent<EmoteEvent>(emote, direction);
|
|
|
|
} else if (mpark::holds_alternative<mtx::events::RoomEvent<msg::File>>(event)) {
|
|
|
|
auto file = mpark::get<mtx::events::RoomEvent<msg::File>>(event);
|
|
|
|
return processMessageEvent<FileEvent, FileItem>(file, direction);
|
|
|
|
} else if (mpark::holds_alternative<mtx::events::RoomEvent<msg::Image>>(event)) {
|
|
|
|
auto image = mpark::get<mtx::events::RoomEvent<msg::Image>>(event);
|
|
|
|
return processMessageEvent<ImageEvent, ImageItem>(image, direction);
|
|
|
|
} else if (mpark::holds_alternative<mtx::events::RoomEvent<msg::Notice>>(event)) {
|
|
|
|
auto notice = mpark::get<mtx::events::RoomEvent<msg::Notice>>(event);
|
|
|
|
return processMessageEvent<NoticeEvent>(notice, direction);
|
|
|
|
} else if (mpark::holds_alternative<mtx::events::RoomEvent<msg::Text>>(event)) {
|
|
|
|
auto text = mpark::get<mtx::events::RoomEvent<msg::Text>>(event);
|
|
|
|
return processMessageEvent<TextEvent>(text, direction);
|
|
|
|
} 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);
|
2017-08-26 11:33:26 +03:00
|
|
|
}
|
2017-05-12 15:43:35 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
return nullptr;
|
2017-05-12 15:43:35 +03:00
|
|
|
}
|
|
|
|
|
2018-01-05 01:27:32 +03:00
|
|
|
void
|
|
|
|
TimelineView::renderBottomEvents(const std::vector<TimelineEvent> &events)
|
2017-05-12 15:43:35 +03:00
|
|
|
{
|
2018-01-05 01:27:32 +03:00
|
|
|
for (const auto &event : events) {
|
2017-12-04 19:41:19 +03:00
|
|
|
TimelineItem *item = parseMessageEvent(event, TimelineDirection::Bottom);
|
2017-05-12 15:43:35 +03:00
|
|
|
|
2018-01-05 01:27:32 +03:00
|
|
|
if (item != nullptr)
|
2017-08-26 11:33:26 +03:00
|
|
|
addTimelineItem(item, TimelineDirection::Bottom);
|
|
|
|
}
|
2017-04-15 02:56:04 +03:00
|
|
|
|
2017-10-27 13:36:26 +03:00
|
|
|
lastMessageDirection_ = TimelineDirection::Bottom;
|
|
|
|
|
2017-10-21 18:53:15 +03:00
|
|
|
QApplication::processEvents();
|
2018-01-05 01:27:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
TimelineView::addEvents(const mtx::responses::Timeline &timeline)
|
|
|
|
{
|
|
|
|
int message_count = 0;
|
2017-10-21 18:53:15 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
if (isInitialSync) {
|
2017-12-04 19:41:19 +03:00
|
|
|
prev_batch_token_ = QString::fromStdString(timeline.prev_batch);
|
2017-08-26 11:33:26 +03:00
|
|
|
isInitialSync = false;
|
|
|
|
}
|
2017-06-05 19:54:45 +03:00
|
|
|
|
2018-01-05 01:27:32 +03:00
|
|
|
for (const auto &e : timeline.events) {
|
|
|
|
// Save the message if it can be rendered.
|
|
|
|
if (isViewable(e))
|
|
|
|
bottomMessages_.push_back(e);
|
|
|
|
|
|
|
|
// Calculate notifications.
|
|
|
|
if (isNotifiable(e))
|
|
|
|
message_count += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bottomMessages_.empty())
|
|
|
|
notifyForLastEvent(bottomMessages_[bottomMessages_.size() - 1]);
|
2017-08-06 18:53:31 +03:00
|
|
|
|
2018-01-05 01:27:32 +03:00
|
|
|
// If the current timeline is open and there are messages to be rendered.
|
|
|
|
if (isVisible() && !bottomMessages_.empty()) {
|
|
|
|
renderBottomEvents(bottomMessages_);
|
|
|
|
|
|
|
|
// Free up space for new messages.
|
|
|
|
bottomMessages_.clear();
|
|
|
|
|
|
|
|
// Send a read receipt for the last event.
|
|
|
|
if (isActiveWindow())
|
|
|
|
readLastEvent();
|
|
|
|
}
|
2017-11-24 01:10:58 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
return message_count;
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2018-01-05 01:27:32 +03:00
|
|
|
inline bool
|
|
|
|
TimelineView::isViewable(const TimelineEvent &event) const
|
|
|
|
{
|
|
|
|
namespace msg = mtx::events::msg;
|
|
|
|
|
|
|
|
return mpark::holds_alternative<mtx::events::RoomEvent<msg::Audio>>(event) ||
|
|
|
|
mpark::holds_alternative<mtx::events::RoomEvent<msg::Emote>>(event) ||
|
|
|
|
mpark::holds_alternative<mtx::events::RoomEvent<msg::File>>(event) ||
|
|
|
|
mpark::holds_alternative<mtx::events::RoomEvent<msg::Image>>(event) ||
|
|
|
|
mpark::holds_alternative<mtx::events::RoomEvent<msg::Notice>>(event) ||
|
|
|
|
mpark::holds_alternative<mtx::events::RoomEvent<msg::Text>>(event) ||
|
|
|
|
mpark::holds_alternative<mtx::events::RoomEvent<msg::Video>>(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
TimelineView::isNotifiable(const TimelineEvent &event) const
|
|
|
|
{
|
|
|
|
namespace msg = mtx::events::msg;
|
|
|
|
|
|
|
|
if (local_user_ == getEventSender(event))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return mpark::holds_alternative<mtx::events::RoomEvent<msg::Audio>>(event) ||
|
|
|
|
mpark::holds_alternative<mtx::events::RoomEvent<msg::Emote>>(event) ||
|
|
|
|
mpark::holds_alternative<mtx::events::RoomEvent<msg::File>>(event) ||
|
|
|
|
mpark::holds_alternative<mtx::events::RoomEvent<msg::Image>>(event) ||
|
|
|
|
mpark::holds_alternative<mtx::events::RoomEvent<msg::Notice>>(event) ||
|
|
|
|
mpark::holds_alternative<mtx::events::RoomEvent<msg::Text>>(event) ||
|
|
|
|
mpark::holds_alternative<mtx::events::RoomEvent<msg::Video>>(event);
|
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
TimelineView::init()
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-09-30 22:26:33 +03:00
|
|
|
QSettings settings;
|
|
|
|
local_user_ = settings.value("auth/user_id").toString();
|
|
|
|
|
2017-10-27 22:20:33 +03:00
|
|
|
QIcon icon;
|
|
|
|
icon.addFile(":/icons/icons/ui/angle-arrow-down.png");
|
|
|
|
scrollDownBtn_ = new FloatingButton(icon, this);
|
|
|
|
scrollDownBtn_->setBackgroundColor(QColor("#F5F5F5"));
|
|
|
|
scrollDownBtn_->setForegroundColor(QColor("black"));
|
|
|
|
scrollDownBtn_->hide();
|
|
|
|
|
|
|
|
connect(scrollDownBtn_, &QPushButton::clicked, this, [=]() {
|
|
|
|
const int max = scroll_area_->verticalScrollBar()->maximum();
|
|
|
|
scroll_area_->verticalScrollBar()->setValue(max);
|
|
|
|
});
|
2017-08-26 11:33:26 +03:00
|
|
|
top_layout_ = new QVBoxLayout(this);
|
|
|
|
top_layout_->setSpacing(0);
|
|
|
|
top_layout_->setMargin(0);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
scroll_area_ = new QScrollArea(this);
|
|
|
|
scroll_area_->setWidgetResizable(true);
|
|
|
|
scroll_area_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
scrollbar_ = new ScrollBar(scroll_area_);
|
|
|
|
scroll_area_->setVerticalScrollBar(scrollbar_);
|
2017-05-24 22:45:13 +03:00
|
|
|
|
2017-10-01 18:15:23 +03:00
|
|
|
scroll_widget_ = new QWidget(this);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-10-01 18:15:23 +03:00
|
|
|
scroll_layout_ = new QVBoxLayout(scroll_widget_);
|
2017-11-25 19:19:58 +03:00
|
|
|
scroll_layout_->setContentsMargins(15, 0, 15, 15);
|
2017-08-26 11:33:26 +03:00
|
|
|
scroll_layout_->addStretch(1);
|
|
|
|
scroll_layout_->setSpacing(0);
|
2017-11-16 17:33:52 +03:00
|
|
|
scroll_layout_->setObjectName("timelinescrollarea");
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
scroll_area_->setWidget(scroll_widget_);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
top_layout_->addWidget(scroll_area_);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
setLayout(top_layout_);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
paginationTimer_ = new QTimer(this);
|
|
|
|
connect(paginationTimer_, &QTimer::timeout, this, &TimelineView::fetchHistory);
|
2017-08-05 15:59:24 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
connect(client_.data(),
|
|
|
|
&MatrixClient::messagesRetrieved,
|
|
|
|
this,
|
|
|
|
&TimelineView::addBackwardsEvents);
|
2017-05-12 15:43:35 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
connect(scroll_area_->verticalScrollBar(),
|
|
|
|
SIGNAL(valueChanged(int)),
|
|
|
|
this,
|
|
|
|
SLOT(sliderMoved(int)));
|
|
|
|
connect(scroll_area_->verticalScrollBar(),
|
|
|
|
SIGNAL(rangeChanged(int, int)),
|
|
|
|
this,
|
|
|
|
SLOT(sliderRangeChanged(int, int)));
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
TimelineView::updateLastSender(const QString &user_id, TimelineDirection direction)
|
2017-05-12 15:43:35 +03:00
|
|
|
{
|
2017-08-26 11:33:26 +03:00
|
|
|
if (direction == TimelineDirection::Bottom)
|
|
|
|
lastSender_ = user_id;
|
|
|
|
else
|
|
|
|
firstSender_ = user_id;
|
2017-05-12 15:43:35 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
bool
|
|
|
|
TimelineView::isSenderRendered(const QString &user_id, TimelineDirection direction)
|
2017-05-12 15:43:35 +03:00
|
|
|
{
|
2017-08-26 11:33:26 +03:00
|
|
|
if (direction == TimelineDirection::Bottom)
|
|
|
|
return lastSender_ != user_id;
|
|
|
|
else
|
|
|
|
return firstSender_ != user_id;
|
2017-05-12 15:43:35 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
TimelineView::addTimelineItem(TimelineItem *item, TimelineDirection direction)
|
2017-05-12 15:43:35 +03:00
|
|
|
{
|
2017-12-26 00:02:33 +03:00
|
|
|
const auto newDate = item->descriptionMessage().datetime;
|
|
|
|
|
|
|
|
if (direction == TimelineDirection::Bottom) {
|
|
|
|
const auto lastItemPosition = scroll_layout_->count() - 1;
|
|
|
|
auto lastItem =
|
2017-12-30 12:59:55 +03:00
|
|
|
qobject_cast<TimelineItem *>(scroll_layout_->itemAt(lastItemPosition)->widget());
|
2017-12-26 00:02:33 +03:00
|
|
|
|
|
|
|
if (lastItem) {
|
|
|
|
auto oldDate = lastItem->descriptionMessage().datetime;
|
|
|
|
|
|
|
|
if (oldDate.daysTo(newDate) != 0)
|
|
|
|
addDateSeparator(newDate, lastItemPosition);
|
|
|
|
}
|
|
|
|
|
2018-01-16 23:24:23 +03:00
|
|
|
pushTimelineItem(item);
|
2017-12-26 00:02:33 +03:00
|
|
|
} else {
|
|
|
|
// The first item (position 0) is a stretch widget that pushes
|
|
|
|
// the widgets to the bottom of the page.
|
|
|
|
if (scroll_layout_->count() > 1) {
|
|
|
|
auto firstItem =
|
2017-12-30 12:59:55 +03:00
|
|
|
qobject_cast<TimelineItem *>(scroll_layout_->itemAt(1)->widget());
|
2017-12-26 00:02:33 +03:00
|
|
|
|
|
|
|
if (firstItem) {
|
|
|
|
auto oldDate = firstItem->descriptionMessage().datetime;
|
|
|
|
|
|
|
|
if (newDate.daysTo(oldDate) != 0)
|
|
|
|
addDateSeparator(oldDate, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
scroll_layout_->insertWidget(1, item);
|
2017-12-26 00:02:33 +03:00
|
|
|
}
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
TimelineView::updatePendingMessage(int txn_id, QString event_id)
|
2017-04-13 04:11:22 +03:00
|
|
|
{
|
2017-12-06 03:59:15 +03:00
|
|
|
if (!pending_msgs_.isEmpty() &&
|
|
|
|
pending_msgs_.head().txn_id == txn_id) { // We haven't received it yet
|
2017-11-15 19:42:21 +03:00
|
|
|
auto msg = pending_msgs_.dequeue();
|
2017-11-15 19:38:50 +03:00
|
|
|
msg.event_id = event_id;
|
2018-01-05 16:28:38 +03:00
|
|
|
|
2018-01-14 13:54:17 +03:00
|
|
|
if (msg.widget) {
|
2018-01-05 16:28:38 +03:00
|
|
|
msg.widget->setEventId(event_id);
|
2018-01-14 13:54:17 +03:00
|
|
|
msg.widget->markReceived();
|
|
|
|
}
|
2018-01-05 16:28:38 +03:00
|
|
|
|
2017-11-15 19:38:50 +03:00
|
|
|
pending_sent_msgs_.append(msg);
|
2017-08-26 11:33:26 +03:00
|
|
|
}
|
2017-12-06 03:59:15 +03:00
|
|
|
|
2017-11-15 19:38:50 +03:00
|
|
|
sendNextPendingMessage();
|
2017-04-13 04:11:22 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
2017-12-04 19:41:19 +03:00
|
|
|
TimelineView::addUserMessage(mtx::events::MessageType ty, const QString &body)
|
2017-04-13 04:11:22 +03:00
|
|
|
{
|
2018-01-05 01:27:32 +03:00
|
|
|
auto with_sender = lastSender_ != local_user_;
|
2017-04-13 04:11:22 +03:00
|
|
|
|
2018-01-05 01:27:32 +03:00
|
|
|
TimelineItem *view_item =
|
|
|
|
new TimelineItem(ty, local_user_, body, with_sender, scroll_widget_);
|
2018-01-16 23:24:23 +03:00
|
|
|
|
|
|
|
pushTimelineItem(view_item);
|
2017-04-13 04:11:22 +03:00
|
|
|
|
2017-10-27 13:36:26 +03:00
|
|
|
lastMessageDirection_ = TimelineDirection::Bottom;
|
|
|
|
|
2017-10-21 18:53:15 +03:00
|
|
|
QApplication::processEvents();
|
2017-10-09 01:32:25 +03:00
|
|
|
|
2018-01-05 01:27:32 +03:00
|
|
|
lastSender_ = local_user_;
|
2017-04-13 04:11:22 +03:00
|
|
|
|
2017-11-15 19:38:50 +03:00
|
|
|
int txn_id = client_->incrementTransactionId();
|
|
|
|
PendingMessage message(ty, txn_id, body, "", "", view_item);
|
|
|
|
handleNewUserMessage(message);
|
2017-04-13 04:11:22 +03:00
|
|
|
}
|
2017-08-06 18:53:31 +03:00
|
|
|
|
2017-11-15 19:38:50 +03:00
|
|
|
void
|
|
|
|
TimelineView::handleNewUserMessage(PendingMessage msg)
|
|
|
|
{
|
|
|
|
pending_msgs_.enqueue(msg);
|
2017-12-06 03:59:15 +03:00
|
|
|
if (pending_msgs_.size() == 1 && pending_sent_msgs_.isEmpty())
|
2017-11-15 19:38:50 +03:00
|
|
|
sendNextPendingMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimelineView::sendNextPendingMessage()
|
|
|
|
{
|
|
|
|
if (pending_msgs_.size() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
PendingMessage &m = pending_msgs_.head();
|
|
|
|
switch (m.ty) {
|
2017-12-04 19:41:19 +03:00
|
|
|
case mtx::events::MessageType::Audio:
|
|
|
|
case mtx::events::MessageType::Image:
|
|
|
|
case mtx::events::MessageType::File:
|
2017-12-01 18:33:49 +03:00
|
|
|
// FIXME: Improve the API
|
2018-01-10 10:52:59 +03:00
|
|
|
client_->sendRoomMessage(
|
|
|
|
m.ty, m.txn_id, room_id_, m.filename, QFileInfo(m.filename), m.body);
|
2017-11-15 19:38:50 +03:00
|
|
|
break;
|
|
|
|
default:
|
2017-12-01 18:33:49 +03:00
|
|
|
client_->sendRoomMessage(m.ty, m.txn_id, room_id_, m.body, QFileInfo());
|
2017-11-15 19:38:50 +03:00
|
|
|
break;
|
|
|
|
}
|
2017-09-10 12:58:00 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
TimelineView::notifyForLastEvent()
|
2017-08-06 18:53:31 +03:00
|
|
|
{
|
2017-08-26 11:33:26 +03:00
|
|
|
auto lastItem = scroll_layout_->itemAt(scroll_layout_->count() - 1);
|
|
|
|
auto *lastTimelineItem = qobject_cast<TimelineItem *>(lastItem->widget());
|
2017-08-06 18:53:31 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
if (lastTimelineItem)
|
|
|
|
emit updateLastTimelineMessage(room_id_, lastTimelineItem->descriptionMessage());
|
|
|
|
else
|
|
|
|
qWarning() << "Cast to TimelineView failed" << room_id_;
|
2017-08-06 18:53:31 +03:00
|
|
|
}
|
2017-09-10 12:58:00 +03:00
|
|
|
|
2018-01-05 01:27:32 +03:00
|
|
|
void
|
|
|
|
TimelineView::notifyForLastEvent(const TimelineEvent &event)
|
|
|
|
{
|
|
|
|
auto descInfo = utils::getMessageDescription(event, local_user_);
|
|
|
|
|
|
|
|
if (!descInfo.timestamp.isEmpty())
|
|
|
|
emit updateLastTimelineMessage(room_id_, descInfo);
|
|
|
|
}
|
|
|
|
|
2017-09-10 12:58:00 +03:00
|
|
|
bool
|
2017-11-15 19:38:50 +03:00
|
|
|
TimelineView::isPendingMessage(const QString &txnid,
|
2017-09-10 12:58:00 +03:00
|
|
|
const QString &sender,
|
|
|
|
const QString &local_userid)
|
|
|
|
{
|
|
|
|
if (sender != local_userid)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (const auto &msg : pending_msgs_) {
|
2017-11-15 19:38:50 +03:00
|
|
|
if (QString::number(msg.txn_id) == txnid)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto &msg : pending_sent_msgs_) {
|
|
|
|
if (QString::number(msg.txn_id) == txnid)
|
2017-09-10 12:58:00 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-11-15 19:38:50 +03:00
|
|
|
TimelineView::removePendingMessage(const QString &txnid)
|
2017-09-10 12:58:00 +03:00
|
|
|
{
|
2017-11-15 19:38:50 +03:00
|
|
|
for (auto it = pending_sent_msgs_.begin(); it != pending_sent_msgs_.end(); ++it) {
|
|
|
|
if (QString::number(it->txn_id) == txnid) {
|
|
|
|
int index = std::distance(pending_sent_msgs_.begin(), it);
|
|
|
|
pending_sent_msgs_.removeAt(index);
|
2017-12-06 03:59:15 +03:00
|
|
|
|
|
|
|
if (pending_sent_msgs_.isEmpty())
|
|
|
|
sendNextPendingMessage();
|
|
|
|
|
2017-11-15 19:38:50 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-10-28 20:46:34 +03:00
|
|
|
for (auto it = pending_msgs_.begin(); it != pending_msgs_.end(); ++it) {
|
2017-11-15 19:38:50 +03:00
|
|
|
if (QString::number(it->txn_id) == txnid) {
|
|
|
|
int index = std::distance(pending_msgs_.begin(), it);
|
2017-09-10 12:58:00 +03:00
|
|
|
pending_msgs_.removeAt(index);
|
2017-11-15 19:38:50 +03:00
|
|
|
return;
|
2017-09-10 12:58:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-15 19:38:50 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
TimelineView::handleFailedMessage(int txnid)
|
|
|
|
{
|
|
|
|
Q_UNUSED(txnid);
|
|
|
|
// Note: We do this even if the message has already been echoed.
|
2017-12-06 03:59:15 +03:00
|
|
|
QTimer::singleShot(2000, this, SLOT(sendNextPendingMessage()));
|
2017-11-15 19:38:50 +03:00
|
|
|
}
|
2017-11-16 17:33:52 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
TimelineView::paintEvent(QPaintEvent *)
|
|
|
|
{
|
|
|
|
QStyleOption opt;
|
|
|
|
opt.init(this);
|
|
|
|
QPainter p(this);
|
|
|
|
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
|
|
|
}
|
2017-11-24 01:10:58 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
TimelineView::readLastEvent() const
|
|
|
|
{
|
|
|
|
const auto eventId = getLastEventId();
|
|
|
|
|
|
|
|
if (!eventId.isEmpty())
|
|
|
|
client_->readEvent(room_id_, eventId);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
TimelineView::getLastEventId() const
|
|
|
|
{
|
|
|
|
auto index = scroll_layout_->count();
|
|
|
|
|
|
|
|
// Search backwards for the first event that has a valid event id.
|
|
|
|
while (index > 0) {
|
|
|
|
--index;
|
|
|
|
|
|
|
|
auto lastItem = scroll_layout_->itemAt(index);
|
|
|
|
auto *lastTimelineItem = qobject_cast<TimelineItem *>(lastItem->widget());
|
|
|
|
|
|
|
|
if (lastTimelineItem && !lastTimelineItem->eventId().isEmpty())
|
|
|
|
return lastTimelineItem->eventId();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QString("");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimelineView::showEvent(QShowEvent *event)
|
|
|
|
{
|
2018-01-05 01:27:32 +03:00
|
|
|
if (!bottomMessages_.empty()) {
|
|
|
|
renderBottomEvents(bottomMessages_);
|
|
|
|
bottomMessages_.clear();
|
|
|
|
scrollDown();
|
|
|
|
}
|
|
|
|
|
2017-11-24 01:10:58 +03:00
|
|
|
readLastEvent();
|
|
|
|
|
|
|
|
QWidget::showEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TimelineView::event(QEvent *event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::WindowActivate) {
|
|
|
|
QTimer::singleShot(1000, this, [=]() {
|
|
|
|
emit clearUnreadMessageCount(room_id_);
|
|
|
|
readLastEvent();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return QWidget::event(event);
|
|
|
|
}
|
2017-12-04 19:41:19 +03:00
|
|
|
|
2017-12-26 00:02:33 +03:00
|
|
|
void
|
|
|
|
TimelineView::addDateSeparator(QDateTime datetime, int position)
|
|
|
|
{
|
|
|
|
auto now = QDateTime::currentDateTime();
|
|
|
|
auto days = now.daysTo(datetime);
|
|
|
|
|
|
|
|
QString fmt;
|
|
|
|
QLabel *separator;
|
|
|
|
|
|
|
|
if (now.date().year() != datetime.date().year())
|
|
|
|
fmt = QString("ddd d MMMM yy");
|
|
|
|
else
|
|
|
|
fmt = QString("ddd d MMMM");
|
|
|
|
|
|
|
|
if (days == 0)
|
|
|
|
separator = new QLabel(tr("Today"));
|
|
|
|
else if (std::abs(days) == 1)
|
|
|
|
separator = new QLabel(tr("Yesterday"));
|
|
|
|
else
|
|
|
|
separator = new QLabel(datetime.toString(fmt));
|
|
|
|
|
|
|
|
if (separator) {
|
|
|
|
separator->setStyleSheet(
|
|
|
|
QString("font-size: %1px").arg(conf::timeline::fonts::dateSeparator));
|
|
|
|
separator->setAlignment(Qt::AlignCenter);
|
|
|
|
separator->setContentsMargins(0, 15, 0, 15);
|
|
|
|
scroll_layout_->insertWidget(position, separator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-04 19:41:19 +03:00
|
|
|
QString
|
|
|
|
TimelineView::getEventSender(const mtx::events::collections::TimelineEvents &event) const
|
|
|
|
{
|
|
|
|
using Aliases = mtx::events::StateEvent<mtx::events::state::Aliases>;
|
|
|
|
using Avatar = mtx::events::StateEvent<mtx::events::state::Avatar>;
|
|
|
|
using CanonicalAlias = mtx::events::StateEvent<mtx::events::state::CanonicalAlias>;
|
|
|
|
using Create = mtx::events::StateEvent<mtx::events::state::Create>;
|
|
|
|
using HistoryVisibility = mtx::events::StateEvent<mtx::events::state::HistoryVisibility>;
|
|
|
|
using JoinRules = mtx::events::StateEvent<mtx::events::state::JoinRules>;
|
|
|
|
using Member = mtx::events::StateEvent<mtx::events::state::Member>;
|
|
|
|
using Name = mtx::events::StateEvent<mtx::events::state::Name>;
|
|
|
|
using PowerLevels = mtx::events::StateEvent<mtx::events::state::PowerLevels>;
|
|
|
|
using Topic = mtx::events::StateEvent<mtx::events::state::Topic>;
|
|
|
|
|
|
|
|
using Audio = mtx::events::RoomEvent<mtx::events::msg::Audio>;
|
|
|
|
using Emote = mtx::events::RoomEvent<mtx::events::msg::Emote>;
|
|
|
|
using File = mtx::events::RoomEvent<mtx::events::msg::File>;
|
|
|
|
using Image = mtx::events::RoomEvent<mtx::events::msg::Image>;
|
|
|
|
using Notice = mtx::events::RoomEvent<mtx::events::msg::Notice>;
|
|
|
|
using Text = mtx::events::RoomEvent<mtx::events::msg::Text>;
|
|
|
|
using Video = mtx::events::RoomEvent<mtx::events::msg::Video>;
|
|
|
|
|
|
|
|
if (mpark::holds_alternative<Aliases>(event)) {
|
|
|
|
auto msg = mpark::get<Aliases>(event);
|
|
|
|
return QString::fromStdString(msg.sender);
|
|
|
|
} else if (mpark::holds_alternative<Avatar>(event)) {
|
|
|
|
auto msg = mpark::get<Avatar>(event);
|
|
|
|
return QString::fromStdString(msg.sender);
|
|
|
|
} else if (mpark::holds_alternative<CanonicalAlias>(event)) {
|
|
|
|
auto msg = mpark::get<CanonicalAlias>(event);
|
|
|
|
return QString::fromStdString(msg.sender);
|
|
|
|
} else if (mpark::holds_alternative<Create>(event)) {
|
|
|
|
auto msg = mpark::get<Create>(event);
|
|
|
|
return QString::fromStdString(msg.sender);
|
|
|
|
} else if (mpark::holds_alternative<HistoryVisibility>(event)) {
|
|
|
|
auto msg = mpark::get<HistoryVisibility>(event);
|
|
|
|
return QString::fromStdString(msg.sender);
|
|
|
|
} else if (mpark::holds_alternative<JoinRules>(event)) {
|
|
|
|
auto msg = mpark::get<JoinRules>(event);
|
|
|
|
return QString::fromStdString(msg.sender);
|
|
|
|
} else if (mpark::holds_alternative<Name>(event)) {
|
|
|
|
auto msg = mpark::get<Name>(event);
|
|
|
|
return QString::fromStdString(msg.sender);
|
|
|
|
} else if (mpark::holds_alternative<Member>(event)) {
|
|
|
|
auto msg = mpark::get<Member>(event);
|
|
|
|
return QString::fromStdString(msg.sender);
|
|
|
|
} else if (mpark::holds_alternative<PowerLevels>(event)) {
|
|
|
|
auto msg = mpark::get<PowerLevels>(event);
|
|
|
|
return QString::fromStdString(msg.sender);
|
|
|
|
} else if (mpark::holds_alternative<Topic>(event)) {
|
|
|
|
auto msg = mpark::get<Topic>(event);
|
|
|
|
return QString::fromStdString(msg.sender);
|
|
|
|
} else if (mpark::holds_alternative<Audio>(event)) {
|
|
|
|
auto msg = mpark::get<Audio>(event);
|
|
|
|
return QString::fromStdString(msg.sender);
|
|
|
|
} else if (mpark::holds_alternative<Emote>(event)) {
|
|
|
|
auto msg = mpark::get<Emote>(event);
|
|
|
|
return QString::fromStdString(msg.sender);
|
|
|
|
} else if (mpark::holds_alternative<File>(event)) {
|
|
|
|
auto msg = mpark::get<File>(event);
|
|
|
|
return QString::fromStdString(msg.sender);
|
|
|
|
} else if (mpark::holds_alternative<Image>(event)) {
|
|
|
|
auto msg = mpark::get<Image>(event);
|
|
|
|
return QString::fromStdString(msg.sender);
|
|
|
|
} else if (mpark::holds_alternative<Notice>(event)) {
|
|
|
|
auto msg = mpark::get<Notice>(event);
|
|
|
|
return QString::fromStdString(msg.sender);
|
|
|
|
} else if (mpark::holds_alternative<Text>(event)) {
|
|
|
|
auto msg = mpark::get<Text>(event);
|
|
|
|
return QString::fromStdString(msg.sender);
|
|
|
|
} else if (mpark::holds_alternative<Video>(event)) {
|
|
|
|
auto msg = mpark::get<Video>(event);
|
|
|
|
return QString::fromStdString(msg.sender);
|
|
|
|
}
|
|
|
|
|
|
|
|
return QString("");
|
|
|
|
}
|