summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2023-06-25 02:40:44 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2023-08-25 19:03:14 +0200
commit76b40f452b8313db972e44f5eca30f59b7fdf4d3 (patch)
treeb9bd90caa90513121e65ef697e94403ed09cf036 /src
parentCreate an EventDelegateChooser (diff)
downloadnheko-76b40f452b8313db972e44f5eca30f59b7fdf4d3.tar.xz
Working text messages in delegate rework
Diffstat (limited to 'src')
-rw-r--r--src/timeline/EventDelegateChooser.cpp26
-rw-r--r--src/timeline/EventDelegateChooser.h5
2 files changed, 27 insertions, 4 deletions
diff --git a/src/timeline/EventDelegateChooser.cpp b/src/timeline/EventDelegateChooser.cpp
index 7618e20b..5e6ee37e 100644
--- a/src/timeline/EventDelegateChooser.cpp
+++ b/src/timeline/EventDelegateChooser.cpp
@@ -85,6 +85,7 @@ EventDelegateChooser::componentComplete()
 {
     QQuickItem::componentComplete();
     // eventIncubator.reset(eventIndex);
+    // eventIncubator.forceCompletion();
 }
 
 void
@@ -104,6 +105,7 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj)
 
     QHash<int, int> roleToPropIdx;
     std::vector<QModelRoleData> roles;
+    bool isReplyNeeded = false;
 
     // Workaround for https://bugreports.qt.io/browse/QTBUG-98846
     QHash<QString, RequiredPropertyKey> requiredProperties;
@@ -121,7 +123,10 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj)
         if (!prop.isRequired() && !requiredProperties.contains(prop.name()))
             continue;
 
-        if (auto role = nameToRole.find(prop.name()); role != nameToRole.end()) {
+        if (prop.name() == std::string_view("isReply")) {
+            isReplyNeeded = true;
+            roleToPropIdx.insert(-1, i);
+        } else if (auto role = nameToRole.find(prop.name()); role != nameToRole.end()) {
             roleToPropIdx.insert(*role, i);
             roles.emplace_back(*role);
 
@@ -134,13 +139,26 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj)
     nhlog::ui()->debug("Querying data for id {}", currentId.toStdString());
     chooser.room_->multiData(currentId, forReply ? chooser.eventId_ : QString(), roles);
 
-    QVariantMap rolesToSet;
     for (const auto &role : roles) {
         const auto &roleName = roleNames[role.role()];
-        nhlog::ui()->critical("Setting role {}, {}", role.role(), roleName.toStdString());
+        nhlog::ui()->critical("Setting role {}, {} to {}",
+                              role.role(),
+                              roleName.toStdString(),
+                              role.data().toString().toStdString());
 
+        nhlog::ui()->critical("Setting {}", mo->property(roleToPropIdx[role.role()]).name());
         mo->property(roleToPropIdx[role.role()]).write(obj, role.data());
-        rolesToSet.insert(roleName, role.data());
+
+        if (const auto &req = requiredProperties.find(roleName); req != requiredProperties.end())
+            QQmlIncubatorPrivate::get(this)->requiredProperties()->remove(*req);
+    }
+
+    if (isReplyNeeded) {
+        const auto roleName = QByteArray("isReply");
+        nhlog::ui()->critical("Setting role {} to {}", roleName.toStdString(), forReply);
+
+        nhlog::ui()->critical("Setting {}", mo->property(roleToPropIdx[-1]).name());
+        mo->property(roleToPropIdx[-1]).write(obj, forReply);
 
         if (const auto &req = requiredProperties.find(roleName); req != requiredProperties.end())
             QQmlIncubatorPrivate::get(this)->requiredProperties()->remove(*req);
diff --git a/src/timeline/EventDelegateChooser.h b/src/timeline/EventDelegateChooser.h
index ce22ca3a..b627b383 100644
--- a/src/timeline/EventDelegateChooser.h
+++ b/src/timeline/EventDelegateChooser.h
@@ -54,6 +54,7 @@ class EventDelegateChooser : public QQuickItem
 public:
     Q_PROPERTY(QQmlListProperty<EventDelegateChoice> choices READ choices CONSTANT FINAL)
     Q_PROPERTY(QQuickItem *main READ main NOTIFY mainChanged FINAL)
+    Q_PROPERTY(QQuickItem *reply READ reply NOTIFY replyChanged FINAL)
     Q_PROPERTY(TimelineModel *room READ room WRITE setRoom NOTIFY roomChanged REQUIRED FINAL)
     Q_PROPERTY(QString eventId READ eventId WRITE setEventId NOTIFY eventIdChanged REQUIRED FINAL)
     Q_PROPERTY(QString replyTo READ replyTo WRITE setReplyTo NOTIFY replyToChanged REQUIRED FINAL)
@@ -64,6 +65,10 @@ public:
     {
         return qobject_cast<QQuickItem *>(eventIncubator.object());
     }
+    [[nodiscard]] QQuickItem *reply() const
+    {
+        return qobject_cast<QQuickItem *>(replyIncubator.object());
+    }
 
     void setRoom(TimelineModel *m)
     {