aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/events/roomcanonicalaliasevent.h72
-rw-r--r--lib/room.cpp46
-rw-r--r--lib/room.h3
3 files changed, 44 insertions, 77 deletions
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;