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:
@@ -10,6 +10,7 @@
|
||||
#include "chatbarcache.h"
|
||||
#include "contentprovider.h"
|
||||
#include "neochatconnection.h"
|
||||
#include "neochatdatetime.h"
|
||||
#include "texthandler.h"
|
||||
|
||||
using namespace Quotient;
|
||||
@@ -79,16 +80,11 @@ QString MessageContentModel::eventId() const
|
||||
return m_eventId;
|
||||
}
|
||||
|
||||
QDateTime MessageContentModel::time() const
|
||||
NeoChatDateTime MessageContentModel::dateTime() 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();
|
||||
@@ -136,11 +132,8 @@ QVariant MessageContentModel::data(const QModelIndex &index, int role) const
|
||||
if (role == EventIdRole) {
|
||||
return eventId();
|
||||
}
|
||||
if (role == TimeRole) {
|
||||
return time();
|
||||
}
|
||||
if (role == TimeStringRole) {
|
||||
return timeString();
|
||||
if (role == DateTimeRole) {
|
||||
return QVariant::fromValue(dateTime());
|
||||
}
|
||||
if (role == AuthorRole) {
|
||||
return QVariant::fromValue<NeochatRoomMember *>(author());
|
||||
@@ -199,8 +192,7 @@ QHash<int, QByteArray> MessageContentModel::roleNamesStatic()
|
||||
roles[MessageContentModel::ComponentTypeRole] = "componentType";
|
||||
roles[MessageContentModel::ComponentAttributesRole] = "componentAttributes";
|
||||
roles[MessageContentModel::EventIdRole] = "eventId";
|
||||
roles[MessageContentModel::TimeRole] = "time";
|
||||
roles[MessageContentModel::TimeStringRole] = "timeString";
|
||||
roles[MessageContentModel::DateTimeRole] = "dateTime";
|
||||
roles[MessageContentModel::AuthorRole] = "author";
|
||||
roles[MessageContentModel::FileTransferInfoRole] = "fileTransferInfo";
|
||||
roles[MessageContentModel::ItineraryModelRole] = "itineraryModel";
|
||||
|
||||
Reference in New Issue
Block a user