summary refs log tree commit diff
path: root/src/timeline
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2023-08-13 11:30:41 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2023-08-25 19:03:16 +0200
commit2360dfd80ae8991c557c9c7d9474c528c00fdaa6 (patch)
tree70a357307798038525871a5e12e422babc342ccd /src/timeline
parentGet rid of redundant constructions and make room implicit (diff)
downloadnheko-2360dfd80ae8991c557c9c7d9474c528c00fdaa6.tar.xz
Remaining events apart from verification
Diffstat (limited to 'src/timeline')
-rw-r--r--src/timeline/EventDelegateChooser.cpp27
-rw-r--r--src/timeline/TimelineModel.cpp42
-rw-r--r--src/timeline/TimelineModel.h3
3 files changed, 36 insertions, 36 deletions
diff --git a/src/timeline/EventDelegateChooser.cpp b/src/timeline/EventDelegateChooser.cpp
index 7fec38dd..2218d9ee 100644
--- a/src/timeline/EventDelegateChooser.cpp
+++ b/src/timeline/EventDelegateChooser.cpp
@@ -195,17 +195,22 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj)
 
     if (!forReply) {
         auto row = chooser.room_->idToIndex(currentId);
-        connect(chooser.room_,
-                &QAbstractItemModel::dataChanged,
-                obj,
-                [row, update](const QModelIndex &topLeft,
-                              const QModelIndex &bottomRight,
-                              const QList<int> &changedRoles) {
-                    if (row < topLeft.row() || row > bottomRight.row())
-                        return;
-
-                    update(changedRoles);
-                });
+        auto connection = connect(
+          chooser.room_,
+          &QAbstractItemModel::dataChanged,
+          obj,
+          [row, update](const QModelIndex &topLeft,
+                        const QModelIndex &bottomRight,
+                        const QList<int> &changedRoles) {
+              if (row < topLeft.row() || row > bottomRight.row())
+                  return;
+
+              update(changedRoles);
+          },
+          Qt::QueuedConnection);
+        connect(&this->chooser, &EventDelegateChooser::destroyed, obj, [connection]() {
+            QObject::disconnect(connection);
+        });
     }
 }
 
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index 66f7d5b8..3e0c6688 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -757,6 +757,8 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
                       return formatHistoryVisibilityEvent(e);
                   else if constexpr (t == mtx::events::EventType::RoomGuestAccess)
                       return formatGuestAccessEvent(e);
+                  else if constexpr (t == mtx::events::EventType::RoomMember)
+                      return formatMemberEvent(e);
 
                   return tr("%1 changed unknown state event %2.")
                     .arg(displayName(QString::fromStdString(e.sender)))
@@ -2958,34 +2960,27 @@ TimelineModel::joinReplacementRoom(const QString &id)
 }
 
 QString
-TimelineModel::formatMemberEvent(const QString &id)
+TimelineModel::formatMemberEvent(
+  const mtx::events::StateEvent<mtx::events::state::Member> &event) const
 {
-    auto e = events.get(id.toStdString(), "");
-    if (!e)
-        return {};
-
-    auto event = std::get_if<mtx::events::StateEvent<mtx::events::state::Member>>(e);
-    if (!event)
-        return {};
-
     mtx::events::StateEvent<mtx::events::state::Member> const *prevEvent = nullptr;
-    if (!event->unsigned_data.replaces_state.empty()) {
-        auto tempPrevEvent = events.get(event->unsigned_data.replaces_state, event->event_id);
+    if (!event.unsigned_data.replaces_state.empty()) {
+        auto tempPrevEvent = events.get(event.unsigned_data.replaces_state, event.event_id);
         if (tempPrevEvent) {
             prevEvent =
               std::get_if<mtx::events::StateEvent<mtx::events::state::Member>>(tempPrevEvent);
         }
     }
 
-    QString user = QString::fromStdString(event->state_key);
+    QString user = QString::fromStdString(event.state_key);
     QString name = utils::replaceEmoji(displayName(user));
     QString rendered;
-    QString sender     = QString::fromStdString(event->sender);
+    QString sender     = QString::fromStdString(event.sender);
     QString senderName = utils::replaceEmoji(displayName(sender));
 
     // see table https://matrix.org/docs/spec/client_server/latest#m-room-member
     using namespace mtx::events::state;
-    switch (event->content.membership) {
+    switch (event.content.membership) {
     case Membership::Invite:
         rendered = tr("%1 invited %2.").arg(senderName, name);
         break;
@@ -2994,9 +2989,8 @@ TimelineModel::formatMemberEvent(const QString &id)
             QString oldName = utils::replaceEmoji(
               QString::fromStdString(prevEvent->content.display_name).toHtmlEscaped());
 
-            bool displayNameChanged =
-              prevEvent->content.display_name != event->content.display_name;
-            bool avatarChanged = prevEvent->content.avatar_url != event->content.avatar_url;
+            bool displayNameChanged = prevEvent->content.display_name != event.content.display_name;
+            bool avatarChanged      = prevEvent->content.avatar_url != event.content.avatar_url;
 
             if (displayNameChanged && avatarChanged)
                 rendered = tr("%1 has changed their avatar and changed their "
@@ -3011,30 +3005,30 @@ TimelineModel::formatMemberEvent(const QString &id)
             // the case of nothing changed but join follows join shouldn't happen, so
             // just show it as join
         } else {
-            if (event->content.join_authorised_via_users_server.empty())
+            if (event.content.join_authorised_via_users_server.empty())
                 rendered = tr("%1 joined.").arg(name);
             else
                 rendered =
                   tr("%1 joined via authorisation from %2's server.")
                     .arg(name,
-                         QString::fromStdString(event->content.join_authorised_via_users_server));
+                         QString::fromStdString(event.content.join_authorised_via_users_server));
         }
         break;
     case Membership::Leave:
         if (!prevEvent || prevEvent->content.membership == Membership::Join) {
-            if (event->state_key == event->sender)
+            if (event.state_key == event.sender)
                 rendered = tr("%1 left the room.").arg(name);
             else
                 rendered = tr("%2 kicked %1.").arg(name, senderName);
         } else if (prevEvent->content.membership == Membership::Invite) {
-            if (event->state_key == event->sender)
+            if (event.state_key == event.sender)
                 rendered = tr("%1 rejected their invite.").arg(name);
             else
                 rendered = tr("%2 revoked the invite to %1.").arg(name, senderName);
         } else if (prevEvent->content.membership == Membership::Ban) {
             rendered = tr("%2 unbanned %1.").arg(name, senderName);
         } else if (prevEvent->content.membership == Membership::Knock) {
-            if (event->state_key == event->sender)
+            if (event.state_key == event.sender)
                 rendered = tr("%1 redacted their knock.").arg(name);
             else
                 rendered = tr("%2 rejected the knock from %1.").arg(name, senderName);
@@ -3053,8 +3047,8 @@ TimelineModel::formatMemberEvent(const QString &id)
         break;
     }
 
-    if (event->content.reason != "") {
-        rendered += " " + tr("Reason: %1").arg(QString::fromStdString(event->content.reason));
+    if (event.content.reason != "") {
+        rendered += " " + tr("Reason: %1").arg(QString::fromStdString(event.content.reason));
     }
 
     return rendered;
diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h
index 2b22ad61..8f787f21 100644
--- a/src/timeline/TimelineModel.h
+++ b/src/timeline/TimelineModel.h
@@ -310,7 +310,8 @@ public:
     Q_INVOKABLE bool showAcceptKnockButton(const QString &id);
     Q_INVOKABLE void acceptKnock(const QString &id);
     Q_INVOKABLE void joinReplacementRoom(const QString &id);
-    Q_INVOKABLE QString formatMemberEvent(const QString &id);
+    Q_INVOKABLE QString
+    formatMemberEvent(const mtx::events::StateEvent<mtx::events::state::Member> &event) const;
     Q_INVOKABLE QString formatJoinRuleEvent(const QString &id);
     QString formatHistoryVisibilityEvent(
       const mtx::events::StateEvent<mtx::events::state::HistoryVisibility> &event) const;