mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-24 20:18:53 +03:00
Use properties
This commit is contained in:
parent
6a6384babe
commit
4eaba191de
6 changed files with 58 additions and 34 deletions
|
@ -10,7 +10,6 @@ import im.nheko 1.0
|
||||||
|
|
||||||
Window {
|
Window {
|
||||||
id: ignoredUsers
|
id: ignoredUsers
|
||||||
required property list<string> users
|
|
||||||
required property var profile
|
required property var profile
|
||||||
|
|
||||||
title: qsTr("Ignored users")
|
title: qsTr("Ignored users")
|
||||||
|
@ -22,13 +21,9 @@ Window {
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: profile
|
target: profile
|
||||||
function onUnignoredUser(id, err) {
|
function onUnignoredUserError(id, err) {
|
||||||
if (err) {
|
|
||||||
const text = qsTr("Failed to unignore \"%1\": %2").arg(id).arg(err)
|
const text = qsTr("Failed to unignore \"%1\": %2").arg(id).arg(err)
|
||||||
MainWindow.showNotification(text)
|
MainWindow.showNotification(text)
|
||||||
} else {
|
|
||||||
users = Array.from(users).filter(user => user !== id)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +32,7 @@ Window {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
spacing: Nheko.paddingMedium
|
spacing: Nheko.paddingMedium
|
||||||
|
|
||||||
model: users
|
model: TimelineManager.ignoredUsers
|
||||||
header: ColumnLayout {
|
header: ColumnLayout {
|
||||||
Text {
|
Text {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
|
|
@ -322,7 +322,7 @@ ApplicationWindow {
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var component = Qt.createComponent("IgnoredUsers.qml")
|
var component = Qt.createComponent("IgnoredUsers.qml")
|
||||||
if (component.status == Component.Ready) {
|
if (component.status == Component.Ready) {
|
||||||
var window = component.createObject(userProfileDialog, {users: profile.getIgnoredUsers(), profile: profile})
|
var window = component.createObject(userProfileDialog, { profile: profile})
|
||||||
window.show()
|
window.show()
|
||||||
timelineRoot.destroyOnClose(window)
|
timelineRoot.destroyOnClose(window)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include "Cache.h"
|
#include "Cache.h"
|
||||||
|
#include "Cache_p.h"
|
||||||
#include "ChatPage.h"
|
#include "ChatPage.h"
|
||||||
#include "CombinedImagePackModel.h"
|
#include "CombinedImagePackModel.h"
|
||||||
#include "CommandCompleter.h"
|
#include "CommandCompleter.h"
|
||||||
|
@ -210,6 +211,7 @@ TimelineViewManager::sync(const mtx::responses::Sync &sync_)
|
||||||
this->rooms_->sync(sync_);
|
this->rooms_->sync(sync_);
|
||||||
this->communities_->sync(sync_);
|
this->communities_->sync(sync_);
|
||||||
this->presenceEmitter->sync(sync_.presence);
|
this->presenceEmitter->sync(sync_.presence);
|
||||||
|
this->processIgnoredUsers(sync_.account_data);
|
||||||
|
|
||||||
if (isInitialSync_) {
|
if (isInitialSync_) {
|
||||||
this->isInitialSync_ = false;
|
this->isInitialSync_ = false;
|
||||||
|
@ -560,3 +562,39 @@ TimelineViewManager::fixImageRendering(QQuickTextDocument *t, QQuickItem *i)
|
||||||
QObject::connect(t->textDocument(), SIGNAL(imagesLoaded()), i, SLOT(updateWholeDocument()));
|
QObject::connect(t->textDocument(), SIGNAL(imagesLoaded()), i, SLOT(updateWholeDocument()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using IgnoredUsers = mtx::events::EphemeralEvent<mtx::events::account_data::IgnoredUsers>;
|
||||||
|
|
||||||
|
static QVector<QString> convertIgnoredToQt(const IgnoredUsers &ev) {
|
||||||
|
QVector<QString> users;
|
||||||
|
for (const mtx::events::account_data::IgnoredUser &user : ev.content.users) {
|
||||||
|
users.push_back(QString::fromStdString(user.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<QString>
|
||||||
|
TimelineViewManager::getIgnoredUsers()
|
||||||
|
{
|
||||||
|
const auto cache = cache::client()->getAccountData(mtx::events::EventType::IgnoredUsers);
|
||||||
|
if (!cache) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return convertIgnoredToQt(std::get<IgnoredUsers>(*cache));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TimelineViewManager::processIgnoredUsers(const mtx::responses::AccountData &data)
|
||||||
|
{
|
||||||
|
for (const mtx::events::collections::RoomAccountDataEvents::variant &ev : data.events) {
|
||||||
|
if (!std::holds_alternative<IgnoredUsers>(ev)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const auto &ignoredEv = std::get<IgnoredUsers>(ev);
|
||||||
|
|
||||||
|
emit this->ignoredUsersChanged(convertIgnoredToQt(ignoredEv));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
|
@ -39,6 +39,7 @@ class TimelineViewManager final : public QObject
|
||||||
Q_PROPERTY(
|
Q_PROPERTY(
|
||||||
bool isInitialSync MEMBER isInitialSync_ READ isInitialSync NOTIFY initialSyncChanged)
|
bool isInitialSync MEMBER isInitialSync_ READ isInitialSync NOTIFY initialSyncChanged)
|
||||||
Q_PROPERTY(bool isConnected READ isConnected NOTIFY isConnectedChanged)
|
Q_PROPERTY(bool isConnected READ isConnected NOTIFY isConnectedChanged)
|
||||||
|
Q_PROPERTY(QVector<QString> ignoredUsers READ getIgnoredUsers NOTIFY ignoredUsersChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TimelineViewManager(CallManager *callManager, ChatPage *parent = nullptr);
|
TimelineViewManager(CallManager *callManager, ChatPage *parent = nullptr);
|
||||||
|
@ -62,6 +63,13 @@ public:
|
||||||
return instance_;
|
return instance_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static TimelineViewManager *instance()
|
||||||
|
{
|
||||||
|
return TimelineViewManager::instance_;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<QString> getIgnoredUsers();
|
||||||
|
|
||||||
void sync(const mtx::responses::Sync &sync_);
|
void sync(const mtx::responses::Sync &sync_);
|
||||||
|
|
||||||
VerificationManager *verificationManager() { return verificationManager_; }
|
VerificationManager *verificationManager() { return verificationManager_; }
|
||||||
|
@ -113,6 +121,7 @@ signals:
|
||||||
QString url,
|
QString url,
|
||||||
double originalWidth,
|
double originalWidth,
|
||||||
double proportionalHeight);
|
double proportionalHeight);
|
||||||
|
void ignoredUsersChanged(const QVector<QString> &ignoredUsers);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateReadReceipts(const QString &room_id, const std::vector<QString> &event_ids);
|
void updateReadReceipts(const QString &room_id, const std::vector<QString> &event_ids);
|
||||||
|
@ -154,4 +163,6 @@ private:
|
||||||
QHash<QPair<QString, quint64>, QColor> userColors;
|
QHash<QPair<QString, quint64>, QColor> userColors;
|
||||||
|
|
||||||
inline static TimelineViewManager *instance_ = nullptr;
|
inline static TimelineViewManager *instance_ = nullptr;
|
||||||
|
|
||||||
|
void processIgnoredUsers(const mtx::responses::AccountData &data);
|
||||||
};
|
};
|
||||||
|
|
|
@ -224,28 +224,10 @@ UserProfile::refreshDevices()
|
||||||
fetchDeviceList(this->userid_);
|
fetchDeviceList(this->userid_);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<QString>
|
|
||||||
UserProfile::getIgnoredUsers()
|
|
||||||
{
|
|
||||||
QVector<QString> vec;
|
|
||||||
const std::optional<mtx::events::collections::RoomAccountDataEvents::variant> optEv =
|
|
||||||
cache::client()->getAccountData(mtx::events::EventType::IgnoredUsers);
|
|
||||||
if (optEv) {
|
|
||||||
const auto &ev =
|
|
||||||
std::get<mtx::events::EphemeralEvent<mtx::events::account_data::IgnoredUsers>>(*optEv)
|
|
||||||
.content;
|
|
||||||
for (const mtx::events::account_data::IgnoredUser &user : ev.users) {
|
|
||||||
vec.append(QString::fromStdString(user.id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
UserProfile::ignoredStatus(const QString &id, const bool ignore)
|
UserProfile::ignoredStatus(const QString &id, const bool ignore)
|
||||||
{
|
{
|
||||||
auto old = this->getIgnoredUsers();
|
auto old = TimelineViewManager::instance()->getIgnoredUsers();
|
||||||
if (ignore) {
|
if (ignore) {
|
||||||
if (old.contains(id)) {
|
if (old.contains(id)) {
|
||||||
emit this->room()->ignoredUser(id, tr("Already ignored"));
|
emit this->room()->ignoredUser(id, tr("Already ignored"));
|
||||||
|
@ -268,9 +250,8 @@ UserProfile::ignoredStatus(const QString &id, const bool ignore)
|
||||||
if (ignore) {
|
if (ignore) {
|
||||||
emit this->room()->ignoredUser(
|
emit this->room()->ignoredUser(
|
||||||
id, e ? std::optional(QString::fromStdString(e->matrix_error.error)) : std::nullopt);
|
id, e ? std::optional(QString::fromStdString(e->matrix_error.error)) : std::nullopt);
|
||||||
} else {
|
} else if (e) {
|
||||||
emit this->unignoredUser(
|
emit this->unignoredUserError(id, QString::fromStdString(e->matrix_error.error));
|
||||||
id, e ? QVariant(QString::fromStdString(e->matrix_error.error)) : QVariant());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,7 +182,6 @@ public:
|
||||||
Q_INVOKABLE void unverify(const QString &device = QLatin1String(""));
|
Q_INVOKABLE void unverify(const QString &device = QLatin1String(""));
|
||||||
Q_INVOKABLE void fetchDeviceList(const QString &userID);
|
Q_INVOKABLE void fetchDeviceList(const QString &userID);
|
||||||
Q_INVOKABLE void refreshDevices();
|
Q_INVOKABLE void refreshDevices();
|
||||||
Q_INVOKABLE QVector<QString> getIgnoredUsers();
|
|
||||||
Q_INVOKABLE void banUser();
|
Q_INVOKABLE void banUser();
|
||||||
Q_INVOKABLE void signOutDevice(const QString &deviceID);
|
Q_INVOKABLE void signOutDevice(const QString &deviceID);
|
||||||
Q_INVOKABLE void ignoredStatus(const QString &id, const bool ignore);
|
Q_INVOKABLE void ignoredStatus(const QString &id, const bool ignore);
|
||||||
|
@ -202,7 +201,7 @@ signals:
|
||||||
void displayError(const QString &errorMessage);
|
void displayError(const QString &errorMessage);
|
||||||
void globalUsernameRetrieved(const QString &globalUser);
|
void globalUsernameRetrieved(const QString &globalUser);
|
||||||
void devicesChanged();
|
void devicesChanged();
|
||||||
void unignoredUser(const QString &id, const QVariant &err);
|
void unignoredUserError(const QString &id, const QVariant &err);
|
||||||
|
|
||||||
// internal
|
// internal
|
||||||
void verificationStatiChanged();
|
void verificationStatiChanged();
|
||||||
|
|
Loading…
Reference in a new issue