mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 03:00:46 +03:00
Cleanup ignore user functionality slightly
This commit is contained in:
parent
fce026725e
commit
a0a49b6c2a
7 changed files with 102 additions and 46 deletions
|
@ -295,11 +295,10 @@ ApplicationWindow {
|
||||||
image: ":/icons/icons/ui/volume-off-indicator.svg"
|
image: ":/icons/icons/ui/volume-off-indicator.svg"
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
ToolTip.visible: hovered
|
ToolTip.visible: hovered
|
||||||
ToolTip.text: qsTr("Ignore the user.")
|
ToolTip.text: profile.ignored ? qsTr("Unignore the user.") : qsTr("Ignore the user.")
|
||||||
onClicked: {
|
buttonTextColor: profile.ignored ? Nheko.theme.red : palette.buttonText
|
||||||
profile.ignoredStatus(profile.userid, true)
|
onClicked: profile.ignored = !profile.ignored
|
||||||
}
|
visible: !profile.isSelf
|
||||||
visible: !profile.isSelf && !profile.isGlobalUserProfile
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageButton {
|
ImageButton {
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
#include <mtx/responses.hpp>
|
#include <mtx/responses.hpp>
|
||||||
|
|
||||||
#include "AvatarProvider.h"
|
#include "AvatarProvider.h"
|
||||||
|
@ -21,7 +24,6 @@
|
||||||
#include "encryption/DeviceVerificationFlow.h"
|
#include "encryption/DeviceVerificationFlow.h"
|
||||||
#include "encryption/Olm.h"
|
#include "encryption/Olm.h"
|
||||||
#include "ui/RoomSummary.h"
|
#include "ui/RoomSummary.h"
|
||||||
#include "ui/Theme.h"
|
|
||||||
#include "ui/UserProfile.h"
|
#include "ui/UserProfile.h"
|
||||||
#include "voip/CallManager.h"
|
#include "voip/CallManager.h"
|
||||||
|
|
||||||
|
@ -29,8 +31,6 @@
|
||||||
|
|
||||||
#include "timeline/TimelineViewManager.h"
|
#include "timeline/TimelineViewManager.h"
|
||||||
|
|
||||||
#include "blurhash.hpp"
|
|
||||||
|
|
||||||
ChatPage *ChatPage::instance_ = nullptr;
|
ChatPage *ChatPage::instance_ = nullptr;
|
||||||
static constexpr int CHECK_CONNECTIVITY_INTERVAL = 15'000;
|
static constexpr int CHECK_CONNECTIVITY_INTERVAL = 15'000;
|
||||||
static constexpr int RETRY_TIMEOUT = 5'000;
|
static constexpr int RETRY_TIMEOUT = 5'000;
|
||||||
|
@ -765,6 +765,23 @@ ChatPage::handleSyncResponse(const mtx::responses::Sync &res, const std::string
|
||||||
// Ensure that we have enough one-time keys available.
|
// Ensure that we have enough one-time keys available.
|
||||||
ensureOneTimeKeyCount(res.device_one_time_keys_count, res.device_unused_fallback_key_types);
|
ensureOneTimeKeyCount(res.device_one_time_keys_count, res.device_unused_fallback_key_types);
|
||||||
|
|
||||||
|
std::optional<mtx::events::account_data::IgnoredUsers> oldIgnoredUsers;
|
||||||
|
if (auto ignoreEv = std::ranges::find_if(
|
||||||
|
res.account_data.events,
|
||||||
|
[](const mtx::events::collections::RoomAccountDataEvents &e) {
|
||||||
|
return std::holds_alternative<
|
||||||
|
mtx::events::AccountDataEvent<mtx::events::account_data::IgnoredUsers>>(e);
|
||||||
|
});
|
||||||
|
ignoreEv != res.account_data.events.end()) {
|
||||||
|
if (auto oldEv = cache::client()->getAccountData(mtx::events::EventType::IgnoredUsers))
|
||||||
|
oldIgnoredUsers =
|
||||||
|
std::get<mtx::events::AccountDataEvent<mtx::events::account_data::IgnoredUsers>>(
|
||||||
|
*oldEv)
|
||||||
|
.content;
|
||||||
|
else
|
||||||
|
oldIgnoredUsers = mtx::events::account_data::IgnoredUsers{};
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: fine grained error handling
|
// TODO: fine grained error handling
|
||||||
try {
|
try {
|
||||||
cache::client()->saveState(res);
|
cache::client()->saveState(res);
|
||||||
|
@ -773,6 +790,36 @@ ChatPage::handleSyncResponse(const mtx::responses::Sync &res, const std::string
|
||||||
auto updates = cache::getRoomInfo(cache::client()->roomsWithStateUpdates(res));
|
auto updates = cache::getRoomInfo(cache::client()->roomsWithStateUpdates(res));
|
||||||
|
|
||||||
emit syncUI(std::move(res));
|
emit syncUI(std::move(res));
|
||||||
|
|
||||||
|
// if the ignored users changed, clear timeline of all affected rooms.
|
||||||
|
if (oldIgnoredUsers) {
|
||||||
|
if (auto newEv =
|
||||||
|
cache::client()->getAccountData(mtx::events::EventType::IgnoredUsers)) {
|
||||||
|
std::vector<mtx::events::account_data::IgnoredUser> changedUsers{};
|
||||||
|
std::ranges::set_symmetric_difference(
|
||||||
|
oldIgnoredUsers->users,
|
||||||
|
std::get<mtx::events::AccountDataEvent<mtx::events::account_data::IgnoredUsers>>(
|
||||||
|
*newEv)
|
||||||
|
.content.users,
|
||||||
|
std::back_inserter(changedUsers),
|
||||||
|
{},
|
||||||
|
&mtx::events::account_data::IgnoredUser::id,
|
||||||
|
&mtx::events::account_data::IgnoredUser::id);
|
||||||
|
|
||||||
|
std::unordered_set<std::string> roomsToReload;
|
||||||
|
for (const auto &user : changedUsers) {
|
||||||
|
auto commonRooms = cache::client()->getCommonRooms(user.id);
|
||||||
|
for (const auto &room : commonRooms)
|
||||||
|
roomsToReload.insert(room.first);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto &room : roomsToReload) {
|
||||||
|
if (auto model =
|
||||||
|
view_manager_->rooms()->getRoomById(QString::fromStdString(room)))
|
||||||
|
model->clearTimeline();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (const lmdb::map_full_error &e) {
|
} catch (const lmdb::map_full_error &e) {
|
||||||
nhlog::db()->error("lmdb is full: {}", e.what());
|
nhlog::db()->error("lmdb is full: {}", e.what());
|
||||||
cache::deleteOldData();
|
cache::deleteOldData();
|
||||||
|
|
|
@ -521,8 +521,6 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
|
||||||
cache::client()->updateState(room_id_.toStdString(), events_, true);
|
cache::client()->updateState(room_id_.toStdString(), events_, true);
|
||||||
this->syncState({std::move(events_.events)});
|
this->syncState({std::move(events_.events)});
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(this, &TimelineModel::ignoredUser, this, &TimelineModel::handleIgnoredUser);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray>
|
QHash<int, QByteArray>
|
||||||
|
@ -2222,16 +2220,6 @@ 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, *err));
|
|
||||||
} else {
|
|
||||||
this->clearTimeline();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TimelineModel::requestKeyForEvent(const QString &id)
|
TimelineModel::requestKeyForEvent(const QString &id)
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
#include "CacheStructs.h"
|
#include "CacheStructs.h"
|
||||||
#include "EventStore.h"
|
#include "EventStore.h"
|
||||||
#include "InputBar.h"
|
#include "InputBar.h"
|
||||||
#include "InviteesModel.h"
|
|
||||||
#include "MemberList.h"
|
|
||||||
#include "Permissions.h"
|
#include "Permissions.h"
|
||||||
#include "ReadReceiptsModel.h"
|
#include "ReadReceiptsModel.h"
|
||||||
#include "ui/RoomSummary.h"
|
#include "ui/RoomSummary.h"
|
||||||
|
@ -463,7 +461,6 @@ public slots:
|
||||||
private slots:
|
private slots:
|
||||||
void addPendingMessage(mtx::events::collections::TimelineEvents event);
|
void addPendingMessage(mtx::events::collections::TimelineEvents event);
|
||||||
void scrollTimerEvent();
|
void scrollTimerEvent();
|
||||||
void handleIgnoredUser(const QString &id, const std::optional<QString> &err);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void dataAtIdChanged(QString id);
|
void dataAtIdChanged(QString id);
|
||||||
|
@ -513,9 +510,6 @@ signals:
|
||||||
|
|
||||||
void fetchedMore();
|
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:
|
private:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void sendEncryptedMessage(mtx::events::RoomEvent<T> msg, mtx::events::EventType eventType);
|
void sendEncryptedMessage(mtx::events::RoomEvent<T> msg, mtx::events::EventType eventType);
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
#include <mtx/common.hpp>
|
#include <mtx/common.hpp>
|
||||||
#include <mtx/responses/messages.hpp>
|
#include <mtx/responses/messages.hpp>
|
||||||
|
|
||||||
#include "ReadReceiptsModel.h"
|
#include "InviteesModel.h"
|
||||||
|
#include "MemberList.h"
|
||||||
#include "timeline/CommunitiesModel.h"
|
#include "timeline/CommunitiesModel.h"
|
||||||
#include "timeline/PresenceEmitter.h"
|
#include "timeline/PresenceEmitter.h"
|
||||||
#include "timeline/RoomlistModel.h"
|
#include "timeline/RoomlistModel.h"
|
||||||
|
|
|
@ -11,11 +11,11 @@
|
||||||
#include "Cache_p.h"
|
#include "Cache_p.h"
|
||||||
#include "ChatPage.h"
|
#include "ChatPage.h"
|
||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
|
#include "MainWindow.h"
|
||||||
|
#include "MatrixClient.h"
|
||||||
#include "UserProfile.h"
|
#include "UserProfile.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "encryption/DeviceVerificationFlow.h"
|
|
||||||
#include "encryption/VerificationManager.h"
|
#include "encryption/VerificationManager.h"
|
||||||
#include "mtx/responses/crypto.hpp"
|
|
||||||
#include "timeline/TimelineModel.h"
|
#include "timeline/TimelineModel.h"
|
||||||
#include "timeline/TimelineViewManager.h"
|
#include "timeline/TimelineViewManager.h"
|
||||||
#include "ui/UIA.h"
|
#include "ui/UIA.h"
|
||||||
|
@ -64,6 +64,19 @@ UserProfile::UserProfile(const QString &roomid,
|
||||||
new RoomInfoModel(cache::client()->getCommonRooms(userid.toStdString()), this);
|
new RoomInfoModel(cache::client()->getCommonRooms(userid.toStdString()), this);
|
||||||
else
|
else
|
||||||
sharedRooms_ = new RoomInfoModel({}, this);
|
sharedRooms_ = new RoomInfoModel({}, this);
|
||||||
|
|
||||||
|
connect(ChatPage::instance(), &ChatPage::syncUI, this, [this](const mtx::responses::Sync &res) {
|
||||||
|
if (auto ignoreEv = std::ranges::find_if(
|
||||||
|
res.account_data.events,
|
||||||
|
[](const mtx::events::collections::RoomAccountDataEvents &e) {
|
||||||
|
return std::holds_alternative<
|
||||||
|
mtx::events::AccountDataEvent<mtx::events::account_data::IgnoredUsers>>(e);
|
||||||
|
});
|
||||||
|
ignoreEv != res.account_data.events.end()) {
|
||||||
|
// doesn't matter much if it was actually us
|
||||||
|
emit ignoredChanged();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray>
|
QHash<int, QByteArray>
|
||||||
|
@ -224,34 +237,45 @@ UserProfile::refreshDevices()
|
||||||
fetchDeviceList(this->userid_);
|
fetchDeviceList(this->userid_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
UserProfile::ignored() const
|
||||||
|
{
|
||||||
|
auto old = TimelineViewManager::instance()->getIgnoredUsers();
|
||||||
|
return old.contains(userid_);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
UserProfile::ignoredStatus(const QString &id, const bool ignore)
|
UserProfile::setIgnored(bool ignore)
|
||||||
{
|
{
|
||||||
auto old = TimelineViewManager::instance()->getIgnoredUsers();
|
auto old = TimelineViewManager::instance()->getIgnoredUsers();
|
||||||
if (ignore) {
|
if (ignore) {
|
||||||
if (old.contains(id)) {
|
if (old.contains(userid_)) {
|
||||||
emit this->room()->ignoredUser(id, tr("Already ignored"));
|
emit ignoredChanged();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
old.append(id);
|
old.append(userid_);
|
||||||
} else {
|
} else {
|
||||||
old.removeOne(id);
|
if (!old.contains(userid_)) {
|
||||||
|
emit ignoredChanged();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
old.removeAll(userid_);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<mtx::events::account_data::IgnoredUser> content;
|
std::vector<mtx::events::account_data::IgnoredUser> content;
|
||||||
for (const QString &item : old) {
|
for (const QString &item : std::as_const(old)) {
|
||||||
const mtx::events::account_data::IgnoredUser data{.id = item.toStdString()};
|
content.emplace_back(item.toStdString());
|
||||||
content.push_back(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const mtx::events::account_data::IgnoredUsers payload{.users{content}};
|
mtx::events::account_data::IgnoredUsers payload{.users{content}};
|
||||||
|
|
||||||
http::client()->put_account_data(payload, [this, id, ignore](mtx::http::RequestErr e) {
|
auto userid = userid_;
|
||||||
if (ignore) {
|
|
||||||
emit this->room()->ignoredUser(
|
http::client()->put_account_data(payload, [userid](mtx::http::RequestErr e) {
|
||||||
id, e ? std::optional(QString::fromStdString(e->matrix_error.error)) : std::nullopt);
|
if (e) {
|
||||||
} else if (e) {
|
MainWindow::instance()->showNotification(
|
||||||
emit this->unignoredUserError(id, QString::fromStdString(e->matrix_error.error));
|
tr("Failed to ignore \"%1\": %2")
|
||||||
|
.arg(userid, QString::fromStdString(e->matrix_error.error)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,6 +157,7 @@ class UserProfile final : public QObject
|
||||||
Q_PROPERTY(int userVerified READ getUserStatus NOTIFY userStatusChanged)
|
Q_PROPERTY(int userVerified READ getUserStatus NOTIFY userStatusChanged)
|
||||||
Q_PROPERTY(bool isLoading READ isLoading NOTIFY loadingChanged)
|
Q_PROPERTY(bool isLoading READ isLoading NOTIFY loadingChanged)
|
||||||
Q_PROPERTY(bool userVerificationEnabled READ userVerificationEnabled NOTIFY userStatusChanged)
|
Q_PROPERTY(bool userVerificationEnabled READ userVerificationEnabled NOTIFY userStatusChanged)
|
||||||
|
Q_PROPERTY(bool ignored READ ignored WRITE setIgnored NOTIFY ignoredChanged)
|
||||||
Q_PROPERTY(bool isSelf READ isSelf CONSTANT)
|
Q_PROPERTY(bool isSelf READ isSelf CONSTANT)
|
||||||
Q_PROPERTY(TimelineModel *room READ room CONSTANT)
|
Q_PROPERTY(TimelineModel *room READ room CONSTANT)
|
||||||
public:
|
public:
|
||||||
|
@ -184,7 +185,6 @@ public:
|
||||||
Q_INVOKABLE void refreshDevices();
|
Q_INVOKABLE void refreshDevices();
|
||||||
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 kickUser();
|
Q_INVOKABLE void kickUser();
|
||||||
Q_INVOKABLE void startChat();
|
Q_INVOKABLE void startChat();
|
||||||
Q_INVOKABLE void startChat(bool encryptionEnabled);
|
Q_INVOKABLE void startChat(bool encryptionEnabled);
|
||||||
|
@ -193,6 +193,9 @@ public:
|
||||||
Q_INVOKABLE void changeAvatar();
|
Q_INVOKABLE void changeAvatar();
|
||||||
Q_INVOKABLE void openGlobalProfile();
|
Q_INVOKABLE void openGlobalProfile();
|
||||||
|
|
||||||
|
void setIgnored(bool ignored);
|
||||||
|
bool ignored() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void userStatusChanged();
|
void userStatusChanged();
|
||||||
void loadingChanged();
|
void loadingChanged();
|
||||||
|
@ -201,7 +204,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 unignoredUserError(const QString &id, const QVariant &err);
|
void ignoredChanged();
|
||||||
|
|
||||||
// internal
|
// internal
|
||||||
void verificationStatiChanged();
|
void verificationStatiChanged();
|
||||||
|
|
Loading…
Reference in a new issue