From 42bca67768d6f174ecf125563ab28ef79b994e23 Mon Sep 17 00:00:00 2001
From: Ram Nad <ramnad1999@gmail.com>
Date: Sun, 8 Mar 2020 02:43:23 +0530
Subject: fixing msc2432

---
 lib/events/roomcanonicalaliasevent.h | 86 ++++++++++++++++++++++++++++++++++++
 lib/events/simplestateevents.h       |  2 -
 2 files changed, 86 insertions(+), 2 deletions(-)
 create mode 100644 lib/events/roomcanonicalaliasevent.h

(limited to 'lib/events')

diff --git a/lib/events/roomcanonicalaliasevent.h b/lib/events/roomcanonicalaliasevent.h
new file mode 100644
index 00000000..3f89f639
--- /dev/null
+++ b/lib/events/roomcanonicalaliasevent.h
@@ -0,0 +1,86 @@
+// Contains code for RoomCanonicalAlias Event
+#pragma once
+
+#include "stateevent.h"
+
+namespace Quotient {
+namespace EventContent{
+    template <typename T1, typename T2>
+    class SimpleDualContent {
+    public:
+        using first_value_type = T1;
+        using second_value_type = T2;
+
+        template <typename TT1, typename TT2>
+        SimpleDualContent(QString Key1Name, TT1&& value1, QString Key2Name,
+                          TT2&& value2)
+            : value1(std::forward<TT1>(value1))
+            , value2(std::forward<TT2>(value2))
+            , key1(std::move(Key1Name))
+            , key2(std::move(Key2Name))
+        { }
+
+        SimpleDualContent(const QJsonObject& json, QString key1Name,
+                          QString key2Name)
+            : value1(fromJson<T1>(json[key1Name]))
+            , value2(fromJson<T2>(json[key2Name]))
+            , key1(std::move(key1Name))
+            , key2(std::move(key2Name))
+        { }
+
+        QJsonObject toJson() const
+        {
+            return { { key1, Quotient::toJson(value1) },
+                     { key2, Quotient::toJson(value2) } };
+        }
+
+    public:
+        T1 value1;
+        T2 value2;
+
+    protected:
+        QString key1;
+        QString key2;
+    };
+} // namespace EventContent
+
+class RoomCanonicalAliasEvent
+    : public StateEvent<EventContent::SimpleDualContent<QString, QStringList>> {
+public:
+    DEFINE_EVENT_TYPEID("m.room.canonical_alias", RoomCanonicalAliasEvent)
+
+    explicit RoomCanonicalAliasEvent(const QJsonObject& obj)
+        : StateEvent(typeId(), obj, QStringLiteral("alias"),
+                     QStringLiteral("alt_aliases"))
+    { }
+
+    RoomCanonicalAliasEvent(const QString& server, const QString& alias,
+                            const QStringList& alt_aliases)
+        : StateEvent(typeId(), matrixTypeId(), server, QStringLiteral("alias"),
+                     alias, QStringLiteral("alt_aliases"), alt_aliases)
+    { }
+
+    // For compatibility used at Room::setCanonicalAlias
+    explicit RoomCanonicalAliasEvent(const QString& value1)
+        : RoomCanonicalAliasEvent(value1, QStringList())
+    { }
+
+    // Because, MSC2432 specifies, that alt_aliases may be present
+    // without aliases as well
+    explicit RoomCanonicalAliasEvent(const QStringList& value2)
+        : RoomCanonicalAliasEvent(QString(), value2)
+    { }
+
+    template <typename T1, typename T2>
+    RoomCanonicalAliasEvent(T1&& value1, T2&& value2)
+        : StateEvent(typeId(), matrixTypeId(), QString(),
+                     QStringLiteral("alias"), std::forward<T1>(value1),
+                     QStringLiteral("alt_aliases"), std::forward<T2>(value2))
+    { }
+
+    QString alias() const { return content().value1; }
+
+    QStringList alt_aliases() const { return content().value2; }
+};
+REGISTER_EVENT_TYPE(RoomCanonicalAliasEvent)
+} // namespace Quotient
\ No newline at end of file
diff --git a/lib/events/simplestateevents.h b/lib/events/simplestateevents.h
index eb1d2f7a..cde5b0fd 100644
--- a/lib/events/simplestateevents.h
+++ b/lib/events/simplestateevents.h
@@ -69,8 +69,6 @@ namespace EventContent {
     // End of macro
 
 DEFINE_SIMPLE_STATE_EVENT(RoomNameEvent, "m.room.name", QString, name)
-DEFINE_SIMPLE_STATE_EVENT(RoomCanonicalAliasEvent, "m.room.canonical_alias",
-                          QString, alias)
 DEFINE_SIMPLE_STATE_EVENT(RoomTopicEvent, "m.room.topic", QString, topic)
 
 class RoomAliasesEvent
-- 
cgit v1.2.3


From a682edf6e93f9ad4a087d5ba1374e42b06ec27e9 Mon Sep 17 00:00:00 2001
From: Ram Nad <ramnad1999@gmail.com>
Date: Fri, 20 Mar 2020 01:11:34 +0530
Subject: Add warranty in lib/events/roomcanonicalaliasevent.h

Co-Authored-By: Kitsune Ral <Kitsune-Ral@users.sf.net>
---
 lib/events/roomcanonicalaliasevent.h | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

(limited to 'lib/events')

diff --git a/lib/events/roomcanonicalaliasevent.h b/lib/events/roomcanonicalaliasevent.h
index 3f89f639..78d541bc 100644
--- a/lib/events/roomcanonicalaliasevent.h
+++ b/lib/events/roomcanonicalaliasevent.h
@@ -1,4 +1,21 @@
-// Contains code for RoomCanonicalAlias Event
+/******************************************************************************
+ * Copyright (C) 2020 QMatrixClient project
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+ 
 #pragma once
 
 #include "stateevent.h"
@@ -83,4 +100,4 @@ public:
     QStringList alt_aliases() const { return content().value2; }
 };
 REGISTER_EVENT_TYPE(RoomCanonicalAliasEvent)
-} // namespace Quotient
\ No newline at end of file
+} // namespace Quotient
-- 
cgit v1.2.3


From 99c7e1c5e2a78c6babba50418789bd4c4f0e9db3 Mon Sep 17 00:00:00 2001
From: Ram Nad <ramnad1999@gmail.com>
Date: Fri, 20 Mar 2020 02:29:45 +0530
Subject: made suggested changes

---
 lib/events/roomcanonicalaliasevent.h | 72 +++++++++++-------------------------
 lib/room.cpp                         | 46 ++++++++++-------------
 lib/room.h                           |  3 ++
 3 files changed, 44 insertions(+), 77 deletions(-)

(limited to 'lib/events')

diff --git a/lib/events/roomcanonicalaliasevent.h b/lib/events/roomcanonicalaliasevent.h
index 78d541bc..012cac75 100644
--- a/lib/events/roomcanonicalaliasevent.h
+++ b/lib/events/roomcanonicalaliasevent.h
@@ -22,82 +22,54 @@
 
 namespace Quotient {
 namespace EventContent{
-    template <typename T1, typename T2>
-    class SimpleDualContent {
+    class AliasesEventContent {
+
     public:
-        using first_value_type = T1;
-        using second_value_type = T2;
 
-        template <typename TT1, typename TT2>
-        SimpleDualContent(QString Key1Name, TT1&& value1, QString Key2Name,
-                          TT2&& value2)
-            : value1(std::forward<TT1>(value1))
-            , value2(std::forward<TT2>(value2))
-            , key1(std::move(Key1Name))
-            , key2(std::move(Key2Name))
+        template<typename T1, typename T2>
+        AliasesEventContent(T1&& canonicalAlias, T2&& altAliases)
+            : canonicalAlias(std::forward<T1>(canonicalAlias))
+            , altAliases(std::forward<T2>(altAliases))
         { }
 
-        SimpleDualContent(const QJsonObject& json, QString key1Name,
-                          QString key2Name)
-            : value1(fromJson<T1>(json[key1Name]))
-            , value2(fromJson<T2>(json[key2Name]))
-            , key1(std::move(key1Name))
-            , key2(std::move(key2Name))
+        AliasesEventContent(const QJsonObject& json)
+            : canonicalAlias(fromJson<QString>(json["alias"]))
+            , altAliases(fromJson<QStringList>(json["alt_aliases"]))
         { }
 
         QJsonObject toJson() const
         {
-            return { { key1, Quotient::toJson(value1) },
-                     { key2, Quotient::toJson(value2) } };
+            return { { "alias", Quotient::toJson(canonicalAlias) },
+                     { "alt_aliases", Quotient::toJson(altAliases) } };
         }
 
-    public:
-        T1 value1;
-        T2 value2;
-
-    protected:
-        QString key1;
-        QString key2;
+        QString canonicalAlias;
+        QStringList altAliases;
     };
 } // namespace EventContent
 
 class RoomCanonicalAliasEvent
-    : public StateEvent<EventContent::SimpleDualContent<QString, QStringList>> {
+    : public StateEvent<EventContent::AliasesEventContent> {
 public:
     DEFINE_EVENT_TYPEID("m.room.canonical_alias", RoomCanonicalAliasEvent)
 
     explicit RoomCanonicalAliasEvent(const QJsonObject& obj)
-        : StateEvent(typeId(), obj, QStringLiteral("alias"),
-                     QStringLiteral("alt_aliases"))
-    { }
-
-    RoomCanonicalAliasEvent(const QString& server, const QString& alias,
-                            const QStringList& alt_aliases)
-        : StateEvent(typeId(), matrixTypeId(), server, QStringLiteral("alias"),
-                     alias, QStringLiteral("alt_aliases"), alt_aliases)
-    { }
-
-    // For compatibility used at Room::setCanonicalAlias
-    explicit RoomCanonicalAliasEvent(const QString& value1)
-        : RoomCanonicalAliasEvent(value1, QStringList())
+        : StateEvent(typeId(), obj)
     { }
 
-    // Because, MSC2432 specifies, that alt_aliases may be present
-    // without aliases as well
-    explicit RoomCanonicalAliasEvent(const QStringList& value2)
-        : RoomCanonicalAliasEvent(QString(), value2)
+    RoomCanonicalAliasEvent(const QString& canonicalAlias, const QStringList& altAliases = {})
+        : StateEvent(typeId(), matrixTypeId(), QString(),
+                canonicalAlias, altAliases)
     { }
 
-    template <typename T1, typename T2>
-    RoomCanonicalAliasEvent(T1&& value1, T2&& value2)
+    RoomCanonicalAliasEvent(QString&& canonicalAlias, QStringList&& altAliases = {})
         : StateEvent(typeId(), matrixTypeId(), QString(),
-                     QStringLiteral("alias"), std::forward<T1>(value1),
-                     QStringLiteral("alt_aliases"), std::forward<T2>(value2))
+                std::move(canonicalAlias), std::move(altAliases))
     { }
 
-    QString alias() const { return content().value1; }
+    QString alias() const { return content().canonicalAlias; }
 
-    QStringList alt_aliases() const { return content().value2; }
+    QStringList altAliases() const { return content().altAliases; }
 };
 REGISTER_EVENT_TYPE(RoomCanonicalAliasEvent)
 } // namespace Quotient
diff --git a/lib/room.cpp b/lib/room.cpp
index 475c6570..fa3f10a6 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -108,7 +108,7 @@ public:
     QHash<StateEventKey, const StateEventBase*> currentState;
     /// Servers with aliases for this room except the one of the local user
     /// \sa Room::remoteAliases
-    // This may not be required anymore
+
     QSet<QString> aliasServers;
 
     Timeline timeline;
@@ -432,15 +432,20 @@ QString Room::name() const
     return d->getCurrentState<RoomNameEvent>()->name();
 }
 
-QStringList Room::localAliases() const
+QStringList Room::aliases() const
 {
-    QStringList result(d
-        ->getCurrentState<RoomCanonicalAliasEvent>()->alias());
-    result += d->getCurrentState<RoomCanonicalAliasEvent>()->alt_aliases();
+    QStringList result(d->getCurrentState<RoomCanonicalAliasEvent>()->alias());
+    result += d->getCurrentState<RoomCanonicalAliasEvent>()->altAliases();
     return result;
 }
 
-// Not sure about this function, maybe it is no more required
+QStringList Room::localAliases() const
+{
+    return d->getCurrentState<RoomAliasesEvent>(
+        connection()->domain())
+        ->aliases();
+}
+
 QStringList Room::remoteAliases() const
 {
     QStringList result;
@@ -1693,6 +1698,8 @@ void Room::setName(const QString& newName)
     d->requestSetState<RoomNameEvent>(newName);
 }
 
+// Change might be required here as well. 
+// Not sure what will be best
 void Room::setCanonicalAlias(const QString& newAlias)
 {
     d->requestSetState<RoomCanonicalAliasEvent>(newAlias);
@@ -1700,7 +1707,7 @@ void Room::setCanonicalAlias(const QString& newAlias)
 
 void Room::setLocalAliases(const QStringList& aliases)
 {
-    d->requestSetState<RoomCanonicalAliasEvent>(aliases);
+    d->requestSetState<RoomCanonicalAliasEvent>(this->canonicalAlias(), aliases);
 }
 
 void Room::setTopic(const QString& newTopic)
@@ -2355,23 +2362,8 @@ Room::Changes Room::processStateEvent(const RoomEvent& e)
         }
         , [this,oldStateEvent] (const RoomAliasesEvent& ae) {
             // clang-format on
-            if (ae.aliases().isEmpty()) {
-                if (d->aliasServers.remove(ae.stateKey()))
-                    qCDebug(STATE).noquote()
-                        << ae.stateKey() << "no more has aliases for room"
-                        << objectName();
-            } else {
-                d->aliasServers.insert(ae.stateKey());
-                qCDebug(STATE).nospace().noquote()
-                    << "New server with aliases for room " << objectName()
-                    << ": " << ae.stateKey();
-            }
-            const auto previousAliases =
-                oldStateEvent
-                    ? static_cast<const RoomAliasesEvent*>(oldStateEvent)->aliases()
-                    : QStringList();
-            connection()->updateRoomAliases(id(), previousAliases, ae.aliases());
-            return OtherChange;
+            // This event has been removed by MSC-2432
+            return NoChange;
             // clang-format off
         }
         , [this, oldStateEvent] (const RoomCanonicalAliasEvent& cae) {
@@ -2386,7 +2378,7 @@ Room::Changes Room::processStateEvent(const RoomEvent& e)
             auto previousAltAliases =
                 oldStateEvent
                     ? static_cast<const RoomCanonicalAliasEvent*>(oldStateEvent)
-                          ->alt_aliases()
+                          ->altAliases()
                     : QStringList();
 
             if (!previousCanonicalAlias.isEmpty()) {
@@ -2395,7 +2387,7 @@ Room::Changes Room::processStateEvent(const RoomEvent& e)
 
             const auto previousAliases = std::move(previousAltAliases);
 
-            auto newAliases = cae.alt_aliases();
+            auto newAliases = cae.altAliases();
 
             if (!cae.alias().isEmpty()) {
                 newAliases.push_front(cae.alias());
@@ -2651,7 +2643,7 @@ QString Room::Private::calculateDisplayname() const
         return dispName;
 
     // 3. m.room.aliases - only local aliases, subject for further removal
-    const auto aliases = q->localAliases();
+    const auto aliases = q->aliases();
     if (!aliases.isEmpty())
         return aliases.front();
 
diff --git a/lib/room.h b/lib/room.h
index ad19792e..4d2527f7 100644
--- a/lib/room.h
+++ b/lib/room.h
@@ -188,11 +188,14 @@ public:
     QString name() const;
     /// Room aliases defined on the current user's server
     /// \sa remoteAliases, setLocalAliases
+    [[deprecated("Use aliases()")]]
     QStringList localAliases() const;
     /// Room aliases defined on other servers
     /// \sa localAliases
+    [[deprecated("Use aliases()")]]
     QStringList remoteAliases() const;
     QString canonicalAlias() const;
+    QStringList aliases() const;
     QString displayName() const;
     QString topic() const;
     QString avatarMediaId() const;
-- 
cgit v1.2.3


From ecdab8ba9d2f411e5cfb049866501f159725a3db Mon Sep 17 00:00:00 2001
From: Ram Nad <ramnad1999@gmail.com>
Date: Fri, 20 Mar 2020 15:01:08 +0530
Subject: Make constructor explicit lib/events/roomcanonicalaliasevent.h

Co-Authored-By: Kitsune Ral <Kitsune-Ral@users.sf.net>
---
 lib/events/roomcanonicalaliasevent.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'lib/events')

diff --git a/lib/events/roomcanonicalaliasevent.h b/lib/events/roomcanonicalaliasevent.h
index 012cac75..0c30db8b 100644
--- a/lib/events/roomcanonicalaliasevent.h
+++ b/lib/events/roomcanonicalaliasevent.h
@@ -57,7 +57,7 @@ public:
         : StateEvent(typeId(), obj)
     { }
 
-    RoomCanonicalAliasEvent(const QString& canonicalAlias, const QStringList& altAliases = {})
+    explicit RoomCanonicalAliasEvent(const QString& canonicalAlias, const QStringList& altAliases = {})
         : StateEvent(typeId(), matrixTypeId(), QString(),
                 canonicalAlias, altAliases)
     { }
-- 
cgit v1.2.3


From 153c1c66c7cc162920e5d4e4d902efcadf015d5b Mon Sep 17 00:00:00 2001
From: Ram Nad <ramnad1999@gmail.com>
Date: Fri, 20 Mar 2020 15:01:55 +0530
Subject: Make rvalue constructor explicit Update
 lib/events/roomcanonicalaliasevent.h

Co-Authored-By: Kitsune Ral <Kitsune-Ral@users.sf.net>
---
 lib/events/roomcanonicalaliasevent.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'lib/events')

diff --git a/lib/events/roomcanonicalaliasevent.h b/lib/events/roomcanonicalaliasevent.h
index 0c30db8b..311a5959 100644
--- a/lib/events/roomcanonicalaliasevent.h
+++ b/lib/events/roomcanonicalaliasevent.h
@@ -62,7 +62,7 @@ public:
                 canonicalAlias, altAliases)
     { }
 
-    RoomCanonicalAliasEvent(QString&& canonicalAlias, QStringList&& altAliases = {})
+    explicit RoomCanonicalAliasEvent(QString&& canonicalAlias, QStringList&& altAliases = {})
         : StateEvent(typeId(), matrixTypeId(), QString(),
                 std::move(canonicalAlias), std::move(altAliases))
     { }
-- 
cgit v1.2.3