From e98a61fea60cf3b95441ce3d9591ced0cf93f566 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Tue, 10 Dec 2019 14:46:52 +0100 Subject: [PATCH] Show topic and name changes in timeline --- resources/qml/delegates/MessageDelegate.qml | 12 ++++++++ resources/qml/delegates/NoticeMessage.qml | 3 +- src/timeline/TimelineModel.cpp | 32 +++++++++++++++++++++ src/timeline/TimelineModel.h | 2 ++ 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/resources/qml/delegates/MessageDelegate.qml b/resources/qml/delegates/MessageDelegate.qml index 178dfd86..20ec71e5 100644 --- a/resources/qml/delegates/MessageDelegate.qml +++ b/resources/qml/delegates/MessageDelegate.qml @@ -49,6 +49,18 @@ DelegateChooser { text: qsTr("Encryption enabled") } } + DelegateChoice { + roleValue: MtxEvent.Name + NoticeMessage { + notice: model.roomName ? qsTr("room name changed to: %1").arg(model.roomName) : qsTr("removed room name") + } + } + DelegateChoice { + roleValue: MtxEvent.Topic + NoticeMessage { + notice: model.roomTopic ? qsTr("topic changed to: %1").arg(model.roomTopic) : qsTr("removed topic") + } + } DelegateChoice { Placeholder {} } diff --git a/resources/qml/delegates/NoticeMessage.qml b/resources/qml/delegates/NoticeMessage.qml index a392eb5b..f7467eca 100644 --- a/resources/qml/delegates/NoticeMessage.qml +++ b/resources/qml/delegates/NoticeMessage.qml @@ -1,7 +1,8 @@ import ".." MatrixText { - text: model.formattedBody + property string notice: model.formattedBody.replace("
", "
")
+	text: notice
 	width: parent ? parent.width : undefined
 	font.italic: true
 	color: inactiveColors.text
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index e3d87ae6..9da8a194 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -59,6 +59,30 @@ eventMsgType(const mtx::events::RoomEvent &e) -> decltype(e.content.msgtype)
         return e.content.msgtype;
 }
 
+template
+QString
+eventRoomName(const T &)
+{
+        return "";
+}
+QString
+eventRoomName(const mtx::events::StateEvent &e)
+{
+        return QString::fromStdString(e.content.name);
+}
+
+template
+QString
+eventRoomTopic(const T &)
+{
+        return "";
+}
+QString
+eventRoomTopic(const mtx::events::StateEvent &e)
+{
+        return QString::fromStdString(e.content.topic);
+}
+
 template
 QString
 eventBody(const mtx::events::Event &)
@@ -437,6 +461,8 @@ TimelineModel::roleNames() const
           {State, "state"},
           {IsEncrypted, "isEncrypted"},
           {ReplyTo, "replyTo"},
+          {RoomName, "roomName"},
+          {RoomTopic, "roomTopic"},
         };
 }
 int
@@ -563,6 +589,12 @@ TimelineModel::data(const QModelIndex &index, int role) const
                   [](const auto &e) -> QString { return eventRelatesTo(e); }, event);
                 return QVariant(evId);
         }
+        case RoomName:
+                return QVariant(boost::apply_visitor(
+                  [](const auto &e) -> QString { return eventRoomName(e); }, event));
+        case RoomTopic:
+                return QVariant(boost::apply_visitor(
+                  [](const auto &e) -> QString { return eventRoomTopic(e); }, event));
         default:
                 return QVariant();
         }
diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h
index 06c64acf..05e05962 100644
--- a/src/timeline/TimelineModel.h
+++ b/src/timeline/TimelineModel.h
@@ -141,6 +141,8 @@ public:
                 State,
                 IsEncrypted,
                 ReplyTo,
+                RoomName,
+                RoomTopic,
         };
 
         QHash roleNames() const override;