Revert "Improve time handling in NeoChat"
This reverts commit 92c58b0ea0.
This commit is contained in:
@@ -27,9 +27,14 @@ RowLayout {
|
||||
required property var author
|
||||
|
||||
/**
|
||||
* @brief The timestamp of the event as a NeoChatDateTime.
|
||||
* @brief The timestamp of the message.
|
||||
*/
|
||||
required property NeoChatDateTime dateTime
|
||||
required property var time
|
||||
|
||||
/**
|
||||
* @brief The timestamp of the message as a string.
|
||||
*/
|
||||
required property string timeString
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.maximumWidth: Message.maxContentWidth
|
||||
@@ -78,11 +83,11 @@ RowLayout {
|
||||
}
|
||||
QQC2.Label {
|
||||
id: timeLabel
|
||||
text: root.dateTime.hourMinuteString
|
||||
text: root.timeString
|
||||
horizontalAlignment: Text.AlignRight
|
||||
color: Kirigami.Theme.disabledTextColor
|
||||
QQC2.ToolTip.visible: timeHoverHandler.hovered
|
||||
QQC2.ToolTip.text: root.dateTime.shortDateTime
|
||||
QQC2.ToolTip.text: root.time.toLocaleString(Qt.locale(), Locale.ShortFormat)
|
||||
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
|
||||
|
||||
HoverHandler {
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#include "contentprovider.h"
|
||||
#include "eventhandler.h"
|
||||
#include "models/reactionmodel.h"
|
||||
#include "neochatdatetime.h"
|
||||
#include "neochatroom.h"
|
||||
#include "texthandler.h"
|
||||
|
||||
@@ -124,13 +123,22 @@ void EventMessageContentModel::initializeModel()
|
||||
resetModel();
|
||||
}
|
||||
|
||||
NeoChatDateTime EventMessageContentModel::dateTime() const
|
||||
QDateTime EventMessageContentModel::time() const
|
||||
{
|
||||
const auto event = m_room->getEvent(m_eventId);
|
||||
if (event.first == nullptr) {
|
||||
return MessageContentModel::dateTime();
|
||||
return MessageContentModel::time();
|
||||
};
|
||||
return EventHandler::dateTime(m_room, event.first, m_currentState == Pending);
|
||||
return EventHandler::time(m_room, event.first, m_currentState == Pending);
|
||||
}
|
||||
|
||||
QString EventMessageContentModel::timeString() const
|
||||
{
|
||||
const auto event = m_room->getEvent(m_eventId);
|
||||
if (event.first == nullptr) {
|
||||
return MessageContentModel::timeString();
|
||||
};
|
||||
return EventHandler::timeString(m_room, event.first, u"hh:mm"_s, m_currentState == Pending);
|
||||
}
|
||||
|
||||
QString EventMessageContentModel::authorId() const
|
||||
@@ -246,7 +254,12 @@ void EventMessageContentModel::resetModel()
|
||||
return;
|
||||
}
|
||||
|
||||
m_components += MessageComponent{MessageComponentType::Author, {}, {}};
|
||||
m_components += MessageComponent{MessageComponentType::Author,
|
||||
QString(),
|
||||
{
|
||||
{u"time"_s, EventHandler::time(m_room, event.first, m_currentState == Pending)},
|
||||
{u"timeString"_s, EventHandler::timeString(m_room, event.first, u"hh:mm"_s, m_currentState == Pending)},
|
||||
}};
|
||||
|
||||
m_components += messageContentComponents();
|
||||
endResetModel();
|
||||
|
||||
@@ -52,7 +52,8 @@ Q_SIGNALS:
|
||||
private:
|
||||
void initializeModel();
|
||||
|
||||
NeoChatDateTime dateTime() const override;
|
||||
QDateTime time() const override;
|
||||
QString timeString() const override;
|
||||
QString authorId() const override;
|
||||
QString threadRootId() const override;
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include "chatbarcache.h"
|
||||
#include "contentprovider.h"
|
||||
#include "neochatconnection.h"
|
||||
#include "neochatdatetime.h"
|
||||
#include "texthandler.h"
|
||||
|
||||
using namespace Quotient;
|
||||
@@ -80,11 +79,16 @@ QString MessageContentModel::eventId() const
|
||||
return m_eventId;
|
||||
}
|
||||
|
||||
NeoChatDateTime MessageContentModel::dateTime() const
|
||||
QDateTime MessageContentModel::time() const
|
||||
{
|
||||
return QDateTime::currentDateTime();
|
||||
}
|
||||
|
||||
QString MessageContentModel::timeString() const
|
||||
{
|
||||
return time().toLocalTime().toString(u"hh:mm"_s);
|
||||
}
|
||||
|
||||
QString MessageContentModel::authorId() const
|
||||
{
|
||||
return m_room->localMember().id();
|
||||
@@ -132,8 +136,11 @@ QVariant MessageContentModel::data(const QModelIndex &index, int role) const
|
||||
if (role == EventIdRole) {
|
||||
return eventId();
|
||||
}
|
||||
if (role == DateTimeRole) {
|
||||
return QVariant::fromValue(dateTime());
|
||||
if (role == TimeRole) {
|
||||
return time();
|
||||
}
|
||||
if (role == TimeStringRole) {
|
||||
return timeString();
|
||||
}
|
||||
if (role == AuthorRole) {
|
||||
return QVariant::fromValue<NeochatRoomMember *>(author());
|
||||
@@ -192,7 +199,8 @@ QHash<int, QByteArray> MessageContentModel::roleNamesStatic()
|
||||
roles[MessageContentModel::ComponentTypeRole] = "componentType";
|
||||
roles[MessageContentModel::ComponentAttributesRole] = "componentAttributes";
|
||||
roles[MessageContentModel::EventIdRole] = "eventId";
|
||||
roles[MessageContentModel::DateTimeRole] = "dateTime";
|
||||
roles[MessageContentModel::TimeRole] = "time";
|
||||
roles[MessageContentModel::TimeStringRole] = "timeString";
|
||||
roles[MessageContentModel::AuthorRole] = "author";
|
||||
roles[MessageContentModel::FileTransferInfoRole] = "fileTransferInfo";
|
||||
roles[MessageContentModel::ItineraryModelRole] = "itineraryModel";
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
#include "neochatroom.h"
|
||||
#include "neochatroommember.h"
|
||||
|
||||
class NeoChatDateTime;
|
||||
|
||||
/**
|
||||
* @class MessageContentModel
|
||||
*
|
||||
@@ -49,7 +47,8 @@ public:
|
||||
ComponentTypeRole = Qt::UserRole, /**< The type of component to visualise the message. */
|
||||
ComponentAttributesRole, /**< The attributes of the component. */
|
||||
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). */
|
||||
TimeStringRole, /**< The timestamp for when the event was sent as a string (in QLocale::ShortFormat). */
|
||||
AuthorRole, /**< The author of the event. */
|
||||
FileTransferInfoRole, /**< FileTransferInfo for any downloading files. */
|
||||
ItineraryModelRole, /**< The itinerary model for a file. */
|
||||
@@ -126,11 +125,18 @@ protected:
|
||||
QString m_eventId;
|
||||
|
||||
/**
|
||||
* @brief NeoChatDateTime for the message.
|
||||
* @brief QDateTime for the message.
|
||||
*
|
||||
* The default implementation returns the current time.
|
||||
*/
|
||||
virtual NeoChatDateTime dateTime() const;
|
||||
virtual QDateTime time() const;
|
||||
|
||||
/**
|
||||
* @brief Time for the message as a string in the from "hh:mm".
|
||||
*
|
||||
* The default implementation returns the current time.
|
||||
*/
|
||||
virtual QString timeString() const;
|
||||
|
||||
/**
|
||||
* @brief The author of the message.
|
||||
|
||||
Reference in New Issue
Block a user