Add /join command support
This commit is contained in:
parent
ac525970b0
commit
76ddfb792b
@ -54,6 +54,7 @@ signals:
|
|||||||
void close();
|
void close();
|
||||||
void changeWindowTitle(const QString &msg);
|
void changeWindowTitle(const QString &msg);
|
||||||
void unreadMessages(int count);
|
void unreadMessages(int count);
|
||||||
|
void showNotification(const QString &msg);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void showUnreadMessageNotification(int count);
|
void showUnreadMessageNotification(int count);
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
#include "OverlayModal.h"
|
#include "OverlayModal.h"
|
||||||
#include "RegisterPage.h"
|
#include "RegisterPage.h"
|
||||||
|
#include "SnackBar.h"
|
||||||
#include "TrayIcon.h"
|
#include "TrayIcon.h"
|
||||||
#include "WelcomePage.h"
|
#include "WelcomePage.h"
|
||||||
|
|
||||||
@ -91,4 +92,7 @@ private:
|
|||||||
|
|
||||||
// Tray icon that shows the unread message count.
|
// Tray icon that shows the unread message count.
|
||||||
TrayIcon *trayIcon_;
|
TrayIcon *trayIcon_;
|
||||||
|
|
||||||
|
// Notifications display.
|
||||||
|
QSharedPointer<SnackBar> snackBar_;
|
||||||
};
|
};
|
||||||
|
@ -93,6 +93,7 @@ signals:
|
|||||||
void initialSyncCompleted(const SyncResponse &response);
|
void initialSyncCompleted(const SyncResponse &response);
|
||||||
void syncCompleted(const SyncResponse &response);
|
void syncCompleted(const SyncResponse &response);
|
||||||
void syncFailed(const QString &msg);
|
void syncFailed(const QString &msg);
|
||||||
|
void joinFailed(const QString &msg);
|
||||||
void messageSent(const QString &event_id, const QString &roomid, const int txn_id);
|
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 emoteSent(const QString &event_id, const QString &roomid, const int txn_id);
|
||||||
void messagesRetrieved(const QString &room_id, const RoomMessages &msgs);
|
void messagesRetrieved(const QString &room_id, const RoomMessages &msgs);
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
namespace msgs = matrix::events::messages;
|
namespace msgs = matrix::events::messages;
|
||||||
|
|
||||||
static const QString EMOTE_COMMAND("/me ");
|
static const QString EMOTE_COMMAND("/me ");
|
||||||
|
static const QString JOIN_COMMAND("/join ");
|
||||||
|
|
||||||
class FilteredTextEdit : public QTextEdit
|
class FilteredTextEdit : public QTextEdit
|
||||||
{
|
{
|
||||||
@ -63,10 +64,12 @@ signals:
|
|||||||
void sendTextMessage(QString msg);
|
void sendTextMessage(QString msg);
|
||||||
void sendEmoteMessage(QString msg);
|
void sendEmoteMessage(QString msg);
|
||||||
void uploadImage(QString filename);
|
void uploadImage(QString filename);
|
||||||
|
void sendJoinRoomRequest(const QString &room);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void showUploadSpinner();
|
void showUploadSpinner();
|
||||||
QString parseEmoteCommand(const QString &cmd);
|
QString parseEmoteCommand(const QString &cmd);
|
||||||
|
QString parseJoinCommand(const QString &cmd);
|
||||||
|
|
||||||
QHBoxLayout *topLayout_;
|
QHBoxLayout *topLayout_;
|
||||||
FilteredTextEdit *input_;
|
FilteredTextEdit *input_;
|
||||||
|
@ -166,10 +166,16 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
|||||||
view_manager_,
|
view_manager_,
|
||||||
SLOT(sendEmoteMessage(const QString &)));
|
SLOT(sendEmoteMessage(const QString &)));
|
||||||
|
|
||||||
|
connect(text_input_,
|
||||||
|
&TextInputWidget::sendJoinRoomRequest,
|
||||||
|
client_.data(),
|
||||||
|
&MatrixClient::joinRoom);
|
||||||
|
|
||||||
connect(text_input_, &TextInputWidget::uploadImage, this, [=](QString filename) {
|
connect(text_input_, &TextInputWidget::uploadImage, this, [=](QString filename) {
|
||||||
client_->uploadImage(current_room_, filename);
|
client_->uploadImage(current_room_, filename);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(client_.data(), &MatrixClient::joinFailed, this, &ChatPage::showNotification);
|
||||||
connect(client_.data(),
|
connect(client_.data(),
|
||||||
&MatrixClient::imageUploaded,
|
&MatrixClient::imageUploaded,
|
||||||
this,
|
this,
|
||||||
@ -203,10 +209,9 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
|||||||
SIGNAL(ownAvatarRetrieved(const QPixmap &)),
|
SIGNAL(ownAvatarRetrieved(const QPixmap &)),
|
||||||
this,
|
this,
|
||||||
SLOT(setOwnAvatar(const QPixmap &)));
|
SLOT(setOwnAvatar(const QPixmap &)));
|
||||||
connect(client_.data(),
|
connect(client_.data(), &MatrixClient::joinedRoom, this, [=]() {
|
||||||
SIGNAL(joinedRoom(const QString &)),
|
emit showNotification("You joined the room.");
|
||||||
this,
|
});
|
||||||
SLOT(addRoom(const QString &)));
|
|
||||||
connect(client_.data(),
|
connect(client_.data(),
|
||||||
SIGNAL(leftRoom(const QString &)),
|
SIGNAL(leftRoom(const QString &)),
|
||||||
this,
|
this,
|
||||||
@ -636,9 +641,9 @@ ChatPage::addRoom(const QString &room_id)
|
|||||||
QSharedPointer<RoomSettings>(new RoomSettings(room_id)));
|
QSharedPointer<RoomSettings>(new RoomSettings(room_id)));
|
||||||
|
|
||||||
room_list_->addRoom(settingsManager_[room_id], state_manager_[room_id], room_id);
|
room_list_->addRoom(settingsManager_[room_id], state_manager_[room_id], room_id);
|
||||||
|
|
||||||
this->changeTopRoomInfo(room_id);
|
|
||||||
room_list_->highlightSelectedRoom(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/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Config.h"
|
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
|
#include "Config.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QLayout>
|
#include <QLayout>
|
||||||
@ -142,6 +142,15 @@ MainWindow::removeOverlayProgressBar()
|
|||||||
spinner_.reset();
|
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);
|
timer->start(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,13 +477,22 @@ MatrixClient::onJoinRoomResponse(QNetworkReply *reply)
|
|||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||||
|
|
||||||
if (status == 0 || status >= 400) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto data = reply->readAll();
|
auto data = reply->readAll();
|
||||||
QJsonDocument response = QJsonDocument::fromJson(data);
|
auto response = QJsonDocument::fromJson(data);
|
||||||
QString room_id = response.object()["room_id"].toString();
|
auto room_id = response.object()["room_id"].toString();
|
||||||
|
|
||||||
emit joinedRoom(room_id);
|
emit joinedRoom(room_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -899,6 +908,7 @@ MatrixClient::joinRoom(const QString &roomIdOrAlias)
|
|||||||
|
|
||||||
QNetworkReply *reply = post(request, "{}");
|
QNetworkReply *reply = post(request, "{}");
|
||||||
reply->setProperty("endpoint", static_cast<int>(Endpoint::JoinRoom));
|
reply->setProperty("endpoint", static_cast<int>(Endpoint::JoinRoom));
|
||||||
|
reply->setProperty("room", roomIdOrAlias);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -148,6 +148,11 @@ TextInputWidget::onSendButtonClicked()
|
|||||||
|
|
||||||
if (!text.isEmpty())
|
if (!text.isEmpty())
|
||||||
emit sendEmoteMessage(text);
|
emit sendEmoteMessage(text);
|
||||||
|
} else if (msgText.startsWith(JOIN_COMMAND)) {
|
||||||
|
auto room = parseJoinCommand(msgText);
|
||||||
|
|
||||||
|
if (!room.isEmpty())
|
||||||
|
emit sendJoinRoomRequest(room);
|
||||||
} else {
|
} else {
|
||||||
emit sendTextMessage(msgText);
|
emit sendTextMessage(msgText);
|
||||||
}
|
}
|
||||||
@ -155,6 +160,17 @@ TextInputWidget::onSendButtonClicked()
|
|||||||
input_->clear();
|
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
|
QString
|
||||||
TextInputWidget::parseEmoteCommand(const QString &cmd)
|
TextInputWidget::parseEmoteCommand(const QString &cmd)
|
||||||
{
|
{
|
||||||
|
@ -84,7 +84,7 @@ SnackBar::showMessage(const QString &msg)
|
|||||||
void
|
void
|
||||||
SnackBar::onTimeout()
|
SnackBar::onTimeout()
|
||||||
{
|
{
|
||||||
offset_ -= 0.5;
|
offset_ -= 1.1;
|
||||||
|
|
||||||
if (offset_ <= 0.0) {
|
if (offset_ <= 0.0) {
|
||||||
showTimer_->stop();
|
showTimer_->stop();
|
||||||
|
Loading…
Reference in New Issue
Block a user