mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Don't send avatars over dbus by default
This should reduce payload size a lot
This commit is contained in:
parent
7e0ea12ebb
commit
30fde1f8ac
4 changed files with 61 additions and 65 deletions
|
@ -35,14 +35,14 @@ apiVersionIsCompatible(const QVersionNumber &clientAppVersion)
|
|||
RoomInfoItem::RoomInfoItem(const QString &roomId,
|
||||
const QString &alias,
|
||||
const QString &title,
|
||||
const QImage &image,
|
||||
const QString &avatarUrl,
|
||||
const int unreadNotifications,
|
||||
QObject *parent)
|
||||
: QObject{parent}
|
||||
, roomId_{roomId}
|
||||
, alias_{alias}
|
||||
, roomName_{title}
|
||||
, image_{image}
|
||||
, avatarUrl_{avatarUrl}
|
||||
, unreadNotifications_{unreadNotifications}
|
||||
{
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ RoomInfoItem::RoomInfoItem(const RoomInfoItem &other)
|
|||
, roomId_{other.roomId_}
|
||||
, alias_{other.alias_}
|
||||
, roomName_{other.roomName_}
|
||||
, image_{other.image_}
|
||||
, avatarUrl_{other.avatarUrl_}
|
||||
, unreadNotifications_{other.unreadNotifications_}
|
||||
{
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ RoomInfoItem::operator=(const RoomInfoItem &other)
|
|||
roomId_ = other.roomId_;
|
||||
alias_ = other.alias_;
|
||||
roomName_ = other.roomName_;
|
||||
image_ = other.image_;
|
||||
avatarUrl_ = other.avatarUrl_;
|
||||
unreadNotifications_ = other.unreadNotifications_;
|
||||
return *this;
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ QDBusArgument &
|
|||
operator<<(QDBusArgument &arg, const RoomInfoItem &item)
|
||||
{
|
||||
arg.beginStructure();
|
||||
arg << item.roomId_ << item.alias_ << item.roomName_ << item.image_
|
||||
arg << item.roomId_ << item.alias_ << item.roomName_ << item.avatarUrl_
|
||||
<< item.unreadNotifications_;
|
||||
arg.endStructure();
|
||||
return arg;
|
||||
|
@ -82,10 +82,8 @@ const QDBusArgument &
|
|||
operator>>(const QDBusArgument &arg, RoomInfoItem &item)
|
||||
{
|
||||
arg.beginStructure();
|
||||
arg >> item.roomId_ >> item.alias_ >> item.roomName_ >> item.image_ >>
|
||||
arg >> item.roomId_ >> item.alias_ >> item.roomName_ >> item.avatarUrl_ >>
|
||||
item.unreadNotifications_;
|
||||
if (item.image_.isNull())
|
||||
item.image_ = QImage{QStringLiteral(":/icons/ui/speech-bubbles.svg")};
|
||||
|
||||
arg.endStructure();
|
||||
return arg;
|
||||
|
@ -121,6 +119,16 @@ rooms()
|
|||
return {};
|
||||
}
|
||||
|
||||
QImage
|
||||
image(const QString &mxcuri)
|
||||
{
|
||||
if (QDBusInterface interface{QStringLiteral(NHEKO_DBUS_SERVICE_NAME), QStringLiteral("/")};
|
||||
interface.isValid())
|
||||
return QDBusReply<QImage>{interface.call(QStringLiteral("image"), mxcuri)}.value();
|
||||
else
|
||||
return {};
|
||||
}
|
||||
|
||||
void
|
||||
activateRoom(const QString &alias)
|
||||
{
|
||||
|
|
|
@ -18,7 +18,7 @@ init();
|
|||
|
||||
//! The nheko D-Bus API version provided by this file. The API version number follows semantic
|
||||
//! versioning as defined by https://semver.org.
|
||||
const QVersionNumber dbusApiVersion{0, 0, 1};
|
||||
const QVersionNumber dbusApiVersion{1, 0, 0};
|
||||
|
||||
//! Compare the installed Nheko API to the version that your client app targets to see if they
|
||||
//! are compatible.
|
||||
|
@ -33,7 +33,7 @@ public:
|
|||
RoomInfoItem(const QString &roomId = QString{},
|
||||
const QString &alias = QString{},
|
||||
const QString &title = QString{},
|
||||
const QImage &image = QImage{},
|
||||
const QString &avatarUrl = QString{},
|
||||
const int unreadNotifications = 0,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
|
@ -42,7 +42,7 @@ public:
|
|||
const QString &roomId() const { return roomId_; }
|
||||
const QString &alias() const { return alias_; }
|
||||
const QString &roomName() const { return roomName_; }
|
||||
const QImage &image() const { return image_; }
|
||||
const QString &avatarUrl() const { return avatarUrl_; }
|
||||
int unreadNotifications() const { return unreadNotifications_; }
|
||||
|
||||
RoomInfoItem &operator=(const RoomInfoItem &other);
|
||||
|
@ -54,7 +54,7 @@ private:
|
|||
QString roomId_;
|
||||
QString alias_;
|
||||
QString roomName_;
|
||||
QImage image_;
|
||||
QString avatarUrl_;
|
||||
int unreadNotifications_;
|
||||
};
|
||||
|
||||
|
@ -67,6 +67,9 @@ nhekoVersion();
|
|||
//! Call this function to get a list of all joined rooms.
|
||||
QVector<RoomInfoItem>
|
||||
rooms();
|
||||
//! Fetch an image using a matrix URI
|
||||
QImage
|
||||
image(const QString &uri);
|
||||
//! Activates a currently joined room.
|
||||
void
|
||||
activateRoom(const QString &alias);
|
||||
|
|
|
@ -32,67 +32,50 @@ struct RoomReplyState
|
|||
}
|
||||
|
||||
QVector<nheko::dbus::RoomInfoItem>
|
||||
NhekoDBusBackend::rooms(const QDBusMessage &message)
|
||||
NhekoDBusBackend::rooms() const
|
||||
{
|
||||
message.setDelayedReply(true);
|
||||
nhlog::ui()->debug("Rooms requested over D-Bus.");
|
||||
|
||||
const auto roomListModel = m_parent->models;
|
||||
|
||||
auto state = QSharedPointer<RoomReplyState>::create();
|
||||
|
||||
std::vector<std::string> roomids;
|
||||
roomids.reserve(roomids.size());
|
||||
for (const auto &room : roomListModel) {
|
||||
roomids.push_back(room->roomId().toStdString());
|
||||
}
|
||||
state->roominfos = cache::getRoomInfo(roomids);
|
||||
QVector<nheko::dbus::RoomInfoItem> model;
|
||||
|
||||
for (const auto &room : roomListModel) {
|
||||
auto addRoom = [room, roomListModelSize = roomListModel.size(), message, state](
|
||||
const QImage &image) {
|
||||
const auto aliases = cache::client()->getStateEvent<mtx::events::state::CanonicalAlias>(
|
||||
room->roomId().toStdString());
|
||||
QString alias;
|
||||
if (aliases.has_value()) {
|
||||
const auto &val = aliases.value().content;
|
||||
if (!val.alias.empty())
|
||||
alias = QString::fromStdString(val.alias);
|
||||
else if (val.alt_aliases.size() > 0)
|
||||
alias = QString::fromStdString(val.alt_aliases.front());
|
||||
}
|
||||
const auto aliases = cache::client()->getStateEvent<mtx::events::state::CanonicalAlias>(
|
||||
room->roomId().toStdString());
|
||||
QString alias;
|
||||
if (aliases.has_value()) {
|
||||
const auto &val = aliases.value().content;
|
||||
if (!val.alias.empty())
|
||||
alias = QString::fromStdString(val.alias);
|
||||
else if (val.alt_aliases.size() > 0)
|
||||
alias = QString::fromStdString(val.alt_aliases.front());
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> childLock(state->m);
|
||||
state->model.push_back(nheko::dbus::RoomInfoItem{
|
||||
room->roomId(),
|
||||
alias,
|
||||
QString::fromStdString(state->roominfos[room->roomId()].name),
|
||||
image,
|
||||
room->notificationCount()});
|
||||
|
||||
if (state->model.size() == roomListModelSize) {
|
||||
nhlog::ui()->debug("Sending {} rooms over D-Bus...", state->model.size());
|
||||
auto reply = message.createReply();
|
||||
reply << QVariant::fromValue(state->model);
|
||||
QDBusConnection::sessionBus().send(reply);
|
||||
nhlog::ui()->debug("Rooms successfully sent to D-Bus.");
|
||||
} else {
|
||||
// nhlog::ui()->debug("DBUS: {}/{}", state->model.size(), roomListModelSize);
|
||||
}
|
||||
};
|
||||
|
||||
if (state->roominfos[room->roomId()].avatar_url.empty())
|
||||
addRoom(QImage());
|
||||
else
|
||||
MainWindow::instance()->imageProvider()->download(
|
||||
QString::fromStdString(state->roominfos[room->roomId()].avatar_url).remove("mxc://"),
|
||||
{96, 96},
|
||||
[addRoom](const QString &, const QSize &, const QImage &image, const QString &) {
|
||||
addRoom(image);
|
||||
},
|
||||
true);
|
||||
model.push_back(nheko::dbus::RoomInfoItem{room->roomId(),
|
||||
alias,
|
||||
room->plainRoomName(),
|
||||
room->roomAvatarUrl(),
|
||||
room->notificationCount()});
|
||||
}
|
||||
|
||||
nhlog::ui()->debug("Sending {} rooms over D-Bus...", model.size());
|
||||
return model;
|
||||
}
|
||||
|
||||
QImage
|
||||
NhekoDBusBackend::image(const QString &uri, const QDBusMessage &message) const
|
||||
{
|
||||
message.setDelayedReply(true);
|
||||
nhlog::ui()->debug("Rooms requested over D-Bus.");
|
||||
MainWindow::instance()->imageProvider()->download(
|
||||
QString(uri).remove("mxc://"),
|
||||
{96, 96},
|
||||
[message](const QString &, const QSize &, const QImage &image, const QString &) {
|
||||
auto reply = message.createReply();
|
||||
reply << QVariant::fromValue(image);
|
||||
QDBusConnection::sessionBus().send(reply);
|
||||
},
|
||||
true);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,9 @@ public slots:
|
|||
//! Get the nheko version.
|
||||
Q_SCRIPTABLE QString nhekoVersion() const { return nheko::version; }
|
||||
//! Call this function to get a list of all joined rooms.
|
||||
Q_SCRIPTABLE QVector<nheko::dbus::RoomInfoItem> rooms(const QDBusMessage &message);
|
||||
Q_SCRIPTABLE QVector<nheko::dbus::RoomInfoItem> rooms() const;
|
||||
//! Call this function to convert a URI into an image
|
||||
Q_SCRIPTABLE QImage image(const QString &uri, const QDBusMessage &message) const;
|
||||
//! Activates a currently joined room.
|
||||
Q_SCRIPTABLE void activateRoom(const QString &alias) const;
|
||||
//! Joins a room. It is your responsibility to ask for confirmation (if desired).
|
||||
|
|
Loading…
Reference in a new issue