Create widgets on demand for messages added to the end of the timeline
This commit is contained in:
parent
a7e84b63ac
commit
983aea7c76
7 changed files with 260 additions and 55 deletions
20
include/Utils.h
Normal file
20
include/Utils.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include "RoomInfoListItem.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <mtx/events/collections.hpp>
|
||||
|
||||
namespace utils {
|
||||
|
||||
using TimelineEvent = mtx::events::collections::TimelineEvents;
|
||||
|
||||
//! Human friendly timestamp representation.
|
||||
QString
|
||||
descriptiveTime(const QDateTime &then);
|
||||
|
||||
//! Generate a message description from the event to be displayed
|
||||
//! in the RoomList.
|
||||
DescInfo
|
||||
getMessageDescription(const TimelineEvent &event, const QString &localUser);
|
||||
}
|
||||
|
|
@ -28,6 +28,7 @@
|
|||
#include "AvatarProvider.h"
|
||||
#include "RoomInfoListItem.h"
|
||||
#include "TimelineViewManager.h"
|
||||
#include "Utils.h"
|
||||
|
||||
class ImageItem;
|
||||
class AudioItem;
|
||||
|
|
@ -107,7 +108,6 @@ private:
|
|||
void generateBody(const QString &body);
|
||||
void generateBody(const QString &userid, const QString &body);
|
||||
void generateTimestamp(const QDateTime &time);
|
||||
QString descriptiveTime(const QDateTime &then);
|
||||
|
||||
void setupAvatarLayout(const QString &userName);
|
||||
void setupSimpleLayout();
|
||||
|
|
@ -145,8 +145,11 @@ TimelineItem::setupLocalWidgetLayout(Widget *widget,
|
|||
auto displayName = TimelineViewManager::displayName(userid);
|
||||
auto timestamp = QDateTime::currentDateTime();
|
||||
|
||||
descriptionMsg_ = {
|
||||
"You", userid, QString(" %1").arg(msgDescription), descriptiveTime(timestamp), timestamp};
|
||||
descriptionMsg_ = {"You",
|
||||
userid,
|
||||
QString(" %1").arg(msgDescription),
|
||||
utils::descriptiveTime(timestamp),
|
||||
timestamp};
|
||||
|
||||
generateTimestamp(timestamp);
|
||||
|
||||
|
|
@ -187,7 +190,7 @@ TimelineItem::setupWidgetLayout(Widget *widget,
|
|||
descriptionMsg_ = {sender == settings.value("auth/user_id") ? "You" : displayName,
|
||||
sender,
|
||||
msgDescription,
|
||||
descriptiveTime(timestamp),
|
||||
utils::descriptiveTime(timestamp),
|
||||
timestamp};
|
||||
|
||||
generateTimestamp(timestamp);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@
|
|||
#include <QList>
|
||||
#include <QQueue>
|
||||
#include <QScrollArea>
|
||||
#include <QSettings>
|
||||
#include <QStyle>
|
||||
#include <QStyleOption>
|
||||
|
||||
|
|
@ -119,10 +118,13 @@ protected:
|
|||
bool event(QEvent *event) override;
|
||||
|
||||
private:
|
||||
using TimelineEvent = mtx::events::collections::TimelineEvents;
|
||||
|
||||
void init();
|
||||
void addTimelineItem(TimelineItem *item, TimelineDirection direction);
|
||||
void updateLastSender(const QString &user_id, TimelineDirection direction);
|
||||
void notifyForLastEvent();
|
||||
void notifyForLastEvent(const TimelineEvent &event);
|
||||
void readLastEvent() const;
|
||||
bool isScrollbarActivated() { return scroll_area_->verticalScrollBar()->value() != 0; }
|
||||
QString getLastEventId() const;
|
||||
|
|
@ -193,6 +195,18 @@ private:
|
|||
|
||||
TimelineDirection lastMessageDirection_;
|
||||
|
||||
//! Messages received by sync not added to the timeline.
|
||||
std::vector<TimelineEvent> bottomMessages_;
|
||||
|
||||
//! Render the given timeline events to the bottom of the timeline.
|
||||
void renderBottomEvents(const std::vector<TimelineEvent> &events);
|
||||
|
||||
//! Decide if the given timeline event can be rendered.
|
||||
inline bool isViewable(const TimelineEvent &event) const;
|
||||
|
||||
//! Decide if the given event should trigger a notification.
|
||||
inline bool isNotifiable(const TimelineEvent &event) const;
|
||||
|
||||
// The events currently rendered. Used for duplicate detection.
|
||||
QMap<QString, bool> eventIds_;
|
||||
QQueue<PendingMessage> pending_msgs_;
|
||||
|
|
@ -204,20 +218,19 @@ template<class Widget, mtx::events::MessageType MsgType>
|
|||
void
|
||||
TimelineView::addUserMessage(const QString &url, const QString &filename)
|
||||
{
|
||||
QSettings settings;
|
||||
auto user_id = settings.value("auth/user_id").toString();
|
||||
auto with_sender = lastSender_ != user_id;
|
||||
auto with_sender = lastSender_ != local_user_;
|
||||
|
||||
auto widget = new Widget(client_, url, filename, this);
|
||||
|
||||
TimelineItem *view_item = new TimelineItem(widget, user_id, with_sender, scroll_widget_);
|
||||
TimelineItem *view_item =
|
||||
new TimelineItem(widget, local_user_, with_sender, scroll_widget_);
|
||||
scroll_layout_->addWidget(view_item);
|
||||
|
||||
lastMessageDirection_ = TimelineDirection::Bottom;
|
||||
|
||||
QApplication::processEvents();
|
||||
|
||||
lastSender_ = user_id;
|
||||
lastSender_ = local_user_;
|
||||
|
||||
int txn_id = client_->incrementTransactionId();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue