diff options
author | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2017-10-08 22:38:38 +0300 |
---|---|---|
committer | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2017-10-08 22:38:38 +0300 |
commit | 76ddfb792b8e99a14b2adae23cfc221314e98f00 (patch) | |
tree | 4993dc88208393f4bad801eff5cda637c838b63d /src | |
parent | Add snackbar (diff) | |
download | nheko-76ddfb792b8e99a14b2adae23cfc221314e98f00.tar.xz |
Add /join command support
Diffstat (limited to 'src')
-rw-r--r-- | src/ChatPage.cc | 17 | ||||
-rw-r--r-- | src/MainWindow.cc | 11 | ||||
-rw-r--r-- | src/MatrixClient.cc | 18 | ||||
-rw-r--r-- | src/TextInputWidget.cc | 16 | ||||
-rw-r--r-- | src/ui/SnackBar.cc | 2 |
5 files changed, 52 insertions, 12 deletions
diff --git a/src/ChatPage.cc b/src/ChatPage.cc index 5648a830..92692fc1 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc @@ -166,10 +166,16 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent) view_manager_, SLOT(sendEmoteMessage(const QString &))); + connect(text_input_, + &TextInputWidget::sendJoinRoomRequest, + client_.data(), + &MatrixClient::joinRoom); + connect(text_input_, &TextInputWidget::uploadImage, this, [=](QString filename) { client_->uploadImage(current_room_, filename); }); + connect(client_.data(), &MatrixClient::joinFailed, this, &ChatPage::showNotification); connect(client_.data(), &MatrixClient::imageUploaded, this, @@ -203,10 +209,9 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent) SIGNAL(ownAvatarRetrieved(const QPixmap &)), this, SLOT(setOwnAvatar(const QPixmap &))); - connect(client_.data(), - SIGNAL(joinedRoom(const QString &)), - this, - SLOT(addRoom(const QString &))); + connect(client_.data(), &MatrixClient::joinedRoom, this, [=]() { + emit showNotification("You joined the room."); + }); connect(client_.data(), SIGNAL(leftRoom(const QString &)), this, @@ -636,9 +641,9 @@ ChatPage::addRoom(const QString &room_id) QSharedPointer<RoomSettings>(new RoomSettings(room_id))); room_list_->addRoom(settingsManager_[room_id], state_manager_[room_id], room_id); - - this->changeTopRoomInfo(room_id); room_list_->highlightSelectedRoom(room_id); + + changeTopRoomInfo(room_id); } } diff --git a/src/MainWindow.cc b/src/MainWindow.cc index 80726683..06f8245c 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -15,8 +15,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "Config.h" #include "MainWindow.h" +#include "Config.h" #include <QApplication> #include <QLayout> @@ -142,6 +142,15 @@ MainWindow::removeOverlayProgressBar() spinner_.reset(); }); + // FIXME: Snackbar doesn't work if it's initialized in the constructor. + QTimer::singleShot(100, this, [=]() { + snackBar_ = QSharedPointer<SnackBar>(new SnackBar(this)); + connect(chat_page_, + &ChatPage::showNotification, + snackBar_.data(), + &SnackBar::showMessage); + }); + timer->start(500); } diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc index 708e1176..e9e47fcb 100644 --- a/src/MatrixClient.cc +++ b/src/MatrixClient.cc @@ -477,13 +477,22 @@ MatrixClient::onJoinRoomResponse(QNetworkReply *reply) int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if (status == 0 || status >= 400) { - qWarning() << reply->errorString(); + auto data = reply->readAll(); + auto response = QJsonDocument::fromJson(data); + auto json = response.object(); + + if (json.contains("error")) + emit joinFailed(json["error"].toString()); + else + qDebug() << reply->errorString(); + return; } - auto data = reply->readAll(); - QJsonDocument response = QJsonDocument::fromJson(data); - QString room_id = response.object()["room_id"].toString(); + auto data = reply->readAll(); + auto response = QJsonDocument::fromJson(data); + auto room_id = response.object()["room_id"].toString(); + emit joinedRoom(room_id); } @@ -899,6 +908,7 @@ MatrixClient::joinRoom(const QString &roomIdOrAlias) QNetworkReply *reply = post(request, "{}"); reply->setProperty("endpoint", static_cast<int>(Endpoint::JoinRoom)); + reply->setProperty("room", roomIdOrAlias); } void diff --git a/src/TextInputWidget.cc b/src/TextInputWidget.cc index f894a247..b90a7caa 100644 --- a/src/TextInputWidget.cc +++ b/src/TextInputWidget.cc @@ -148,6 +148,11 @@ TextInputWidget::onSendButtonClicked() if (!text.isEmpty()) emit sendEmoteMessage(text); + } else if (msgText.startsWith(JOIN_COMMAND)) { + auto room = parseJoinCommand(msgText); + + if (!room.isEmpty()) + emit sendJoinRoomRequest(room); } else { emit sendTextMessage(msgText); } @@ -156,6 +161,17 @@ TextInputWidget::onSendButtonClicked() } QString +TextInputWidget::parseJoinCommand(const QString &cmd) +{ + auto room = cmd.right(cmd.size() - JOIN_COMMAND.size()).trimmed(); + + if (!room.isEmpty()) + return room; + + return QString(""); +} + +QString TextInputWidget::parseEmoteCommand(const QString &cmd) { auto text = cmd.right(cmd.size() - EMOTE_COMMAND.size()).trimmed(); diff --git a/src/ui/SnackBar.cc b/src/ui/SnackBar.cc index 673c2f93..39566e99 100644 --- a/src/ui/SnackBar.cc +++ b/src/ui/SnackBar.cc @@ -84,7 +84,7 @@ SnackBar::showMessage(const QString &msg) void SnackBar::onTimeout() { - offset_ -= 0.5; + offset_ -= 1.1; if (offset_ <= 0.0) { showTimer_->stop(); |