Improve time handling in NeoChat

This introduces a new NeoChatDateTime object that wraps a QDateTime. The intent is that it can be passed to QML and has a series of functions that format the QDateTime into the various string representations we need.

This means we only have to send the single object to QML and then the correct string can be grabbed from there, simplifying the backend. It is also easy to add a new representation if needed as a function with a QString output and Q_PROPERTY can be added and then it will be available.
This commit is contained in:
James Graham
2026-01-25 13:01:31 +00:00
parent c797ecea3d
commit 92c58b0ea0
17 changed files with 191 additions and 172 deletions

View File

@@ -21,6 +21,8 @@
#include "neochatroom.h"
#include "neochatroommember.h"
class NeoChatDateTime;
/**
* @class MessageContentModel
*
@@ -47,8 +49,7 @@ 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. */
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). */
DateTimeRole, /**< The timestamp for when the event was sent (as a NeoChatDateTime). */
AuthorRole, /**< The author of the event. */
FileTransferInfoRole, /**< FileTransferInfo for any downloading files. */
ItineraryModelRole, /**< The itinerary model for a file. */
@@ -125,18 +126,11 @@ protected:
QString m_eventId;
/**
* @brief QDateTime for the message.
* @brief NeoChatDateTime for the message.
*
* The default implementation returns the current time.
*/
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;
virtual NeoChatDateTime dateTime() const;
/**
* @brief The author of the message.