Update libqmatrixclient && fix broken avatar && fix broken image provider.

This commit is contained in:
Black Hat 2018-09-09 18:35:37 +08:00
parent 2992804472
commit 7c426e254b
7 changed files with 32 additions and 16 deletions

@ -1 +1 @@
Subproject commit d9ff200ff62fb7f5b6b51082dc3979d5454a1bec
Subproject commit 3dfcd0f4f4501dba5925d894b7f0fbc9414549c8

View File

@ -103,12 +103,12 @@ Drawer {
anchors.margins: 8
spacing: 12
ImageStatus {
ImageItem {
Layout.preferredWidth: height
Layout.fillHeight: true
source: avatar != "" ? "image://mxc/" + avatar : ""
displayText: name
image: avatar
hint: name
}
Label {

View File

@ -112,12 +112,13 @@ ApplicationWindow {
width: parent.width
height: width
ImageStatus {
ImageItem {
anchors.fill: parent
anchors.margins: 12
// source: matriqueController.isLogin ? connection.localUser && connection.localUser.avatarUrl ? "image://mxc/" + connection.localUser.avatarUrl : "" : "qrc:/asset/img/avatar.png"
displayText: name
hint: name
image: avatar
defaultColor: Material.accent
}
page: roomPage
@ -289,6 +290,6 @@ ApplicationWindow {
Binding {
target: imageProvider
property: "connection"
value: matriqueController.connection
value: accountListView.currentConnection
}
}

View File

@ -1,5 +1,7 @@
#include "accountlistmodel.h"
#include "room.h"
AccountListModel::AccountListModel(QObject* parent)
: QAbstractListModel(parent) {}
@ -10,7 +12,18 @@ void AccountListModel::setController(Controller* value) {
m_controller = value;
for (auto c : m_controller->connections()) m_connections.append(c);
for (auto c : m_controller->connections()) {
connect(c->user(), &User::avatarChanged, [=] {
const auto it =
std::find(m_connections.begin(), m_connections.end(), c);
if (it == m_connections.end()) {
return;
}
const auto idx = index(it - m_connections.begin());
emit dataChanged(idx, idx, {AvatarRole});
});
m_connections.append(c);
};
connect(m_controller, &Controller::connectionAdded, this,
[=](Connection* conn) {
@ -59,7 +72,7 @@ QVariant AccountListModel::data(const QModelIndex& index, int role) const {
int AccountListModel::rowCount(const QModelIndex& parent) const {
if (parent.isValid()) return 0;
return m_controller->connections().count();
return m_connections.count();
}
QHash<int, QByteArray> AccountListModel::roleNames() const {

View File

@ -35,7 +35,7 @@ class ImageItem : public QQuickPaintedItem {
private:
QImage m_image;
QString m_hint;
QString m_hint = "H";
QString m_color = "#000000";
};

View File

@ -19,8 +19,6 @@ void RoomListModel::setConnection(Connection* connection) {
using QMatrixClient::Room;
m_connection = connection;
doResetModel();
connect(connection, &Connection::connected, this,
&RoomListModel::doResetModel);
connect(connection, &Connection::invitedRoom, this,
@ -30,6 +28,8 @@ void RoomListModel::setConnection(Connection* connection) {
connect(connection, &Connection::leftRoom, this, &RoomListModel::updateRoom);
connect(connection, &Connection::aboutToDeleteRoom, this,
&RoomListModel::deleteRoom);
doResetModel();
}
void RoomListModel::doResetModel() {
@ -139,7 +139,7 @@ QVariant RoomListModel::data(const QModelIndex& index, int role) const {
MatriqueRoom* room = m_rooms.at(index.row());
if (role == NameRole) return room->displayName();
if (role == AvatarRole) {
if (room->avatarUrl().toString() != "") return room->avatar(64, 64);
if (!room->avatarUrl().isEmpty()) return room->avatar(64, 64);
return QImage();
}
if (role == TopicRole) return room->topic();

View File

@ -68,7 +68,9 @@ QVariant UserListModel::data(const QModelIndex& index, int role) const {
return user->displayname(m_currentRoom);
}
if (role == AvatarRole) {
return user->avatarUrl(m_currentRoom);
if (!user->avatarUrl(m_currentRoom).isEmpty())
return user->avatar(32, m_currentRoom);
return QImage();
}
return QVariant();
@ -110,7 +112,7 @@ void UserListModel::refresh(QMatrixClient::User* user, QVector<int> roles) {
void UserListModel::avatarChanged(QMatrixClient::User* user,
const QMatrixClient::Room* context) {
if (context == m_currentRoom) refresh(user, {Qt::DecorationRole});
if (context == m_currentRoom) refresh(user, {AvatarRole});
}
int UserListModel::findUserPos(User* user) const {