mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 12:38:48 +03:00
Add /join command support
This commit is contained in:
parent
ac525970b0
commit
76ddfb792b
9 changed files with 61 additions and 12 deletions
|
@ -54,6 +54,7 @@ signals:
|
|||
void close();
|
||||
void changeWindowTitle(const QString &msg);
|
||||
void unreadMessages(int count);
|
||||
void showNotification(const QString &msg);
|
||||
|
||||
private slots:
|
||||
void showUnreadMessageNotification(int count);
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "MatrixClient.h"
|
||||
#include "OverlayModal.h"
|
||||
#include "RegisterPage.h"
|
||||
#include "SnackBar.h"
|
||||
#include "TrayIcon.h"
|
||||
#include "WelcomePage.h"
|
||||
|
||||
|
@ -91,4 +92,7 @@ private:
|
|||
|
||||
// Tray icon that shows the unread message count.
|
||||
TrayIcon *trayIcon_;
|
||||
|
||||
// Notifications display.
|
||||
QSharedPointer<SnackBar> snackBar_;
|
||||
};
|
||||
|
|
|
@ -93,6 +93,7 @@ signals:
|
|||
void initialSyncCompleted(const SyncResponse &response);
|
||||
void syncCompleted(const SyncResponse &response);
|
||||
void syncFailed(const QString &msg);
|
||||
void joinFailed(const QString &msg);
|
||||
void messageSent(const QString &event_id, const QString &roomid, const int txn_id);
|
||||
void emoteSent(const QString &event_id, const QString &roomid, const int txn_id);
|
||||
void messagesRetrieved(const QString &room_id, const RoomMessages &msgs);
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
namespace msgs = matrix::events::messages;
|
||||
|
||||
static const QString EMOTE_COMMAND("/me ");
|
||||
static const QString JOIN_COMMAND("/join ");
|
||||
|
||||
class FilteredTextEdit : public QTextEdit
|
||||
{
|
||||
|
@ -63,10 +64,12 @@ signals:
|
|||
void sendTextMessage(QString msg);
|
||||
void sendEmoteMessage(QString msg);
|
||||
void uploadImage(QString filename);
|
||||
void sendJoinRoomRequest(const QString &room);
|
||||
|
||||
private:
|
||||
void showUploadSpinner();
|
||||
QString parseEmoteCommand(const QString &cmd);
|
||||
QString parseJoinCommand(const QString &cmd);
|
||||
|
||||
QHBoxLayout *topLayout_;
|
||||
FilteredTextEdit *input_;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
@ -155,6 +160,17 @@ TextInputWidget::onSendButtonClicked()
|
|||
input_->clear();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -84,7 +84,7 @@ SnackBar::showMessage(const QString &msg)
|
|||
void
|
||||
SnackBar::onTimeout()
|
||||
{
|
||||
offset_ -= 0.5;
|
||||
offset_ -= 1.1;
|
||||
|
||||
if (offset_ <= 0.0) {
|
||||
showTimer_->stop();
|
||||
|
|
Loading…
Reference in a new issue