Revert "Improve time handling in NeoChat"
This reverts commit 92c58b0ea0.
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
#include <Quotient/room.h>
|
||||
|
||||
#include "messagefiltermodel.h"
|
||||
#include "neochatdatetime.h"
|
||||
#include "timelinemessagemodel.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
@@ -35,9 +34,8 @@ QVariant MediaMessageFilterModel::data(const QModelIndex &index, int role) const
|
||||
// We need to catch this one and return true if the next media object was
|
||||
// on a different day.
|
||||
if (role == TimelineMessageModel::ShowSectionRole) {
|
||||
const auto day = mapToSource(index).data(TimelineMessageModel::DateTimeRole).value<NeoChatDateTime>().dateTime().toLocalTime().date();
|
||||
const auto previousEventDay =
|
||||
mapToSource(this->index(index.row() + 1, 0)).data(TimelineMessageModel::DateTimeRole).value<NeoChatDateTime>().dateTime().toLocalTime().date();
|
||||
const auto day = mapToSource(index).data(TimelineMessageModel::TimeRole).toDateTime().toLocalTime().date();
|
||||
const auto previousEventDay = mapToSource(this->index(index.row() + 1, 0)).data(TimelineMessageModel::TimeRole).toDateTime().toLocalTime().date();
|
||||
return day != previousEventDay;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "enums/delegatetype.h"
|
||||
#include "messagemodel.h"
|
||||
#include "models/timelinemodel.h"
|
||||
#include "neochatdatetime.h"
|
||||
|
||||
using namespace Quotient;
|
||||
|
||||
@@ -180,13 +179,9 @@ bool MessageFilterModel::showAuthor(QModelIndex index) const
|
||||
if (data(i, TimelineMessageModel::SpecialMarksRole) != EventStatus::Hidden && !itemData(i).empty()) {
|
||||
return data(i, TimelineMessageModel::AuthorRole) != data(index, TimelineMessageModel::AuthorRole)
|
||||
|| data(i, TimelineMessageModel::DelegateTypeRole) == DelegateType::State
|
||||
|| data(i, TimelineMessageModel::DateTimeRole)
|
||||
.value<NeoChatDateTime>()
|
||||
.dateTime()
|
||||
.msecsTo(data(index, TimelineMessageModel::DateTimeRole).value<NeoChatDateTime>().dateTime())
|
||||
> 600000
|
||||
|| data(i, TimelineMessageModel::DateTimeRole).value<NeoChatDateTime>().dateTime().toLocalTime().date().day()
|
||||
!= data(index, TimelineMessageModel::DateTimeRole).value<NeoChatDateTime>().dateTime().toLocalTime().date().day();
|
||||
|| data(i, TimelineMessageModel::TimeRole).toDateTime().msecsTo(data(index, TimelineMessageModel::TimeRole).toDateTime()) > 600000
|
||||
|| data(i, TimelineMessageModel::TimeRole).toDateTime().toLocalTime().date().day()
|
||||
!= data(index, TimelineMessageModel::TimeRole).toDateTime().toLocalTime().date().day();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,9 +17,8 @@
|
||||
#include "enums/messagecomponenttype.h"
|
||||
#include "eventhandler.h"
|
||||
#include "events/pollevent.h"
|
||||
#include "models/eventmessagecontentmodel.h"
|
||||
#include "models/reactionmodel.h"
|
||||
#include "neochatdatetime.h"
|
||||
#include "models/eventmessagecontentmodel.h"
|
||||
#include "neochatroommember.h"
|
||||
|
||||
using namespace Quotient;
|
||||
@@ -111,8 +110,11 @@ QVariant MessageModel::data(const QModelIndex &idx, int role) const
|
||||
switch (role) {
|
||||
case DelegateTypeRole:
|
||||
return DelegateType::ReadMarker;
|
||||
case DateTimeRole:
|
||||
return data(index(m_lastReadEventIndex.row() + 1, 0), DateTimeRole);
|
||||
case TimeRole: {
|
||||
const QDateTime eventDate = data(index(m_lastReadEventIndex.row() + 1, 0), TimeRole).toDateTime().toLocalTime();
|
||||
static const KFormat format;
|
||||
return format.formatRelativeDateTime(eventDate, QLocale::ShortFormat);
|
||||
}
|
||||
case SpecialMarksRole:
|
||||
// Check if all the earlier events in the timeline are hidden. If so hide this.
|
||||
for (auto r = row - 1; r >= 0; --r) {
|
||||
@@ -228,8 +230,12 @@ QVariant MessageModel::data(const QModelIndex &idx, int role) const
|
||||
return {};
|
||||
}
|
||||
|
||||
if (role == DateTimeRole) {
|
||||
return QVariant::fromValue(EventHandler::dateTime(eventRoom, &event.value().get(), isPending));
|
||||
if (role == TimeRole) {
|
||||
return EventHandler::time(eventRoom, &event.value().get(), isPending);
|
||||
}
|
||||
|
||||
if (role == SectionRole) {
|
||||
return EventHandler::timeString(eventRoom, &event.value().get(), true, QLocale::ShortFormat, isPending);
|
||||
}
|
||||
|
||||
if (role == IsThreadedRole) {
|
||||
@@ -261,8 +267,8 @@ QVariant MessageModel::data(const QModelIndex &idx, int role) const
|
||||
// While the row is removed the subsequent row indexes are not changed so we need to skip over the removed index.
|
||||
// See - https://doc.qt.io/qt-5/qabstractitemmodel.html#beginRemoveRows
|
||||
if (data(i, SpecialMarksRole) != EventStatus::Hidden && !itemData(i).empty()) {
|
||||
const auto day = data(idx, DateTimeRole).value<NeoChatDateTime>().dateTime().toLocalTime().date().dayOfYear();
|
||||
const auto previousEventDay = data(i, DateTimeRole).value<NeoChatDateTime>().dateTime().toLocalTime().date().dayOfYear();
|
||||
const auto day = data(idx, TimeRole).toDateTime().toLocalTime().date().dayOfYear();
|
||||
const auto previousEventDay = data(i, TimeRole).toDateTime().toLocalTime().date().dayOfYear();
|
||||
return day != previousEventDay;
|
||||
}
|
||||
}
|
||||
@@ -336,7 +342,8 @@ QHash<int, QByteArray> MessageModel::roleNames() const
|
||||
QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
|
||||
roles[DelegateTypeRole] = "delegateType";
|
||||
roles[EventIdRole] = "eventId";
|
||||
roles[DateTimeRole] = "dateTime";
|
||||
roles[TimeRole] = "time";
|
||||
roles[SectionRole] = "section";
|
||||
roles[AuthorRole] = "author";
|
||||
roles[HighlightRole] = "isHighlighted";
|
||||
roles[SpecialMarksRole] = "marks";
|
||||
|
||||
@@ -60,7 +60,8 @@ public:
|
||||
enum EventRoles {
|
||||
DelegateTypeRole = Qt::UserRole + 1, /**< The delegate type of the message. */
|
||||
EventIdRole, /**< The matrix event ID of the event. */
|
||||
DateTimeRole, /**< The timestamp for when the event was sent (as a NeoChatDateTime). */
|
||||
TimeRole, /**< The timestamp for when the event was sent (as a QDateTime). */
|
||||
SectionRole, /**< The date of the event as a string. */
|
||||
AuthorRole, /**< The author of the event. */
|
||||
HighlightRole, /**< Whether the event should be highlighted. */
|
||||
SpecialMarksRole, /**< Whether the event is hidden or not. */
|
||||
|
||||
Reference in New Issue
Block a user