mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 03:00:46 +03:00
Add a /command to redact all visible messages sent by a user
This commit is contained in:
parent
7198cee85e
commit
678806749d
4 changed files with 31 additions and 0 deletions
|
@ -178,6 +178,12 @@ Ban a user from the current room. _reason_ is optional.
|
||||||
*/unban* _<username>_ _[reason]_::
|
*/unban* _<username>_ _[reason]_::
|
||||||
Unban a user. _reason_ is optional.
|
Unban a user. _reason_ is optional.
|
||||||
|
|
||||||
|
*/redact* _<username>_ _[reason]_::
|
||||||
|
Redacts all visible messages of the specified user. You will run into rate limits quickly.
|
||||||
|
|
||||||
|
*/redact* _<eventid>_ _[reason]_::
|
||||||
|
Redacts a specific event.
|
||||||
|
|
||||||
*/roomnick* _<roomname>_::
|
*/roomnick* _<roomname>_::
|
||||||
Change your nickname in a single room.
|
Change your nickname in a single room.
|
||||||
|
|
||||||
|
|
|
@ -692,6 +692,12 @@ InputBar::command(const QString &command, QString args)
|
||||||
} else if (command == QLatin1String("unban")) {
|
} else if (command == QLatin1String("unban")) {
|
||||||
ChatPage::instance()->unbanUser(
|
ChatPage::instance()->unbanUser(
|
||||||
room->roomId(), args.section(' ', 0, 0), args.section(' ', 1, -1));
|
room->roomId(), args.section(' ', 0, 0), args.section(' ', 1, -1));
|
||||||
|
} else if (command == QLatin1String("redact")) {
|
||||||
|
if (args.startsWith('@')) {
|
||||||
|
room->redactAllFromUser(args.section(' ', 0, 0), args.section(' ', 1, -1));
|
||||||
|
} else if (args.startsWith('$')) {
|
||||||
|
room->redactEvent(args.section(' ', 0, 0), args.section(' ', 1, -1));
|
||||||
|
}
|
||||||
} else if (command == QLatin1String("roomnick")) {
|
} else if (command == QLatin1String("roomnick")) {
|
||||||
mtx::events::state::Member member;
|
mtx::events::state::Member member;
|
||||||
member.display_name = args.toStdString();
|
member.display_name = args.toStdString();
|
||||||
|
|
|
@ -1271,6 +1271,24 @@ TimelineModel::showReadReceipts(QString id)
|
||||||
emit openReadReceiptsDialog(new ReadReceiptsProxy{id, roomId(), this});
|
emit openReadReceiptsDialog(new ReadReceiptsProxy{id, roomId(), this});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TimelineModel::redactAllFromUser(const QString &userid, const QString &reason)
|
||||||
|
{
|
||||||
|
auto user = userid.toStdString();
|
||||||
|
std::vector<QString> toRedact;
|
||||||
|
for (auto it = events.size() - 1; it >= 0; --it) {
|
||||||
|
auto event = events.get(it, false);
|
||||||
|
if (event && mtx::accessors::sender(*event) == user &&
|
||||||
|
!std::holds_alternative<mtx::events::RoomEvent<mtx::events::msg::Redacted>>(*event)) {
|
||||||
|
toRedact.push_back(QString::fromStdString(mtx::accessors::event_id(*event)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto &e : toRedact) {
|
||||||
|
redactEvent(e, reason);
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||||
|
}
|
||||||
|
}
|
||||||
void
|
void
|
||||||
TimelineModel::redactEvent(const QString &id, const QString &reason)
|
TimelineModel::redactEvent(const QString &id, const QString &reason)
|
||||||
{
|
{
|
||||||
|
|
|
@ -276,6 +276,7 @@ public:
|
||||||
Q_INVOKABLE void pin(const QString &id);
|
Q_INVOKABLE void pin(const QString &id);
|
||||||
Q_INVOKABLE void showReadReceipts(QString id);
|
Q_INVOKABLE void showReadReceipts(QString id);
|
||||||
Q_INVOKABLE void redactEvent(const QString &id, const QString &reason = "");
|
Q_INVOKABLE void redactEvent(const QString &id, const QString &reason = "");
|
||||||
|
Q_INVOKABLE void redactAllFromUser(const QString &userid, const QString &reason = "");
|
||||||
Q_INVOKABLE int idToIndex(const QString &id) const;
|
Q_INVOKABLE int idToIndex(const QString &id) const;
|
||||||
Q_INVOKABLE QString indexToId(int index) const;
|
Q_INVOKABLE QString indexToId(int index) const;
|
||||||
Q_INVOKABLE void openMedia(const QString &eventId);
|
Q_INVOKABLE void openMedia(const QString &eventId);
|
||||||
|
|
Loading…
Reference in a new issue