From b0ff1baa1d1c38523b5479a5191a5559f4c21bf6 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 29 Jan 2020 00:30:53 +0100 Subject: [PATCH] Add command for invite,kick,ban and unban --- CMakeLists.txt | 2 +- resources/langs/nheko_de.ts | 101 ++++++++++++++++++++++++++++----- resources/langs/nheko_el.ts | 101 ++++++++++++++++++++++++++++----- resources/langs/nheko_en.ts | 101 ++++++++++++++++++++++++++++----- resources/langs/nheko_fi.ts | 101 ++++++++++++++++++++++++++++----- resources/langs/nheko_fr.ts | 101 ++++++++++++++++++++++++++++----- resources/langs/nheko_nl.ts | 101 ++++++++++++++++++++++++++++----- resources/langs/nheko_pl.ts | 101 ++++++++++++++++++++++++++++----- resources/langs/nheko_ru.ts | 101 ++++++++++++++++++++++++++++----- resources/langs/nheko_zh_CN.ts | 101 ++++++++++++++++++++++++++++----- src/ChatPage.cpp | 99 +++++++++++++++++++++++++++++--- src/TextInputWidget.cpp | 8 +++ src/TextInputWidget.h | 4 ++ 13 files changed, 877 insertions(+), 145 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d5faa4a9..c2496f2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -333,7 +333,7 @@ if(USE_BUNDLED_MTXCLIENT) FetchContent_Declare( MatrixClient GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git - GIT_TAG 1fd59de2a37e6b547db8e5b52114f3f10171ef2f + GIT_TAG 03b5008a05f895e91e3968de7b68db50f6c41b2a ) FetchContent_MakeAvailable(MatrixClient) else() diff --git a/resources/langs/nheko_de.ts b/resources/langs/nheko_de.ts index e4271a6e..32526797 100644 --- a/resources/langs/nheko_de.ts +++ b/resources/langs/nheko_de.ts @@ -4,7 +4,53 @@ ChatPage - + + Failed to invite user: %1 + + + + + + Invited user: %1 + + + + + Failed to invite %1 to %2: %3 + + + + + Failed to kick %1 to %2: %3 + + + + + Kicked user: %1 + + + + + Failed to ban %1 in %2: %3 + + + + + Banned user: %1 + + + + + Failed to unban %1 in %2: %3 + + + + + Unbanned user: %1 + + + + Failed to upload media. Please try again. Medienupload fehlgeschlagen. Bitte versuche es erneut. @@ -25,17 +71,37 @@ - + Please try to login again: %1 Bitte melde dich erneut an: %1 - + + Failed to join room: %1 + + + + + You joined the room + + + + + Failed to remove invite: %1 + + + + Room creation failed: %1 Raum konnte nicht erstellt werden: %1 - + + Room %1 created + + + + Failed to leave room: %1 Konnte den Raum nicht verlassen: %1 @@ -385,7 +451,7 @@ Emoji - + Select a file Datei auswählen @@ -403,7 +469,7 @@ TimelineModel - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted -- verschlüsselter Event (keine Schlüssel zur Entschlüsselung gefunden) -- @@ -646,42 +712,47 @@ UserSettingsPage - + Minimize to tray Ins Benachrichtigungsfeld minimieren - + Start in tray Im Benachrichtigungsfeld starten - + Group's sidebar Gruppen-Seitenleiste - + Circular Avatars Runde Profilbilder - + Typing notifications Schreibbenachrichtigungen - + Read receipts Lesebestätigungen - + + Send messages as markdown + + + + Desktop notifications Desktopbenachrichtigungen - + Scale factor Skalierungsfaktor @@ -741,7 +812,7 @@ ALLGEMEINES - + Open Sessions File Öffne Sessions Datei diff --git a/resources/langs/nheko_el.ts b/resources/langs/nheko_el.ts index 982a14ac..4344c568 100644 --- a/resources/langs/nheko_el.ts +++ b/resources/langs/nheko_el.ts @@ -4,7 +4,53 @@ ChatPage - + + Failed to invite user: %1 + + + + + + Invited user: %1 + + + + + Failed to invite %1 to %2: %3 + + + + + Failed to kick %1 to %2: %3 + + + + + Kicked user: %1 + + + + + Failed to ban %1 in %2: %3 + + + + + Banned user: %1 + + + + + Failed to unban %1 in %2: %3 + + + + + Unbanned user: %1 + + + + Failed to upload media. Please try again. @@ -25,17 +71,37 @@ - + Please try to login again: %1 - + + Failed to join room: %1 + + + + + You joined the room + + + + + Failed to remove invite: %1 + + + + Room creation failed: %1 - + + Room %1 created + + + + Failed to leave room: %1 @@ -385,7 +451,7 @@ - + Select a file Διάλεξε ένα αρχείο @@ -403,7 +469,7 @@ TimelineModel - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted @@ -646,42 +712,47 @@ UserSettingsPage - + Minimize to tray Ελαχιστοποίηση - + Start in tray - + Group's sidebar - + Circular Avatars - + Typing notifications - + Read receipts - + + Send messages as markdown + + + + Desktop notifications - + Scale factor @@ -741,7 +812,7 @@ ΓΕΝΙΚΑ - + Open Sessions File diff --git a/resources/langs/nheko_en.ts b/resources/langs/nheko_en.ts index 60b1fe3d..fee87ffb 100644 --- a/resources/langs/nheko_en.ts +++ b/resources/langs/nheko_en.ts @@ -4,7 +4,53 @@ ChatPage - + + Failed to invite user: %1 + + + + + + Invited user: %1 + + + + + Failed to invite %1 to %2: %3 + + + + + Failed to kick %1 to %2: %3 + + + + + Kicked user: %1 + + + + + Failed to ban %1 in %2: %3 + + + + + Banned user: %1 + + + + + Failed to unban %1 in %2: %3 + + + + + Unbanned user: %1 + + + + Failed to upload media. Please try again. @@ -25,17 +71,37 @@ - + Please try to login again: %1 Please try to login again: %1 - + + Failed to join room: %1 + + + + + You joined the room + + + + + Failed to remove invite: %1 + + + + Room creation failed: %1 Room creation failed: %1 - + + Room %1 created + + + + Failed to leave room: %1 Failed to leave room: %1 @@ -385,7 +451,7 @@ Emoji - + Select a file Select a file @@ -403,7 +469,7 @@ TimelineModel - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted -- Encrypted Event (No keys found for decryption) -- @@ -646,42 +712,47 @@ UserSettingsPage - + Minimize to tray Minimize to tray - + Start in tray Start in tray - + Group's sidebar Group's sidebar - + Circular Avatars - + Typing notifications Typing notifications - + Read receipts Read receipts - + + Send messages as markdown + + + + Desktop notifications Desktop notifications - + Scale factor Scale factor @@ -741,7 +812,7 @@ GENERAL - + Open Sessions File Open Sessions File diff --git a/resources/langs/nheko_fi.ts b/resources/langs/nheko_fi.ts index b4b184c9..f6e2756c 100644 --- a/resources/langs/nheko_fi.ts +++ b/resources/langs/nheko_fi.ts @@ -4,7 +4,53 @@ ChatPage - + + Failed to invite user: %1 + + + + + + Invited user: %1 + + + + + Failed to invite %1 to %2: %3 + + + + + Failed to kick %1 to %2: %3 + + + + + Kicked user: %1 + + + + + Failed to ban %1 in %2: %3 + + + + + Banned user: %1 + + + + + Failed to unban %1 in %2: %3 + + + + + Unbanned user: %1 + + + + Failed to upload media. Please try again. @@ -25,17 +71,37 @@ - + Please try to login again: %1 Ole hyvä ja yritä kirjautua sisään uudelleen: %1 - + + Failed to join room: %1 + + + + + You joined the room + + + + + Failed to remove invite: %1 + + + + Room creation failed: %1 Huoneen luominen epäonnistui: %1 - + + Room %1 created + + + + Failed to leave room: %1 Huoneesta poistuminen epäonnistui: %1 @@ -385,7 +451,7 @@ Emoji - + Select a file Valitse tiedosto @@ -403,7 +469,7 @@ TimelineModel - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted -- Salattu viesti (salauksen purkuavaimia ei löydetty) -- @@ -646,42 +712,47 @@ UserSettingsPage - + Minimize to tray Pienennä ilmoitusalueelle - + Start in tray Aloita ilmoitusalueella - + Group's sidebar Ryhmäsivupalkki - + Circular Avatars - + Typing notifications Kirjoitusilmoitukset - + Read receipts Lukukuittaukset - + + Send messages as markdown + + + + Desktop notifications Työpöytäilmoitukset - + Scale factor Mittakerroin @@ -741,7 +812,7 @@ YLEISET ASETUKSET - + Open Sessions File Avaa Istuntoavaintiedosto diff --git a/resources/langs/nheko_fr.ts b/resources/langs/nheko_fr.ts index c713dcb1..89dd8cdd 100644 --- a/resources/langs/nheko_fr.ts +++ b/resources/langs/nheko_fr.ts @@ -4,7 +4,53 @@ ChatPage - + + Failed to invite user: %1 + + + + + + Invited user: %1 + + + + + Failed to invite %1 to %2: %3 + + + + + Failed to kick %1 to %2: %3 + + + + + Kicked user: %1 + + + + + Failed to ban %1 in %2: %3 + + + + + Banned user: %1 + + + + + Failed to unban %1 in %2: %3 + + + + + Unbanned user: %1 + + + + Failed to upload media. Please try again. @@ -25,17 +71,37 @@ - + Please try to login again: %1 - + + Failed to join room: %1 + + + + + You joined the room + + + + + Failed to remove invite: %1 + + + + Room creation failed: %1 - + + Room %1 created + + + + Failed to leave room: %1 @@ -386,7 +452,7 @@ - + Select a file Sélectionnez un fichier @@ -404,7 +470,7 @@ TimelineModel - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted @@ -647,42 +713,47 @@ UserSettingsPage - + Minimize to tray Réduire à la barre des tâches - + Start in tray Démarrer dans la barre des tâches - + Group's sidebar Barre latérale des groupes - + Circular Avatars - + Typing notifications Notifications d'écriture - + Read receipts Accusés de lecture - + + Send messages as markdown + + + + Desktop notifications - + Scale factor @@ -742,7 +813,7 @@ GÉNÉRAL - + Open Sessions File diff --git a/resources/langs/nheko_nl.ts b/resources/langs/nheko_nl.ts index 82b0f881..2aa5de74 100644 --- a/resources/langs/nheko_nl.ts +++ b/resources/langs/nheko_nl.ts @@ -4,7 +4,53 @@ ChatPage - + + Failed to invite user: %1 + + + + + + Invited user: %1 + + + + + Failed to invite %1 to %2: %3 + + + + + Failed to kick %1 to %2: %3 + + + + + Kicked user: %1 + + + + + Failed to ban %1 in %2: %3 + + + + + Banned user: %1 + + + + + Failed to unban %1 in %2: %3 + + + + + Unbanned user: %1 + + + + Failed to upload media. Please try again. @@ -25,17 +71,37 @@ - + Please try to login again: %1 - + + Failed to join room: %1 + + + + + You joined the room + + + + + Failed to remove invite: %1 + + + + Room creation failed: %1 - + + Room %1 created + + + + Failed to leave room: %1 @@ -385,7 +451,7 @@ - + Select a file Kies een bestand @@ -403,7 +469,7 @@ TimelineModel - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted @@ -646,42 +712,47 @@ UserSettingsPage - + Minimize to tray Minimaliseren naar systeemvak - + Start in tray Geminimaliseerd opstarten - + Group's sidebar Zijbalk van groep - + Circular Avatars - + Typing notifications Meldingen bij typen van berichten - + Read receipts Leesbevestigingen - + + Send messages as markdown + + + + Desktop notifications - + Scale factor @@ -741,7 +812,7 @@ ALGEMEEN - + Open Sessions File diff --git a/resources/langs/nheko_pl.ts b/resources/langs/nheko_pl.ts index 6fb2133b..88dfe2b9 100644 --- a/resources/langs/nheko_pl.ts +++ b/resources/langs/nheko_pl.ts @@ -4,7 +4,53 @@ ChatPage - + + Failed to invite user: %1 + + + + + + Invited user: %1 + + + + + Failed to invite %1 to %2: %3 + + + + + Failed to kick %1 to %2: %3 + + + + + Kicked user: %1 + + + + + Failed to ban %1 in %2: %3 + + + + + Banned user: %1 + + + + + Failed to unban %1 in %2: %3 + + + + + Unbanned user: %1 + + + + Failed to upload media. Please try again. @@ -25,17 +71,37 @@ - + Please try to login again: %1 Spróbuj zalogować się ponownie: %1 - + + Failed to join room: %1 + + + + + You joined the room + + + + + Failed to remove invite: %1 + + + + Room creation failed: %1 Tworzenie pokoju nie powiodło się: %1 - + + Room %1 created + + + + Failed to leave room: %1 Nie udało się opuścić pokoju: %1 @@ -385,7 +451,7 @@ Emoji - + Select a file Wybierz plik @@ -403,7 +469,7 @@ TimelineModel - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted @@ -647,42 +713,47 @@ UserSettingsPage - + Minimize to tray Zminimalizuj do paska zadań - + Start in tray Rozpocznij na pasku zadań - + Group's sidebar Pasek boczny grupy - + Circular Avatars - + Typing notifications Powiadomienia o pisaniu - + Read receipts Potwierdzenia przeczytania - + + Send messages as markdown + + + + Desktop notifications Powiadomienia na pulpicie - + Scale factor @@ -742,7 +813,7 @@ OGÓLNE - + Open Sessions File diff --git a/resources/langs/nheko_ru.ts b/resources/langs/nheko_ru.ts index 1b84074f..07e169f7 100644 --- a/resources/langs/nheko_ru.ts +++ b/resources/langs/nheko_ru.ts @@ -4,7 +4,53 @@ ChatPage - + + Failed to invite user: %1 + + + + + + Invited user: %1 + + + + + Failed to invite %1 to %2: %3 + + + + + Failed to kick %1 to %2: %3 + + + + + Kicked user: %1 + + + + + Failed to ban %1 in %2: %3 + + + + + Banned user: %1 + + + + + Failed to unban %1 in %2: %3 + + + + + Unbanned user: %1 + + + + Failed to upload media. Please try again. @@ -25,17 +71,37 @@ - + Please try to login again: %1 Повторите попытку входа: %1 - + + Failed to join room: %1 + + + + + You joined the room + + + + + Failed to remove invite: %1 + + + + Room creation failed: %1 Не удалось создать комнату: %1 - + + Room %1 created + + + + Failed to leave room: %1 Не удалось покинуть комнату: %1 @@ -385,7 +451,7 @@ - + Select a file Выберите файл @@ -403,7 +469,7 @@ TimelineModel - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted @@ -647,42 +713,47 @@ UserSettingsPage - + Minimize to tray Сворачивать в системную панель - + Start in tray Запускать в системной панели - + Group's sidebar Боковая панель групп - + Circular Avatars - + Typing notifications Сообщать о наборе сообщения - + Read receipts Подтверждать прочтение - + + Send messages as markdown + + + + Desktop notifications Уведомления на рабочем столе - + Scale factor Масштаб @@ -742,7 +813,7 @@ ГЛАВНОЕ - + Open Sessions File Открыть файл сеансов diff --git a/resources/langs/nheko_zh_CN.ts b/resources/langs/nheko_zh_CN.ts index f8b19434..c7e42fba 100644 --- a/resources/langs/nheko_zh_CN.ts +++ b/resources/langs/nheko_zh_CN.ts @@ -4,7 +4,53 @@ ChatPage - + + Failed to invite user: %1 + + + + + + Invited user: %1 + + + + + Failed to invite %1 to %2: %3 + + + + + Failed to kick %1 to %2: %3 + + + + + Kicked user: %1 + + + + + Failed to ban %1 in %2: %3 + + + + + Banned user: %1 + + + + + Failed to unban %1 in %2: %3 + + + + + Unbanned user: %1 + + + + Failed to upload media. Please try again. @@ -25,17 +71,37 @@ - + Please try to login again: %1 请尝试再次登录:%1 - + + Failed to join room: %1 + + + + + You joined the room + + + + + Failed to remove invite: %1 + + + + Room creation failed: %1 创建聊天室失败:%1 - + + Room %1 created + + + + Failed to leave room: %1 离开聊天室失败:%1 @@ -385,7 +451,7 @@ - + Select a file 选择一个文件 @@ -403,7 +469,7 @@ TimelineModel - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted @@ -645,42 +711,47 @@ UserSettingsPage - + Minimize to tray 最小化至托盘 - + Start in tray 在托盘启动 - + Group's sidebar 群组侧边栏 - + Circular Avatars - + Typing notifications 打字通知 - + Read receipts 阅读回执 - + + Send messages as markdown + + + + Desktop notifications 桌面通知 - + Scale factor @@ -740,7 +811,7 @@ 通用 - + Open Sessions File 打开会话文件 diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index c7739281..a337baac 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -208,12 +208,11 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) mtx::http::RequestErr err) { if (err) { emit showNotification( - QString("Failed to invite user: %1").arg(user)); + tr("Failed to invite user: %1").arg(user)); return; } - emit showNotification( - QString("Invited user: %1").arg(user)); + emit showNotification(tr("Invited user: %1").arg(user)); }); }); } @@ -280,6 +279,89 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) connect(text_input_, &TextInputWidget::sendJoinRoomRequest, this, &ChatPage::joinRoom); + // invites and bans via quick command + connect(text_input_, + &TextInputWidget::sendInviteRoomRequest, + this, + [this](QString userid, QString reason) { + http::client()->invite_user( + current_room_.toStdString(), + userid.toStdString(), + [this, userid, room = current_room_](const mtx::responses::Empty &, + mtx::http::RequestErr err) { + if (err) { + emit showNotification(tr("Failed to invite %1 to %2: %3") + .arg(userid) + .arg(room) + .arg(QString::fromStdString( + err->matrix_error.error))); + } else + emit showNotification(tr("Invited user: %1").arg(userid)); + }, + reason.trimmed().toStdString()); + }); + connect(text_input_, + &TextInputWidget::sendKickRoomRequest, + this, + [this](QString userid, QString reason) { + http::client()->kick_user( + current_room_.toStdString(), + userid.toStdString(), + [this, userid, room = current_room_](const mtx::responses::Empty &, + mtx::http::RequestErr err) { + if (err) { + emit showNotification(tr("Failed to kick %1 to %2: %3") + .arg(userid) + .arg(room) + .arg(QString::fromStdString( + err->matrix_error.error))); + } else + emit showNotification(tr("Kicked user: %1").arg(userid)); + }, + reason.trimmed().toStdString()); + }); + connect(text_input_, + &TextInputWidget::sendBanRoomRequest, + this, + [this](QString userid, QString reason) { + http::client()->ban_user( + current_room_.toStdString(), + userid.toStdString(), + [this, userid, room = current_room_](const mtx::responses::Empty &, + mtx::http::RequestErr err) { + if (err) { + emit showNotification(tr("Failed to ban %1 in %2: %3") + .arg(userid) + .arg(room) + .arg(QString::fromStdString( + err->matrix_error.error))); + } else + emit showNotification(tr("Banned user: %1").arg(userid)); + }, + reason.trimmed().toStdString()); + }); + connect( + text_input_, + &TextInputWidget::sendUnbanRoomRequest, + this, + [this](QString userid, QString reason) { + http::client()->unban_user( + current_room_.toStdString(), + userid.toStdString(), + [this, userid, room = current_room_](const mtx::responses::Empty &, + mtx::http::RequestErr err) { + if (err) { + emit showNotification( + tr("Failed to unban %1 in %2: %3") + .arg(userid) + .arg(room) + .arg(QString::fromStdString(err->matrix_error.error))); + } else + emit showNotification(tr("Unbanned user: %1").arg(userid)); + }, + reason.trimmed().toStdString()); + }); + connect( text_input_, &TextInputWidget::uploadMedia, @@ -998,19 +1080,18 @@ ChatPage::joinRoom(const QString &room) room_id, [this, room_id](const nlohmann::json &, mtx::http::RequestErr err) { if (err) { emit showNotification( - QString("Failed to join room: %1") + tr("Failed to join room: %1") .arg(QString::fromStdString(err->matrix_error.error))); return; } - emit showNotification("You joined the room"); + emit tr("You joined the room"); // We remove any invites with the same room_id. try { cache::removeInvite(room_id); } catch (const lmdb::error &e) { - emit showNotification( - QString("Failed to remove invite: %1").arg(e.what())); + emit showNotification(tr("Failed to remove invite: %1").arg(e.what())); } }); } @@ -1033,8 +1114,8 @@ ChatPage::createRoom(const mtx::requests::CreateRoom &req) return; } - emit showNotification(QString("Room %1 created") - .arg(QString::fromStdString(res.room_id.to_string()))); + emit showNotification( + tr("Room %1 created").arg(QString::fromStdString(res.room_id.to_string()))); }); } diff --git a/src/TextInputWidget.cpp b/src/TextInputWidget.cpp index b6b51980..52686c0f 100644 --- a/src/TextInputWidget.cpp +++ b/src/TextInputWidget.cpp @@ -605,6 +605,14 @@ TextInputWidget::command(QString command, QString args) sendEmoteMessage(args, input_->related); } else if (command == "join") { sendJoinRoomRequest(args); + } else if (command == "invite") { + sendInviteRoomRequest(args.section(' ', 0, 0), args.section(' ', 1, -1)); + } else if (command == "kick") { + sendKickRoomRequest(args.section(' ', 0, 0), args.section(' ', 1, -1)); + } else if (command == "ban") { + sendBanRoomRequest(args.section(' ', 0, 0), args.section(' ', 1, -1)); + } else if (command == "unban") { + sendUnbanRoomRequest(args.section(' ', 0, 0), args.section(' ', 1, -1)); } else if (command == "shrug") { sendTextMessage("¯\\_(ツ)_/¯", input_->related); } else if (command == "fliptable") { diff --git a/src/TextInputWidget.h b/src/TextInputWidget.h index 6641d97c..4bdb2509 100644 --- a/src/TextInputWidget.h +++ b/src/TextInputWidget.h @@ -183,6 +183,10 @@ signals: const std::optional &related); void sendJoinRoomRequest(const QString &room); + void sendInviteRoomRequest(const QString &userid, const QString &reason); + void sendKickRoomRequest(const QString &userid, const QString &reason); + void sendBanRoomRequest(const QString &userid, const QString &reason); + void sendUnbanRoomRequest(const QString &userid, const QString &reason); void startedTyping(); void stoppedTyping();