Update libqmatrixclient && basic working messageeventmodel && room
search.
This commit is contained in:
parent
b3c0dc9421
commit
a19364610a
1
main.cpp
1
main.cpp
|
@ -31,6 +31,7 @@ int main(int argc, char *argv[])
|
||||||
qmlRegisterType<Controller>("Matrique", 0, 1, "Controller");
|
qmlRegisterType<Controller>("Matrique", 0, 1, "Controller");
|
||||||
qmlRegisterType<RoomListModel>("Matrique", 0, 1, "RoomListModel");
|
qmlRegisterType<RoomListModel>("Matrique", 0, 1, "RoomListModel");
|
||||||
qmlRegisterType<MessageEventModel>("Matrique", 0, 1, "MessageEventModel");
|
qmlRegisterType<MessageEventModel>("Matrique", 0, 1, "MessageEventModel");
|
||||||
|
qRegisterMetaType<User*>("User*");
|
||||||
|
|
||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
|
|
||||||
#include "libqmatrixclient/connection.h"
|
#include "connection.h"
|
||||||
|
|
||||||
Controller::Controller(QObject *parent) : QObject(parent) {
|
Controller::Controller(QObject *parent) : QObject(parent) {
|
||||||
connect(m_connection, &QMatrixClient::Connection::connected, this, &Controller::connected);
|
connect(m_connection, &QMatrixClient::Connection::connected, this, &Controller::connected);
|
||||||
connect(m_connection, &QMatrixClient::Connection::resolveError, this, &Controller::reconnect);
|
connect(m_connection, &QMatrixClient::Connection::resolveError, this, &Controller::reconnect);
|
||||||
connect(m_connection, &QMatrixClient::Connection::syncError, this, &Controller::reconnect);
|
connect(m_connection, &QMatrixClient::Connection::syncError, this, &Controller::reconnect);
|
||||||
connect(m_connection, &QMatrixClient::Connection::syncDone, this, &Controller::resync);
|
connect(m_connection, &QMatrixClient::Connection::syncDone, this, &Controller::resync);
|
||||||
|
connect(m_connection, &QMatrixClient::Connection::connected, this, &Controller::connectionChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
Controller::~Controller() {
|
Controller::~Controller() {
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
#define CONTROLLER_H
|
#define CONTROLLER_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include "libqmatrixclient/connection.h"
|
#include "connection.h"
|
||||||
|
#include "user.h"
|
||||||
#include "roomlistmodel.h"
|
#include "roomlistmodel.h"
|
||||||
|
|
||||||
namespace QMatrixClient {
|
namespace QMatrixClient {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include <QtCore/QReadWriteLock>
|
#include <QtCore/QReadWriteLock>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include "libqmatrixclient/connection.h"
|
#include "connection.h"
|
||||||
#include "imageproviderconnection.h"
|
#include "imageproviderconnection.h"
|
||||||
|
|
||||||
class ImageProvider: public QQuickImageProvider
|
class ImageProvider: public QQuickImageProvider
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include "libqmatrixclient/connection.h"
|
#include "connection.h"
|
||||||
|
|
||||||
class ImageProviderConnection : public QObject
|
class ImageProviderConnection : public QObject
|
||||||
{
|
{
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit b7c1ff183384738f170d53128c684681cb34f3b7
|
Subproject commit c4acd8ece12622164caf396c06bd0f22ab3589f7
|
|
@ -7,37 +7,25 @@
|
||||||
#include "events/roommemberevent.h"
|
#include "events/roommemberevent.h"
|
||||||
#include "events/simplestateevents.h"
|
#include "events/simplestateevents.h"
|
||||||
#include "events/redactionevent.h"
|
#include "events/redactionevent.h"
|
||||||
|
#include "events/roomavatarevent.h"
|
||||||
|
|
||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
#include "user.h"
|
#include "user.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
QHash<int, QByteArray> MessageEventModel::roleNames() const
|
|
||||||
{
|
|
||||||
QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
|
|
||||||
roles[EventTypeRole] = "eventType";
|
|
||||||
roles[EventIdRole] = "eventId";
|
|
||||||
roles[TimeRole] = "time";
|
|
||||||
roles[SectionRole] = "section";
|
|
||||||
roles[AboveSectionRole] = "aboveSection";
|
|
||||||
roles[AuthorRole] = "author";
|
|
||||||
roles[ContentRole] = "content";
|
|
||||||
roles[ContentTypeRole] = "contentType";
|
|
||||||
roles[ReadMarkerRole] = "readMarker";
|
|
||||||
roles[SpecialMarksRole] = "marks";
|
|
||||||
roles[LongOperationRole] = "progressInfo";
|
|
||||||
return roles;
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageEventModel::MessageEventModel(QObject* parent)
|
MessageEventModel::MessageEventModel(QObject* parent)
|
||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent)
|
||||||
, m_currentRoom(nullptr)
|
|
||||||
{
|
{
|
||||||
qmlRegisterType<QMatrixClient::FileTransferInfo>();
|
qmlRegisterType<QMatrixClient::FileTransferInfo>();
|
||||||
qRegisterMetaType<QMatrixClient::FileTransferInfo>();
|
qRegisterMetaType<QMatrixClient::FileTransferInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageEventModel::changeRoom(QMatrixClient::Room* room)
|
MessageEventModel::~MessageEventModel()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageEventModel::setRoom(QMatrixClient::Room* room)
|
||||||
{
|
{
|
||||||
if (room == m_currentRoom)
|
if (room == m_currentRoom)
|
||||||
return;
|
return;
|
||||||
|
@ -90,6 +78,7 @@ void MessageEventModel::changeRoom(QMatrixClient::Room* room)
|
||||||
}
|
}
|
||||||
lastReadEventId = room ? room->readMarkerEventId() : "";
|
lastReadEventId = room ? room->readMarkerEventId() : "";
|
||||||
endResetModel();
|
endResetModel();
|
||||||
|
emit roomChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageEventModel::refreshEvent(const QString& eventId)
|
void MessageEventModel::refreshEvent(const QString& eventId)
|
||||||
|
@ -163,82 +152,77 @@ int MessageEventModel::rowCount(const QModelIndex& parent) const
|
||||||
|
|
||||||
QVariant MessageEventModel::data(const QModelIndex& index, int role) const
|
QVariant MessageEventModel::data(const QModelIndex& index, int role) const
|
||||||
{
|
{
|
||||||
if(!m_currentRoom ||
|
if( !m_currentRoom ||
|
||||||
index.row() < 0 || index.row() >= m_currentRoom->timelineSize())
|
index.row() < 0 || index.row() >= m_currentRoom->timelineSize())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
const auto eventIt = m_currentRoom->messageEvents().rbegin() + index.row();
|
const auto timelineIt = m_currentRoom->messageEvents().rbegin() + index.row();
|
||||||
auto* event = eventIt->event();
|
const auto& ti = *timelineIt;
|
||||||
// FIXME: Rewind to the name that was right before this event
|
|
||||||
QString senderName = m_currentRoom->roomMembername(event->senderId());
|
|
||||||
|
|
||||||
using namespace QMatrixClient;
|
using namespace QMatrixClient;
|
||||||
if(role == Qt::DisplayRole)
|
if( role == Qt::DisplayRole )
|
||||||
{
|
{
|
||||||
if (event->isRedacted())
|
if (ti->isRedacted())
|
||||||
{
|
{
|
||||||
auto reason = event->redactedBecause()->reason();
|
auto reason = ti->redactedBecause()->reason();
|
||||||
if (reason.isEmpty())
|
if (reason.isEmpty())
|
||||||
return tr("Redacted");
|
return tr("Redacted");
|
||||||
else
|
|
||||||
return tr("Redacted: %1")
|
return tr("Redacted: %1")
|
||||||
.arg(event->redactedBecause()->reason());
|
.arg(ti->redactedBecause()->reason());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(event->type() == EventType::RoomMessage)
|
return visit(*ti
|
||||||
{
|
, [this] (const RoomMessageEvent& e) -> QVariant {
|
||||||
using namespace MessageEventContent;
|
using namespace MessageEventContent;
|
||||||
|
|
||||||
auto* e = static_cast<const RoomMessageEvent*>(event);
|
if (e.hasTextContent() && e.mimeType().name() != "text/plain")
|
||||||
if (e->hasTextContent() && e->mimeType().name() != "text/plain")
|
return static_cast<const TextContent*>(e.content())->body;
|
||||||
return static_cast<const TextContent*>(e->content())->body;
|
if (e.hasFileContent())
|
||||||
if (e->hasFileContent())
|
|
||||||
{
|
{
|
||||||
auto fileCaption = e->content()->fileInfo()->originalName;
|
auto fileCaption = e.content()->fileInfo()->originalName;
|
||||||
if (fileCaption.isEmpty())
|
if (fileCaption.isEmpty())
|
||||||
fileCaption = m_currentRoom->prettyPrint(e->plainBody());
|
fileCaption = m_currentRoom->prettyPrint(e.plainBody());
|
||||||
if (fileCaption.isEmpty())
|
if (fileCaption.isEmpty())
|
||||||
return tr("a file");
|
return tr("a file");
|
||||||
}
|
}
|
||||||
return m_currentRoom->prettyPrint(e->plainBody());
|
return m_currentRoom->prettyPrint(e.plainBody());
|
||||||
}
|
}
|
||||||
if(event->type() == EventType::RoomMember)
|
, [this] (const RoomMemberEvent& e) -> QVariant {
|
||||||
{
|
|
||||||
auto* e = static_cast<const RoomMemberEvent*>(event);
|
|
||||||
// FIXME: Rewind to the name that was at the time of this event
|
// FIXME: Rewind to the name that was at the time of this event
|
||||||
QString subjectName = m_currentRoom->roomMembername(e->userId());
|
QString subjectName = m_currentRoom->roomMembername(e.userId());
|
||||||
// The below code assumes senderName output in AuthorRole
|
// The below code assumes senderName output in AuthorRole
|
||||||
switch(e->membership())
|
switch( e.membership() )
|
||||||
{
|
{
|
||||||
case MembershipType::Invite:
|
case MembershipType::Invite:
|
||||||
if (e->repeatsState())
|
if (e.repeatsState())
|
||||||
return tr("reinvited %1 to the room").arg(subjectName);
|
return tr("reinvited %1 to the room").arg(subjectName);
|
||||||
// [[fallthrough]]
|
FALLTHROUGH;
|
||||||
case MembershipType::Join:
|
case MembershipType::Join:
|
||||||
{
|
{
|
||||||
if (e->repeatsState())
|
if (e.repeatsState())
|
||||||
return tr("joined the room (repeated)");
|
return tr("joined the room (repeated)");
|
||||||
if (!e->prev_content() ||
|
if (!e.prevContent() ||
|
||||||
e->membership() != e->prev_content()->membership)
|
e.membership() != e.prevContent()->membership)
|
||||||
{
|
{
|
||||||
return e->membership() == MembershipType::Invite
|
return e.membership() == MembershipType::Invite
|
||||||
? tr("invited %1 to the room").arg(subjectName)
|
? tr("invited %1 to the room").arg(subjectName)
|
||||||
: tr("joined the room");
|
: tr("joined the room");
|
||||||
}
|
}
|
||||||
QString text {};
|
QString text {};
|
||||||
if (e->displayName() != e->prev_content()->displayName)
|
if (e.displayName() != e.prevContent()->displayName)
|
||||||
{
|
{
|
||||||
if (e->displayName().isEmpty())
|
if (e.displayName().isEmpty())
|
||||||
text = tr("cleared the display name");
|
text = tr("cleared the display name");
|
||||||
else
|
else
|
||||||
text = tr("changed the display name to %1")
|
text = tr("changed the display name to %1")
|
||||||
.arg(e->displayName());
|
.arg(e.displayName());
|
||||||
}
|
}
|
||||||
if (e->avatarUrl() != e->prev_content()->avatarUrl)
|
if (e.avatarUrl() != e.prevContent()->avatarUrl)
|
||||||
{
|
{
|
||||||
if (!text.isEmpty())
|
if (!text.isEmpty())
|
||||||
text += " and ";
|
text += " and ";
|
||||||
if (e->avatarUrl().isEmpty())
|
if (e.avatarUrl().isEmpty())
|
||||||
text += tr("cleared the avatar");
|
text += tr("cleared the avatar");
|
||||||
else
|
else
|
||||||
text += tr("updated the avatar");
|
text += tr("updated the avatar");
|
||||||
|
@ -246,73 +230,68 @@ QVariant MessageEventModel::data(const QModelIndex& index, int role) const
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
case MembershipType::Leave:
|
case MembershipType::Leave:
|
||||||
if (e->prev_content() &&
|
if (e.prevContent() &&
|
||||||
e->prev_content()->membership == MembershipType::Ban)
|
e.prevContent()->membership == MembershipType::Ban)
|
||||||
{
|
{
|
||||||
if (e->senderId() != e->userId())
|
return (e.senderId() != e.userId())
|
||||||
return tr("unbanned %1").arg(subjectName);
|
? tr("unbanned %1").arg(subjectName)
|
||||||
else
|
: tr("self-unbanned");
|
||||||
return tr("self-unbanned");
|
|
||||||
}
|
}
|
||||||
if (e->senderId() != e->userId())
|
return (e.senderId() != e.userId())
|
||||||
return tr("has put %1 out of the room").arg(subjectName);
|
? tr("has put %1 out of the room").arg(subjectName)
|
||||||
else
|
: tr("left the room");
|
||||||
return tr("left the room");
|
|
||||||
case MembershipType::Ban:
|
case MembershipType::Ban:
|
||||||
if (e->senderId() != e->userId())
|
return (e.senderId() != e.userId())
|
||||||
return tr("banned %1 from the room").arg(subjectName);
|
? tr("banned %1 from the room").arg(subjectName)
|
||||||
else
|
: tr("self-banned from the room");
|
||||||
return tr("self-banned from the room");
|
|
||||||
case MembershipType::Knock:
|
case MembershipType::Knock:
|
||||||
return tr("knocked");
|
return tr("knocked");
|
||||||
// case MembershipType::Unknown;
|
default:
|
||||||
// return tr("made something unknown");
|
;
|
||||||
}
|
}
|
||||||
|
return tr("made something unknown");
|
||||||
}
|
}
|
||||||
if(event->type() == EventType::RoomAliases)
|
, [] (const RoomAliasesEvent& e) -> QVariant {
|
||||||
{
|
return tr("set aliases to: %1").arg(e.aliases().join(", "));
|
||||||
auto* e = static_cast<const RoomAliasesEvent*>(event);
|
|
||||||
return tr("set aliases to: %1").arg(e->aliases().join(", "));
|
|
||||||
}
|
}
|
||||||
if(event->type() == EventType::RoomCanonicalAlias)
|
, [] (const RoomCanonicalAliasEvent& e) -> QVariant {
|
||||||
{
|
return (e.alias().isEmpty())
|
||||||
auto* e = static_cast<const RoomCanonicalAliasEvent*>(event);
|
? tr("cleared the room main alias")
|
||||||
return tr("set the room main alias to: %1").arg(e->alias());
|
: tr("set the room main alias to: %1").arg(e.alias());
|
||||||
}
|
}
|
||||||
if(event->type() == EventType::RoomName)
|
, [] (const RoomNameEvent& e) -> QVariant {
|
||||||
{
|
return (e.name().isEmpty())
|
||||||
auto* e = static_cast<const RoomNameEvent*>(event);
|
? tr("cleared the room name")
|
||||||
return tr("set the room name to: %1").arg(e->name());
|
: tr("set the room name to: %1").arg(e.name());
|
||||||
}
|
}
|
||||||
if(event->type() == EventType::RoomTopic)
|
, [] (const RoomTopicEvent& e) -> QVariant {
|
||||||
{
|
return (e.topic().isEmpty())
|
||||||
auto* e = static_cast<const RoomTopicEvent*>(event);
|
? tr("cleared the topic")
|
||||||
return tr("set the topic to: %1").arg(e->topic());
|
: tr("set the topic to: %1").arg(e.topic());
|
||||||
}
|
}
|
||||||
if(event->type() == EventType::RoomAvatar)
|
, [] (const RoomAvatarEvent&) -> QVariant {
|
||||||
{
|
|
||||||
return tr("changed the room avatar");
|
return tr("changed the room avatar");
|
||||||
}
|
}
|
||||||
if(event->type() == EventType::RoomEncryption)
|
, [] (const EncryptionEvent&) -> QVariant {
|
||||||
{
|
|
||||||
return tr("activated End-to-End Encryption");
|
return tr("activated End-to-End Encryption");
|
||||||
}
|
}
|
||||||
return tr("Unknown Event");
|
, tr("Unknown Event")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(role == Qt::ToolTipRole)
|
if( role == Qt::ToolTipRole )
|
||||||
{
|
{
|
||||||
return event->originalJson();
|
return ti->originalJson();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(role == EventTypeRole)
|
if( role == EventTypeRole )
|
||||||
{
|
{
|
||||||
if (event->isStateEvent())
|
if (ti->isStateEvent())
|
||||||
return "state";
|
return "state";
|
||||||
|
|
||||||
if (event->type() == EventType::RoomMessage)
|
if (auto e = ti.viewAs<RoomMessageEvent>())
|
||||||
{
|
{
|
||||||
switch (static_cast<const RoomMessageEvent*>(event)->msgtype())
|
switch (e->msgtype())
|
||||||
{
|
{
|
||||||
case MessageEventType::Emote:
|
case MessageEventType::Emote:
|
||||||
return "emote";
|
return "emote";
|
||||||
|
@ -328,44 +307,31 @@ QVariant MessageEventModel::data(const QModelIndex& index, int role) const
|
||||||
return "message";
|
return "message";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "other";
|
return "other";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(role == TimeRole)
|
if (role == EventResolvedTypeRole)
|
||||||
return makeMessageTimestamp(eventIt);
|
return EventTypeRegistry::getMatrixType(ti->type());
|
||||||
|
|
||||||
if(role == SectionRole)
|
if( role == TimeRole )
|
||||||
return makeDateString(eventIt); // FIXME: move date rendering to QML
|
return makeMessageTimestamp(timelineIt);
|
||||||
|
|
||||||
if(role == AboveSectionRole) // FIXME: shouldn't be here, because #312
|
if( role == SectionRole )
|
||||||
|
return makeDateString(timelineIt); // FIXME: move date rendering to QML
|
||||||
|
|
||||||
|
if( role == AuthorRole )
|
||||||
{
|
{
|
||||||
auto aboveEventIt = eventIt + 1;
|
auto userId = ti->senderId();
|
||||||
if (aboveEventIt != m_currentRoom->timelineEdge())
|
// FIXME: It shouldn't be User, it should be its state "as of event"
|
||||||
return makeDateString(aboveEventIt);
|
return QVariant::fromValue(m_currentRoom->user(userId));
|
||||||
}
|
|
||||||
|
|
||||||
if(role == AuthorRole)
|
|
||||||
{
|
|
||||||
auto userId = event->senderId();
|
|
||||||
// FIXME: This will go away after senderName is generated correctly
|
|
||||||
// (see the FIXME in the beginning of the method).
|
|
||||||
// if (event->type() == EventType::RoomMember)
|
|
||||||
// {
|
|
||||||
// const auto* e = static_cast<const RoomMemberEvent*>(event);
|
|
||||||
// if (e->senderId() == e->userId() /*???*/ && e->prev_content()
|
|
||||||
// && !e->prev_content()->displayName.isEmpty())
|
|
||||||
// userId = e->prevSenderId();
|
|
||||||
// }
|
|
||||||
return QVariant::fromValue(m_currentRoom->connection()->user(userId));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role == ContentTypeRole)
|
if (role == ContentTypeRole)
|
||||||
{
|
{
|
||||||
if (event->type() == EventType::RoomMessage)
|
if (is<RoomMessageEvent>(*ti))
|
||||||
{
|
{
|
||||||
const auto& contentType =
|
const auto& contentType =
|
||||||
static_cast<const RoomMessageEvent*>(event)->mimeType().name();
|
ti.viewAs<RoomMessageEvent>()->mimeType().name();
|
||||||
return contentType == "text/plain" ? "text/html" : contentType;
|
return contentType == "text/plain" ? "text/html" : contentType;
|
||||||
}
|
}
|
||||||
return "text/plain";
|
return "text/plain";
|
||||||
|
@ -373,21 +339,19 @@ QVariant MessageEventModel::data(const QModelIndex& index, int role) const
|
||||||
|
|
||||||
if (role == ContentRole)
|
if (role == ContentRole)
|
||||||
{
|
{
|
||||||
if (event->isRedacted())
|
if (ti->isRedacted())
|
||||||
{
|
{
|
||||||
auto reason = event->redactedBecause()->reason();
|
auto reason = ti->redactedBecause()->reason();
|
||||||
if (reason.isEmpty())
|
return (reason.isEmpty())
|
||||||
return tr("Redacted");
|
? tr("Redacted")
|
||||||
else
|
: tr("Redacted: %1").arg(ti->redactedBecause()->reason());
|
||||||
return tr("Redacted: %1")
|
|
||||||
.arg(event->redactedBecause()->reason());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(event->type() == EventType::RoomMessage)
|
if (is<RoomMessageEvent>(*ti))
|
||||||
{
|
{
|
||||||
using namespace MessageEventContent;
|
using namespace MessageEventContent;
|
||||||
|
|
||||||
auto* e = static_cast<const RoomMessageEvent*>(event);
|
auto* e = ti.viewAs<RoomMessageEvent>();
|
||||||
switch (e->msgtype())
|
switch (e->msgtype())
|
||||||
{
|
{
|
||||||
case MessageEventType::Image:
|
case MessageEventType::Image:
|
||||||
|
@ -401,29 +365,64 @@ QVariant MessageEventModel::data(const QModelIndex& index, int role) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(role == ReadMarkerRole)
|
if( role == HighlightRole )
|
||||||
return event->id() == lastReadEventId;
|
return QVariant();
|
||||||
|
|
||||||
if(role == SpecialMarksRole)
|
if( role == ReadMarkerRole )
|
||||||
|
return ti->id() == lastReadEventId;
|
||||||
|
|
||||||
|
if( role == SpecialMarksRole )
|
||||||
{
|
{
|
||||||
if (event->isStateEvent() &&
|
if (auto e = ti.viewAs<StateEventBase>())
|
||||||
static_cast<const StateEventBase*>(event)->repeatsState())
|
if (e->repeatsState())
|
||||||
return "hidden";
|
return "hidden";
|
||||||
return event->isRedacted() ? "redacted" : "";
|
return ti->isRedacted() ? "redacted" : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(role == EventIdRole)
|
if( role == EventIdRole )
|
||||||
return event->id();
|
return ti->id();
|
||||||
|
|
||||||
if(role == LongOperationRole)
|
if( role == LongOperationRole )
|
||||||
{
|
{
|
||||||
if (event->type() == EventType::RoomMessage &&
|
if (is<RoomMessageEvent>(*ti) &&
|
||||||
static_cast<const RoomMessageEvent*>(event)->hasFileContent())
|
ti.viewAs<RoomMessageEvent>()->hasFileContent())
|
||||||
{
|
{
|
||||||
auto info = m_currentRoom->fileTransferInfo(event->id());
|
auto info = m_currentRoom->fileTransferInfo(ti->id());
|
||||||
return QVariant::fromValue(info);
|
return QVariant::fromValue(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto aboveEventIt = timelineIt + 1; // FIXME: shouldn't be here, because #312
|
||||||
|
if (aboveEventIt != m_currentRoom->timelineEdge())
|
||||||
|
{
|
||||||
|
if( role == AboveSectionRole )
|
||||||
|
return makeDateString(aboveEventIt);
|
||||||
|
|
||||||
|
if( role == AboveAuthorRole )
|
||||||
|
return QVariant::fromValue(
|
||||||
|
m_currentRoom->user((*aboveEventIt)->senderId()));
|
||||||
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QHash<int, QByteArray> MessageEventModel::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
|
||||||
|
roles[EventTypeRole] = "eventType";
|
||||||
|
roles[EventIdRole] = "eventId";
|
||||||
|
roles[TimeRole] = "time";
|
||||||
|
roles[SectionRole] = "section";
|
||||||
|
roles[AboveSectionRole] = "aboveSection";
|
||||||
|
roles[AuthorRole] = "author";
|
||||||
|
roles[AboveAuthorRole] = "aboveAuthor";
|
||||||
|
roles[ContentRole] = "content";
|
||||||
|
roles[ContentTypeRole] = "contentType";
|
||||||
|
roles[HighlightRole] = "highlight";
|
||||||
|
roles[ReadMarkerRole] = "readMarker";
|
||||||
|
roles[SpecialMarksRole] = "marks";
|
||||||
|
roles[LongOperationRole] = "progressInfo";
|
||||||
|
roles[EventResolvedTypeRole] = "eventResolvedType";
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
|
|
@ -7,12 +7,7 @@
|
||||||
class MessageEventModel: public QAbstractListModel
|
class MessageEventModel: public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
// The below property is marked constant because it only changes
|
Q_PROPERTY(QMatrixClient::Room* room READ getRoom WRITE setRoom NOTIFY roomChanged)
|
||||||
// when the whole model is reset (so anything that depends on the model
|
|
||||||
// has to be re-calculated anyway).
|
|
||||||
// XXX: A better way would be to make [Room::]Timeline a list model
|
|
||||||
// itself, leaving only representation of the model to a client.
|
|
||||||
Q_PROPERTY(QMatrixClient::Room* room MEMBER m_currentRoom CONSTANT)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum EventRoles {
|
enum EventRoles {
|
||||||
|
@ -22,31 +17,40 @@ class MessageEventModel: public QAbstractListModel
|
||||||
SectionRole,
|
SectionRole,
|
||||||
AboveSectionRole,
|
AboveSectionRole,
|
||||||
AuthorRole,
|
AuthorRole,
|
||||||
|
AboveAuthorRole,
|
||||||
ContentRole,
|
ContentRole,
|
||||||
ContentTypeRole,
|
ContentTypeRole,
|
||||||
|
HighlightRole,
|
||||||
ReadMarkerRole,
|
ReadMarkerRole,
|
||||||
SpecialMarksRole,
|
SpecialMarksRole,
|
||||||
LongOperationRole,
|
LongOperationRole,
|
||||||
|
// For debugging
|
||||||
|
EventResolvedTypeRole,
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit MessageEventModel(QObject* parent = nullptr);
|
explicit MessageEventModel(QObject* parent = nullptr);
|
||||||
|
~MessageEventModel();
|
||||||
|
|
||||||
void changeRoom(QMatrixClient::Room* room);
|
QMatrixClient::Room* getRoom() { return m_currentRoom; }
|
||||||
|
void setRoom(QMatrixClient::Room* room);
|
||||||
|
|
||||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
Q_INVOKABLE int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex& index, int role) const override;
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void refreshEvent(const QString& eventId);
|
void refreshEvent(const QString& eventId);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMatrixClient::Room* m_currentRoom;
|
QMatrixClient::Room* m_currentRoom = nullptr;
|
||||||
QString lastReadEventId;
|
QString lastReadEventId;
|
||||||
|
|
||||||
QDateTime makeMessageTimestamp(QMatrixClient::Room::rev_iter_t baseIt) const;
|
QDateTime makeMessageTimestamp(QMatrixClient::Room::rev_iter_t baseIt) const;
|
||||||
QString makeDateString(QMatrixClient::Room::rev_iter_t baseIt) const;
|
QString makeDateString(QMatrixClient::Room::rev_iter_t baseIt) const;
|
||||||
void refreshEventRoles(const QString& eventId, const QVector<int> roles);
|
void refreshEventRoles(const QString& eventId, const QVector<int> roles);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void roomChanged();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MESSAGEEVENTMODEL_H
|
#endif // MESSAGEEVENTMODEL_H
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
RoomListModel::RoomListModel(QObject* parent)
|
RoomListModel::RoomListModel(QObject* parent)
|
||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent)
|
||||||
{
|
{
|
||||||
m_connection = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RoomListModel::~RoomListModel()
|
RoomListModel::~RoomListModel()
|
||||||
|
|
|
@ -30,7 +30,7 @@ class RoomListModel: public QAbstractListModel
|
||||||
void addRoom(QMatrixClient::Room* room);
|
void addRoom(QMatrixClient::Room* room);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMatrixClient::Connection* m_connection;
|
QMatrixClient::Connection* m_connection = nullptr;
|
||||||
QList<QMatrixClient::Room*> m_rooms;
|
QList<QMatrixClient::Room*> m_rooms;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
|
@ -80,14 +80,7 @@ Item {
|
||||||
function applyFilter(filterName){
|
function applyFilter(filterName){
|
||||||
var roomCount = listModel.rowCount();
|
var roomCount = listModel.rowCount();
|
||||||
for (var i = 0; i < roomCount; i++){
|
for (var i = 0; i < roomCount; i++){
|
||||||
var roomName = "";
|
var roomName = listModel.roomAt(i).displayName;
|
||||||
if (listModel.roomAt(i).name !== "") {
|
|
||||||
roomName = listModel.roomAt(i).name;
|
|
||||||
} else if (model.alias !== "") {
|
|
||||||
roomName = listModel.roomAt(i).alias;
|
|
||||||
} else {
|
|
||||||
roomName = listModel.roomAt(i).id;
|
|
||||||
}
|
|
||||||
if (roomName.toLowerCase().indexOf(filterName.toLowerCase()) !== -1) {
|
if (roomName.toLowerCase().indexOf(filterName.toLowerCase()) !== -1) {
|
||||||
items.addGroups(i, 1, "filterGroup");
|
items.addGroups(i, 1, "filterGroup");
|
||||||
} else {items.removeGroups(i, 1, "filterGroup");}
|
} else {items.removeGroups(i, 1, "filterGroup");}
|
||||||
|
|
|
@ -52,7 +52,7 @@ Item {
|
||||||
ImageStatus {
|
ImageStatus {
|
||||||
Layout.preferredWidth: parent.height
|
Layout.preferredWidth: parent.height
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
source: "qrc:/asset/img/avatar.png"
|
source: currentRoom != null && currentRoom.avatarUrl != "" ? "image://mxc/" + currentRoom.avatarUrl : "qrc:/asset/img/avatar.png"
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
|
@ -88,34 +88,35 @@ Item {
|
||||||
displayMarginEnd: 40
|
displayMarginEnd: 40
|
||||||
verticalLayoutDirection: ListView.BottomToTop
|
verticalLayoutDirection: ListView.BottomToTop
|
||||||
spacing: 12
|
spacing: 12
|
||||||
// model: MessageEventModel{ currentRoom: item.currentRoom }
|
model: MessageEventModel{
|
||||||
model: 10
|
id: messageEventModel
|
||||||
|
room: currentRoom
|
||||||
|
}
|
||||||
delegate: Row {
|
delegate: Row {
|
||||||
readonly property bool sentByMe: index % 2 == 0
|
readonly property bool sentByMe: author === currentRoom.localUser
|
||||||
|
|
||||||
id: messageRow
|
id: messageRow
|
||||||
|
|
||||||
height: 40
|
|
||||||
anchors.right: sentByMe ? parent.right : undefined
|
anchors.right: sentByMe ? parent.right : undefined
|
||||||
spacing: 6
|
spacing: 6
|
||||||
|
|
||||||
Rectangle {
|
Image {
|
||||||
id: avatar
|
id: avatar
|
||||||
width: height
|
width: height
|
||||||
height: parent.height
|
height: 40
|
||||||
color: "grey"
|
|
||||||
visible: !sentByMe
|
visible: !sentByMe
|
||||||
|
source: author.avatarUrl != "" ? "image://mxc/" + author.avatarUrl : "qrc:/asset/img/avatar.png"
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
width: Math.min(messageText.implicitWidth + 24,
|
width: Math.min(messageText.implicitWidth + 24,
|
||||||
messageListView.width - (!sentByMe ? avatar.width + messageRow.spacing : 0))
|
messageListView.width - (!sentByMe ? avatar.width + messageRow.spacing : 0))
|
||||||
height: parent.height
|
height: messageText.implicitHeight + 24
|
||||||
color: sentByMe ? "lightgrey" : Material.accent
|
color: sentByMe ? "lightgrey" : Material.accent
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
id: messageText
|
id: messageText
|
||||||
text: index
|
text: display
|
||||||
color: sentByMe ? "black" : "white"
|
color: sentByMe ? "black" : "white"
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: 12
|
anchors.margins: 12
|
||||||
|
@ -146,6 +147,7 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
TextField {
|
TextField {
|
||||||
|
id: inputField
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
placeholderText: "Send a Message"
|
placeholderText: "Send a Message"
|
||||||
|
@ -157,6 +159,11 @@ Item {
|
||||||
background: Rectangle {
|
background: Rectangle {
|
||||||
color: Material.theme == Material.Light ? "#eaeaea" : "#242424"
|
color: Material.theme == Material.Light ? "#eaeaea" : "#242424"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Keys.onReturnPressed: {
|
||||||
|
currentRoom.postMessage("text", inputField.text)
|
||||||
|
inputField.text = ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemDelegate {
|
ItemDelegate {
|
||||||
|
|
|
@ -118,7 +118,7 @@ ApplicationWindow {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: 15
|
anchors.margins: 15
|
||||||
|
|
||||||
source: "qrc:/asset/img/avatar.png"
|
source: matriqueController.connection.localUser != null ? "image://mxc/" + matriqueController.connection.localUser.avatarUrl : "qrc:/asset/img/avatar.png"
|
||||||
opaqueBackground: false
|
opaqueBackground: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue