mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-10-30 09:30:47 +03:00
Merge pull request #1635 from NepNep21/ignore-command
Add /ignore, fixes #1634
This commit is contained in:
commit
45cc7ab6f7
9 changed files with 80 additions and 1 deletions
|
@ -229,6 +229,14 @@ Inserts `┯━┯╭( º _ º╭)`
|
||||||
*/sovietflip*::
|
*/sovietflip*::
|
||||||
Inserts `ノ┬─┬ノ ︵ ( \\o°o)\\`
|
Inserts `ノ┬─┬ノ ︵ ( \\o°o)\\`
|
||||||
|
|
||||||
|
=== User management
|
||||||
|
|
||||||
|
*/ignore* _<username>_::
|
||||||
|
Ignore a user, invites from them are also rejected.
|
||||||
|
|
||||||
|
*/unignore* _<username>_::
|
||||||
|
Stops ignoring a user.
|
||||||
|
|
||||||
=== Advanced
|
=== Advanced
|
||||||
|
|
||||||
*/clear-timeline*::
|
*/clear-timeline*::
|
||||||
|
|
|
@ -277,6 +277,16 @@ Item {
|
||||||
|
|
||||||
onClicked: Rooms.declineInvite(roomPreview.roomid)
|
onClicked: Rooms.declineInvite(roomPreview.roomid)
|
||||||
}
|
}
|
||||||
|
FlatButton {
|
||||||
|
Layout.alignment: Qt.AlignHCenter
|
||||||
|
text: qsTr("decline invite and ignore user")
|
||||||
|
visible: roomPreview && roomPreview.isInvite
|
||||||
|
|
||||||
|
onClicked: {
|
||||||
|
var inviter = TimelineManager.getGlobalUserProfile(roomPreview.inviterUserId)
|
||||||
|
inviter.ignored = true
|
||||||
|
}
|
||||||
|
}
|
||||||
FlatButton {
|
FlatButton {
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
text: qsTr("leave")
|
text: qsTr("leave")
|
||||||
|
|
|
@ -97,6 +97,10 @@ CommandCompleter::data(const QModelIndex &index, int role) const
|
||||||
return QStringLiteral("/converttodm");
|
return QStringLiteral("/converttodm");
|
||||||
case ConvertToRoom:
|
case ConvertToRoom:
|
||||||
return QStringLiteral("/converttoroom");
|
return QStringLiteral("/converttoroom");
|
||||||
|
case Ignore:
|
||||||
|
return QStringLiteral("/ignore");
|
||||||
|
case Unignore:
|
||||||
|
return QStringLiteral("/unignore");
|
||||||
default:
|
default:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -170,6 +174,10 @@ CommandCompleter::data(const QModelIndex &index, int role) const
|
||||||
return QStringLiteral("/converttodm");
|
return QStringLiteral("/converttodm");
|
||||||
case ConvertToRoom:
|
case ConvertToRoom:
|
||||||
return QStringLiteral("/converttoroom");
|
return QStringLiteral("/converttoroom");
|
||||||
|
case Ignore:
|
||||||
|
return QStringLiteral("/ignore <@userid>");
|
||||||
|
case Unignore:
|
||||||
|
return QStringLiteral("/unignore <@userid>");
|
||||||
default:
|
default:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -243,6 +251,10 @@ CommandCompleter::data(const QModelIndex &index, int role) const
|
||||||
return tr("Convert this room to a direct chat.");
|
return tr("Convert this room to a direct chat.");
|
||||||
case ConvertToRoom:
|
case ConvertToRoom:
|
||||||
return tr("Convert this direct chat into a room.");
|
return tr("Convert this direct chat into a room.");
|
||||||
|
case Ignore:
|
||||||
|
return tr("Ignore a user.");
|
||||||
|
case Unignore:
|
||||||
|
return tr("Stop ignoring a user.");
|
||||||
default:
|
default:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,8 @@ public:
|
||||||
Goto,
|
Goto,
|
||||||
ConvertToDm,
|
ConvertToDm,
|
||||||
ConvertToRoom,
|
ConvertToRoom,
|
||||||
|
Ignore,
|
||||||
|
Unignore,
|
||||||
COUNT,
|
COUNT,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include "ChatPage.h"
|
#include "ChatPage.h"
|
||||||
#include "EventAccessors.h"
|
#include "EventAccessors.h"
|
||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
|
#include "MainWindow.h"
|
||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
#include "TimelineModel.h"
|
#include "TimelineModel.h"
|
||||||
#include "TimelineViewManager.h"
|
#include "TimelineViewManager.h"
|
||||||
|
@ -239,7 +240,9 @@ InputBar::updateTextContentProperties(const QString &t)
|
||||||
QStringLiteral("msgtype"),
|
QStringLiteral("msgtype"),
|
||||||
QStringLiteral("goto"),
|
QStringLiteral("goto"),
|
||||||
QStringLiteral("converttodm"),
|
QStringLiteral("converttodm"),
|
||||||
QStringLiteral("converttoroom")};
|
QStringLiteral("converttoroom"),
|
||||||
|
QStringLiteral("ignore"),
|
||||||
|
QStringLiteral("unignore")};
|
||||||
bool hasInvalidCommand = !commandName.isNull() && !validCommands.contains(commandName);
|
bool hasInvalidCommand = !commandName.isNull() && !validCommands.contains(commandName);
|
||||||
bool hasIncompleteCommand = hasInvalidCommand && '/' + commandName == t;
|
bool hasIncompleteCommand = hasInvalidCommand && '/' + commandName == t;
|
||||||
|
|
||||||
|
@ -937,6 +940,10 @@ InputBar::command(const QString &command, QString args)
|
||||||
cache::getMembers(this->room->roomId().toStdString(), 0, -1));
|
cache::getMembers(this->room->roomId().toStdString(), 0, -1));
|
||||||
} else if (command == QLatin1String("converttoroom")) {
|
} else if (command == QLatin1String("converttoroom")) {
|
||||||
utils::removeDirectFromRoom(this->room->roomId());
|
utils::removeDirectFromRoom(this->room->roomId());
|
||||||
|
} else if (command == QLatin1String("ignore")) {
|
||||||
|
this->toggleIgnore(args, true);
|
||||||
|
} else if (command == QLatin1String("unignore")) {
|
||||||
|
this->toggleIgnore(args, false);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -944,6 +951,23 @@ InputBar::command(const QString &command, QString args)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
InputBar::toggleIgnore(const QString &user, const bool ignored)
|
||||||
|
{
|
||||||
|
UserProfile *profile = new UserProfile(QString(), user, TimelineViewManager::instance());
|
||||||
|
connect(profile, &UserProfile::failedToFetchProfile, [user, profile] {
|
||||||
|
MainWindow::instance()->showNotification(tr("Failed to fetch user %1").arg(user));
|
||||||
|
profile->deleteLater();
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(
|
||||||
|
profile, &UserProfile::globalUsernameRetrieved, [profile, ignored](const QString &user_id) {
|
||||||
|
Q_UNUSED(user_id)
|
||||||
|
profile->setIgnored(ignored);
|
||||||
|
profile->deleteLater();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
MediaUpload::MediaUpload(std::unique_ptr<QIODevice> source_,
|
MediaUpload::MediaUpload(std::unique_ptr<QIODevice> source_,
|
||||||
const QString &mimetype,
|
const QString &mimetype,
|
||||||
const QString &originalFilename,
|
const QString &originalFilename,
|
||||||
|
|
|
@ -283,6 +283,8 @@ private:
|
||||||
|
|
||||||
void updateTextContentProperties(const QString &t);
|
void updateTextContentProperties(const QString &t);
|
||||||
|
|
||||||
|
void toggleIgnore(const QString &user, const bool ignored);
|
||||||
|
|
||||||
QTimer typingRefresh_;
|
QTimer typingRefresh_;
|
||||||
QTimer typingTimeout_;
|
QTimer typingTimeout_;
|
||||||
TimelineModel *room;
|
TimelineModel *room;
|
||||||
|
|
|
@ -197,6 +197,8 @@ public:
|
||||||
return instance_;
|
return instance_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static FilteredRoomlistModel *instance() { return instance_; }
|
||||||
|
|
||||||
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
|
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
|
||||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &) const override;
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &) const override;
|
||||||
|
|
||||||
|
|
|
@ -278,6 +278,17 @@ UserProfile::setIgnored(bool ignore)
|
||||||
.arg(userid, QString::fromStdString(e->matrix_error.error)));
|
.arg(userid, QString::fromStdString(e->matrix_error.error)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (ignore) {
|
||||||
|
const QHash<QString, RoomInfo> invites = cache::invites();
|
||||||
|
FilteredRoomlistModel *room_model = FilteredRoomlistModel::instance();
|
||||||
|
|
||||||
|
for (auto room = invites.keyBegin(), end = invites.keyEnd(); room != end; room++) {
|
||||||
|
if (room_model->getRoomPreviewById(*room).inviterUserId() == userid) {
|
||||||
|
room_model->declineInvite(*room);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -592,12 +603,18 @@ UserProfile::getGlobalProfileData()
|
||||||
emit avatarUrlChanged();
|
emit avatarUrlChanged();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(profProx.get(),
|
||||||
|
&UserProfileFetchProxy::failedToFetchProfile,
|
||||||
|
this,
|
||||||
|
&UserProfile::failedToFetchProfile);
|
||||||
|
|
||||||
http::client()->get_profile(userid_.toStdString(),
|
http::client()->get_profile(userid_.toStdString(),
|
||||||
[prox = std::move(profProx), user = userid_.toStdString()](
|
[prox = std::move(profProx), user = userid_.toStdString()](
|
||||||
const mtx::responses::Profile &res, mtx::http::RequestErr err) {
|
const mtx::responses::Profile &res, mtx::http::RequestErr err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
nhlog::net()->warn("failed to retrieve profile info for {}",
|
nhlog::net()->warn("failed to retrieve profile info for {}",
|
||||||
user);
|
user);
|
||||||
|
emit prox->failedToFetchProfile();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ public:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void profileFetched(mtx::responses::Profile);
|
void profileFetched(mtx::responses::Profile);
|
||||||
|
void failedToFetchProfile();
|
||||||
};
|
};
|
||||||
|
|
||||||
class DeviceInfo
|
class DeviceInfo
|
||||||
|
@ -205,6 +206,7 @@ signals:
|
||||||
void globalUsernameRetrieved(const QString &globalUser);
|
void globalUsernameRetrieved(const QString &globalUser);
|
||||||
void devicesChanged();
|
void devicesChanged();
|
||||||
void ignoredChanged();
|
void ignoredChanged();
|
||||||
|
void failedToFetchProfile();
|
||||||
|
|
||||||
// internal
|
// internal
|
||||||
void verificationStatiChanged();
|
void verificationStatiChanged();
|
||||||
|
|
Loading…
Reference in a new issue