aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-01-25 19:54:17 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-01-25 19:54:17 +0900
commit2f83e4be20a15013181c1ba6944e21f051ccac9d (patch)
treeb6d1014f736b8c75e05e1dea8157e7ed04cc7820
parentd45298d5db97663f300879002a8e0ccdf6b8d523 (diff)
parent80f7e44e1a9056fc55147718dd2812eb93925ec1 (diff)
downloadlibquotient-2f83e4be20a15013181c1ba6944e21f051ccac9d.tar.gz
libquotient-2f83e4be20a15013181c1ba6944e21f051ccac9d.zip
Merge branch 'kitsune-avatar-url-properties'
-rw-r--r--avatar.cpp5
-rw-r--r--avatar.h1
-rw-r--r--events/event.h28
-rw-r--r--room.cpp18
-rw-r--r--room.h10
-rw-r--r--user.cpp12
-rw-r--r--user.h8
7 files changed, 68 insertions, 14 deletions
diff --git a/avatar.cpp b/avatar.cpp
index 44cad4e5..040bf9bb 100644
--- a/avatar.cpp
+++ b/avatar.cpp
@@ -62,6 +62,11 @@ QImage Avatar::get(int width, int height, notifier_t notifier) const
return d->get({width, height}, notifier);
}
+QString Avatar::mediaId() const
+{
+ return d->_url.authority() + d->_url.path();
+}
+
QImage Avatar::Private::get(QSize size, Avatar::notifier_t notifier) const
{
// FIXME: Alternating between longer-width and longer-height requests
diff --git a/avatar.h b/avatar.h
index 28c16e4d..4d476ea5 100644
--- a/avatar.h
+++ b/avatar.h
@@ -38,6 +38,7 @@ namespace QMatrixClient
QImage get(int dimension, notifier_t notifier) const;
QImage get(int w, int h, notifier_t notifier) const;
+ QString mediaId() const;
QUrl url() const;
bool updateUrl(const QUrl& newUrl);
diff --git a/events/event.h b/events/event.h
index 6ed5ba49..b5a4d94e 100644
--- a/events/event.h
+++ b/events/event.h
@@ -256,6 +256,21 @@ namespace QMatrixClient
};
template <typename ContentT>
+ struct Prev
+ {
+ template <typename... ContentParamTs>
+ explicit Prev(const QJsonObject& unsignedJson,
+ ContentParamTs&&... contentParams)
+ : senderId(unsignedJson.value("prev_sender").toString())
+ , content(unsignedJson.value("prev_content").toObject(),
+ std::forward<ContentParamTs>(contentParams)...)
+ { }
+
+ QString senderId;
+ ContentT content;
+ };
+
+ template <typename ContentT>
class StateEvent: public StateEventBase
{
public:
@@ -270,9 +285,8 @@ namespace QMatrixClient
{
auto unsignedData = obj.value("unsigned").toObject();
if (unsignedData.contains("prev_content"))
- _prev.reset(new ContentT(
- unsignedData.value("prev_content").toObject(),
- std::forward<ContentParamTs>(contentParams)...));
+ _prev = std::make_unique<Prev<ContentT>>(unsignedData,
+ std::forward<ContentParamTs>(contentParams)...);
}
template <typename... ContentParamTs>
explicit StateEvent(Type type, ContentParamTs&&... contentParams)
@@ -283,11 +297,15 @@ namespace QMatrixClient
QJsonObject toJson() const { return _content.toJson(); }
ContentT content() const { return _content; }
- ContentT* prev_content() const { return _prev.data(); }
+ /** @deprecated Use prevContent instead */
+ ContentT* prev_content() const { return prevContent(); }
+ ContentT* prevContent() const
+ { return _prev ? &_prev->content : nullptr; }
+ QString prevSenderId() const { return _prev ? _prev->senderId : ""; }
protected:
ContentT _content;
- QScopedPointer<ContentT> _prev;
+ std::unique_ptr<Prev<ContentT>> _prev;
};
} // namespace QMatrixClient
Q_DECLARE_METATYPE(QMatrixClient::Event*)
diff --git a/room.cpp b/room.cpp
index 71b7b228..bc7c083e 100644
--- a/room.cpp
+++ b/room.cpp
@@ -213,6 +213,7 @@ RoomEventPtr TimelineItem::replaceEvent(RoomEventPtr&& other)
Room::Room(Connection* connection, QString id, JoinState initialJoinState)
: QObject(connection), d(new Private(connection, id, initialJoinState))
{
+ setObjectName(id);
// See "Accessing the Public Class" section in
// https://marcmutz.wordpress.com/translated-articles/pimp-my-pimpl-%E2%80%94-reloaded/
d->q = this;
@@ -262,6 +263,16 @@ QString Room::topic() const
return d->topic;
}
+QString Room::avatarMediaId() const
+{
+ return d->avatar.mediaId();
+}
+
+QUrl Room::avatarUrl() const
+{
+ return d->avatar.url();
+}
+
QImage Room::avatar(int dimension)
{
return avatar(dimension, dimension);
@@ -278,8 +289,8 @@ QImage Room::avatar(int width, int height)
auto theOtherOneIt = d->membersMap.begin();
if (theOtherOneIt.value() == localUser())
++theOtherOneIt;
- return theOtherOneIt.value()->avatarObject()
- .get(width, height, [=] { emit avatarChanged(); });
+ return (*theOtherOneIt)->avatarObject()
+ .get(width, height, [=] { emit avatarChanged(); });
}
return {};
}
@@ -752,7 +763,7 @@ void Room::Private::removeMember(User* u)
}
}
-QString Room::roomMembername(User *u) const
+QString Room::roomMembername(const User* u) const
{
// See the CS spec, section 11.2.2.3
@@ -1234,6 +1245,7 @@ void Room::processStateEvents(const RoomEvents& events)
case EventType::RoomCanonicalAlias: {
auto aliasEvent = static_cast<RoomCanonicalAliasEvent*>(event);
d->canonicalAlias = aliasEvent->alias();
+ setObjectName(d->canonicalAlias);
qCDebug(MAIN) << "Room canonical alias updated:" << d->canonicalAlias;
emitNamesChanged = true;
break;
diff --git a/room.h b/room.h
index 2284e8b1..b908a763 100644
--- a/room.h
+++ b/room.h
@@ -40,7 +40,6 @@ namespace QMatrixClient
class MemberSorter;
class LeaveRoomJob;
class RedactEventJob;
- class Room;
class TimelineItem
{
@@ -105,6 +104,9 @@ namespace QMatrixClient
Q_PROPERTY(QString canonicalAlias READ canonicalAlias NOTIFY namesChanged)
Q_PROPERTY(QString displayName READ displayName NOTIFY namesChanged)
Q_PROPERTY(QString topic READ topic NOTIFY topicChanged)
+ Q_PROPERTY(QString avatarMediaId READ avatarMediaId NOTIFY avatarChanged STORED false)
+ Q_PROPERTY(QUrl avatarUrl READ avatarUrl NOTIFY avatarChanged)
+
Q_PROPERTY(int timelineSize READ timelineSize NOTIFY addedMessages)
Q_PROPERTY(QStringList memberNames READ memberNames NOTIFY memberListChanged)
Q_PROPERTY(int memberCount READ memberCount NOTIFY memberListChanged)
@@ -122,6 +124,8 @@ namespace QMatrixClient
Room(Connection* connection, QString id, JoinState initialJoinState);
~Room() override;
+ // Property accessors
+
Connection* connection() const;
User* localUser() const;
const QString& id() const;
@@ -130,6 +134,8 @@ namespace QMatrixClient
QString canonicalAlias() const;
QString displayName() const;
QString topic() const;
+ QString avatarMediaId() const;
+ QUrl avatarUrl() const;
Q_INVOKABLE JoinState joinState() const;
Q_INVOKABLE QList<User*> usersTyping() const;
QList<User*> membersLeft() const;
@@ -158,7 +164,7 @@ namespace QMatrixClient
* @brief Produces a disambiguated name for a given user in
* the context of the room
*/
- Q_INVOKABLE QString roomMembername(User* u) const;
+ Q_INVOKABLE QString roomMembername(const User* u) const;
/**
* @brief Produces a disambiguated name for a user with this id in
* the context of the room
diff --git a/user.cpp b/user.cpp
index baa7bc45..b0890b61 100644
--- a/user.cpp
+++ b/user.cpp
@@ -51,7 +51,9 @@ class User::Private
User::User(QString userId, Connection* connection)
: QObject(connection), d(new Private(std::move(userId), connection))
-{ }
+{
+ setObjectName(userId);
+}
User::~User()
{
@@ -74,6 +76,7 @@ void User::updateName(const QString& newName)
if (oldName != newName)
{
d->name = newName;
+ setObjectName(displayname());
emit nameChanged(newName, oldName);
}
}
@@ -127,7 +130,7 @@ QString User::bridged() const {
return d->bridged;
}
-const Avatar& User::avatarObject()
+const Avatar& User::avatarObject() const
{
return d->avatar;
}
@@ -142,6 +145,11 @@ QImage User::avatar(int width, int height)
return d->avatar.get(width, height, [=] { emit avatarChanged(this); });
}
+QString User::avatarMediaId() const
+{
+ return d->avatar.mediaId();
+}
+
QUrl User::avatarUrl() const
{
return d->avatar.url();
diff --git a/user.h b/user.h
index 91dfdc09..8a2c53d9 100644
--- a/user.h
+++ b/user.h
@@ -33,6 +33,8 @@ namespace QMatrixClient
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(QString displayName READ displayname NOTIFY nameChanged STORED false)
Q_PROPERTY(QString bridgeName READ bridged NOTIFY nameChanged STORED false)
+ Q_PROPERTY(QString avatarMediaId READ avatarMediaId NOTIFY avatarChanged STORED false)
+ Q_PROPERTY(QUrl avatarUrl READ avatarUrl NOTIFY avatarChanged)
public:
User(QString userId, Connection* connection);
~User() override;
@@ -57,11 +59,12 @@ namespace QMatrixClient
*/
QString bridged() const;
- const Avatar& avatarObject();
+ const Avatar& avatarObject() const;
Q_INVOKABLE QImage avatar(int dimension);
Q_INVOKABLE QImage avatar(int requestedWidth, int requestedHeight);
- Q_INVOKABLE QUrl avatarUrl() const;
+ QString avatarMediaId() const;
+ QUrl avatarUrl() const;
void processEvent(Event* event);
@@ -83,3 +86,4 @@ namespace QMatrixClient
Private* d;
};
}
+Q_DECLARE_METATYPE(QMatrixClient::User*)