From 983aea7c76da65214463e725576e8b147fd02cdf Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Fri, 5 Jan 2018 00:27:32 +0200 Subject: Create widgets on demand for messages added to the end of the timeline --- src/Utils.cc | 121 +++++++++++++++++++++++++++++++++++++++++++ src/timeline/TimelineItem.cc | 28 +++------- src/timeline/TimelineView.cc | 109 ++++++++++++++++++++++++++++++-------- 3 files changed, 213 insertions(+), 45 deletions(-) create mode 100644 src/Utils.cc (limited to 'src') diff --git a/src/Utils.cc b/src/Utils.cc new file mode 100644 index 00000000..663f7196 --- /dev/null +++ b/src/Utils.cc @@ -0,0 +1,121 @@ +#include "Utils.h" +#include "timeline/TimelineViewManager.h" + +#include + +using TimelineEvent = mtx::events::collections::TimelineEvents; + +QString +utils::descriptiveTime(const QDateTime &then) +{ + const auto now = QDateTime::currentDateTime(); + const auto days = then.daysTo(now); + + if (days == 0) + return then.toString("HH:mm"); + else if (days < 2) + return QString("Yesterday"); + else if (days < 365) + return then.toString("dd/MM"); + + return then.toString("dd/MM/yy"); +} + +DescInfo +utils::getMessageDescription(const TimelineEvent &event, const QString &localUser) +{ + using Audio = mtx::events::RoomEvent; + using Emote = mtx::events::RoomEvent; + using File = mtx::events::RoomEvent; + using Image = mtx::events::RoomEvent; + using Notice = mtx::events::RoomEvent; + using Text = mtx::events::RoomEvent; + using Video = mtx::events::RoomEvent; + + if (mpark::holds_alternative