summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2023-07-28 20:05:47 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2023-08-25 19:03:15 +0200
commit718a58d388abd228c6a08f9fa3365588c06923ba (patch)
treedab9877a7bd16fd291fcd16262d868cf87469c67 /src
parentPort redacted messages (diff)
downloadnheko-718a58d388abd228c6a08f9fa3365588c06923ba.tar.xz
Get rid of redundant constructions and make room implicit
Diffstat (limited to 'src')
-rw-r--r--src/timeline/EventDelegateChooser.cpp6
-rw-r--r--src/timeline/EventDelegateChooser.h15
-rw-r--r--src/timeline/TimelineModel.cpp3
-rw-r--r--src/timeline/TimelineModel.h1
4 files changed, 21 insertions, 4 deletions
diff --git a/src/timeline/EventDelegateChooser.cpp b/src/timeline/EventDelegateChooser.cpp
index 5e6ee37e..7fec38dd 100644
--- a/src/timeline/EventDelegateChooser.cpp
+++ b/src/timeline/EventDelegateChooser.cpp
@@ -84,7 +84,8 @@ void
 EventDelegateChooser::componentComplete()
 {
     QQuickItem::componentComplete();
-    // eventIncubator.reset(eventIndex);
+    eventIncubator.reset(eventId_);
+    replyIncubator.reset(replyId);
     // eventIncubator.forceCompletion();
 }
 
@@ -226,6 +227,9 @@ EventDelegateChooser::DelegateIncubator::reset(QString id)
     for (const auto choice : qAsConst(chooser.choices_)) {
         const auto &choiceValue = choice->roleValues();
         if (choiceValue.contains(role) || choiceValue.empty()) {
+            nhlog::ui()->debug(
+              "Instantiating type: {}, c {}", (int)role, choiceValue.contains(role));
+
             if (auto child = qobject_cast<QQuickItem *>(object())) {
                 child->setParentItem(nullptr);
             }
diff --git a/src/timeline/EventDelegateChooser.h b/src/timeline/EventDelegateChooser.h
index b627b383..1cd2d65a 100644
--- a/src/timeline/EventDelegateChooser.h
+++ b/src/timeline/EventDelegateChooser.h
@@ -55,9 +55,9 @@ 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)
+    Q_PROPERTY(TimelineModel *room READ room WRITE setRoom NOTIFY roomChanged REQUIRED FINAL)
 
     QQmlListProperty<EventDelegateChoice> choices();
 
@@ -74,9 +74,12 @@ public:
     {
         if (m != room_) {
             room_ = m;
-            eventIncubator.reset(eventId_);
-            replyIncubator.reset(replyId);
             emit roomChanged();
+
+            if (isComponentComplete()) {
+                eventIncubator.reset(eventId_);
+                replyIncubator.reset(replyId);
+            }
         }
     }
     [[nodiscard]] TimelineModel *room() { return room_; }
@@ -85,12 +88,18 @@ public:
     {
         eventId_ = idx;
         emit eventIdChanged();
+
+        if (isComponentComplete())
+            eventIncubator.reset(eventId_);
     }
     [[nodiscard]] QString eventId() const { return eventId_; }
     void setReplyTo(QString id)
     {
         replyId = id;
         emit replyToChanged();
+
+        if (isComponentComplete())
+            replyIncubator.reset(replyId);
     }
     [[nodiscard]] QString replyTo() const { return replyId; }
 
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index 066d8b01..66f7d5b8 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -561,6 +561,7 @@ TimelineModel::roleNames() const
       {ReplyTo, "replyTo"},
       {ThreadId, "threadId"},
       {Reactions, "reactions"},
+      {Room, "room"},
       {RoomId, "roomId"},
       {RoomName, "roomName"},
       {RoomTopic, "roomTopic"},
@@ -899,6 +900,8 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
         auto id = relations(event).replaces().value_or(event_id(event));
         return QVariant::fromValue(events.reactions(id));
     }
+    case Room:
+        return QVariant::fromValue(this);
     case RoomId:
         return QVariant(room_id_);
     case RoomName:
diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h
index b81fc209..2b22ad61 100644
--- a/src/timeline/TimelineModel.h
+++ b/src/timeline/TimelineModel.h
@@ -267,6 +267,7 @@ public:
         ReplyTo,
         ThreadId,
         Reactions,
+        Room,
         RoomId,
         RoomName,
         RoomTopic,