This commit is contained in:
NepNep21 2023-07-27 22:04:34 -03:00
parent 2401c211ab
commit d1ba9fd878
No known key found for this signature in database
GPG key ID: 818E86B41BD5C364
7 changed files with 169 additions and 5 deletions

View file

@ -772,6 +772,7 @@ set(QML_SOURCES
resources/qml/dialogs/AllowedRoomsSettingsDialog.qml
resources/qml/dialogs/RoomSettings.qml
resources/qml/dialogs/UserProfile.qml
resources/qml/dialogs/IgnoredUsers.qml
resources/qml/emoji/StickerPicker.qml
resources/qml/pages/LoginPage.qml
resources/qml/pages/RegisterPage.qml

View file

@ -0,0 +1,65 @@
// SPDX-FileCopyrightText: Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQml 2.15
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 2.15
import QtQuick.Window 2.15
import im.nheko 1.0
Window {
id: ignoredUsers
required property list<string> users
required property var profile
title: qsTr("Ignored users")
flags: Qt.WindowCloseButtonHint | Qt.WindowTitleHint
height: 650
width: 420
minimumHeight: 420
color: palette.window
Connections {
target: profile
function onUnignoredUser(id, err) {
if (err) {
const text = qsTr("Failed to unignore \"%1\": %2").arg(id).arg(err)
MainWindow.showNotification(text)
} else {
users = Array.from(users).filter(user => user !== id)
}
}
}
ListView {
id: view
width: ignoredUsers.width
height: ignoredUsers.height
Layout.leftMargin: Nheko.paddingMedium
Layout.rightMargin: Nheko.paddingMedium
spacing: Nheko.paddingMedium
model: users
delegate: RowLayout {
width: view.width
Text {
Layout.fillWidth: true
Layout.alignment: Qt.AlignLeft
elide: Text.ElideRight
color: palette.text
text: modelData
}
ImageButton {
Layout.preferredHeight: 24
Layout.preferredWidth: 24
image: ":/icons/icons/ui/delete.svg"
hoverEnabled: true
ToolTip.visible: hovered
ToolTip.text: qsTr("Stop Ignoring.")
onClicked: profile.ignoredStatus(modelData, false)
}
}
}
}

View file

@ -289,6 +289,19 @@ ApplicationWindow {
visible: !profile.isGlobalUserProfile && profile.room.permissions.canBan()
}
ImageButton {
Layout.preferredHeight: 24
Layout.preferredWidth: 24
image: ":/icons/icons/ui/volume-off-indicator.svg"
hoverEnabled: true
ToolTip.visible: hovered
ToolTip.text: qsTr("Ignore the user.")
onClicked: {
profile.ignoredStatus(profile.userid, true)
}
visible: !profile.isSelf && !profile.isGlobalUserProfile
}
ImageButton {
Layout.preferredHeight: 24
Layout.preferredWidth: 24
@ -299,6 +312,25 @@ ApplicationWindow {
onClicked: profile.refreshDevices()
}
ImageButton {
Layout.preferredHeight: 24
Layout.preferredWidth: 24
image: ":/icons/icons/ui/volume-off-indicator.svg"
hoverEnabled: true
ToolTip.visible: hovered
ToolTip.text: qsTr("Ignored users.")
onClicked: {
var component = Qt.createComponent("IgnoredUsers.qml")
if (component.status == Component.Ready) {
var window = component.createObject(userProfileDialog, {users: profile.getIgnoredUsers(), profile: profile})
window.show()
timelineRoot.destroyOnClose(window)
} else {
console.error("Failed to create component: " + component.errorString());
}
}
visible: profile.isSelf && profile.isGlobalUserProfile
}
}
TabBar {

View file

@ -521,6 +521,8 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
cache::client()->updateState(room_id_.toStdString(), events_, true);
this->syncState({std::move(events_.events)});
});
connect(this, &TimelineModel::ignoredUser, this, &TimelineModel::handleIgnoredUser);
}
QHash<int, QByteArray>
@ -2108,6 +2110,17 @@ TimelineModel::scrollTimerEvent()
}
}
void
TimelineModel::handleIgnoredUser(const QString &id, const std::optional<QString> &err)
{
if (err) {
MainWindow::instance()->showNotification(
tr("Failed to ignore \"%1\": %2").arg(id).arg(*err));
} else {
this->clearTimeline();
}
}
void
TimelineModel::requestKeyForEvent(const QString &id)
{

View file

@ -454,6 +454,7 @@ public slots:
private slots:
void addPendingMessage(mtx::events::collections::TimelineEvents event);
void scrollTimerEvent();
void handleIgnoredUser(const QString &id, const std::optional<QString> &err);
signals:
void dataAtIdChanged(QString id);
@ -503,6 +504,9 @@ signals:
void fetchedMore();
// The user may close the profile window before we receive a response, so handle it here
void ignoredUser(const QString &id, const std::optional<QString> &err);
private:
template<typename T>
void sendEncryptedMessage(mtx::events::RoomEvent<T> msg, mtx::events::EventType eventType);

View file

@ -224,6 +224,57 @@ UserProfile::refreshDevices()
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
UserProfile::ignoredStatus(const QString &id, const bool ignore)
{
auto old = this->getIgnoredUsers();
if (ignore) {
if (old.contains(id)) {
emit this->room()->ignoredUser(id, tr("Already ignored"));
return;
}
old.append(id);
} else {
old.removeOne(id);
}
std::vector<mtx::events::account_data::IgnoredUser> content;
for (const QString &item : old) {
const mtx::events::account_data::IgnoredUser data{.id = item.toStdString()};
content.push_back(data);
}
const mtx::events::account_data::IgnoredUsers payload{.users{content}};
http::client()->put_account_data(payload, [this, id, ignore](mtx::http::RequestErr e) {
if (ignore) {
emit this->room()->ignoredUser(
id, e ? std::optional(QString::fromStdString(e->matrix_error.error)) : std::nullopt);
} else {
emit this->unignoredUser(
id, e ? QVariant(QString::fromStdString(e->matrix_error.error)) : QVariant());
}
});
}
void
UserProfile::fetchDeviceList(const QString &userID)
{
@ -345,10 +396,6 @@ UserProfile::banUser()
ChatPage::instance()->banUser(roomid_, this->userid_, QLatin1String(""));
}
// void ignoreUser(){
// }
void
UserProfile::kickUser()
{

View file

@ -182,9 +182,10 @@ public:
Q_INVOKABLE void unverify(const QString &device = QLatin1String(""));
Q_INVOKABLE void fetchDeviceList(const QString &userID);
Q_INVOKABLE void refreshDevices();
Q_INVOKABLE QVector<QString> getIgnoredUsers();
Q_INVOKABLE void banUser();
Q_INVOKABLE void signOutDevice(const QString &deviceID);
// Q_INVOKABLE void ignoreUser();
Q_INVOKABLE void ignoredStatus(const QString &id, const bool ignore);
Q_INVOKABLE void kickUser();
Q_INVOKABLE void startChat();
Q_INVOKABLE void startChat(bool encryptionEnabled);
@ -201,6 +202,7 @@ signals:
void displayError(const QString &errorMessage);
void globalUsernameRetrieved(const QString &globalUser);
void devicesChanged();
void unignoredUser(const QString &id, const QVariant &err);
// internal
void verificationStatiChanged();