React to externally left and joined rooms, and add "leave room" button in room menu (#75)
* Initial "join room" feature. * React correctly to remotely joined rooms. * Leaving rooms implemented both locally using the room menu in nheko, and reacting properly when leaving a room remotely from another client.
This commit is contained in:
parent
ea296321c9
commit
7ad45d8d64
23 changed files with 571 additions and 41 deletions
|
|
@ -37,6 +37,8 @@ public:
|
|||
inline void unmount();
|
||||
inline QString memberDbName(const QString &roomid);
|
||||
|
||||
void removeRoom(const QString &roomid);
|
||||
|
||||
private:
|
||||
void setNextBatchToken(lmdb::txn &txn, const QString &token);
|
||||
void insertRoomState(lmdb::txn &txn, const QString &roomid, const RoomState &state);
|
||||
|
|
|
|||
|
|
@ -61,6 +61,8 @@ private slots:
|
|||
void changeTopRoomInfo(const QString &room_id);
|
||||
void startSync();
|
||||
void logout();
|
||||
void addRoom(const QString &room_id);
|
||||
void removeRoom(const QString &room_id);
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
|
|
|
|||
22
include/JoinRoomDialog.h
Normal file
22
include/JoinRoomDialog.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include <QFrame>
|
||||
#include <QLineEdit>
|
||||
|
||||
#include "FlatButton.h"
|
||||
|
||||
class JoinRoomDialog : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
JoinRoomDialog(QWidget *parent = nullptr);
|
||||
|
||||
signals:
|
||||
void closing(bool isJoining, QString roomAlias);
|
||||
|
||||
private:
|
||||
FlatButton *confirmBtn_;
|
||||
FlatButton *cancelBtn_;
|
||||
|
||||
QLineEdit *roomAliasEdit_;
|
||||
};
|
||||
19
include/LeaveRoomDialog.h
Normal file
19
include/LeaveRoomDialog.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include <QFrame>
|
||||
|
||||
#include "FlatButton.h"
|
||||
|
||||
class LeaveRoomDialog : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LeaveRoomDialog(QWidget *parent = nullptr);
|
||||
|
||||
signals:
|
||||
void closing(bool isLeaving);
|
||||
|
||||
private:
|
||||
FlatButton *confirmBtn_;
|
||||
FlatButton *cancelBtn_;
|
||||
};
|
||||
|
|
@ -52,6 +52,8 @@ public:
|
|||
void downloadImage(const QString &event_id, const QUrl &url);
|
||||
void messages(const QString &room_id, const QString &from_token, int limit = 20) noexcept;
|
||||
void uploadImage(const QString &roomid, const QString &filename);
|
||||
void joinRoom(const QString &roomIdOrAlias);
|
||||
void leaveRoom(const QString &roomId);
|
||||
|
||||
inline QUrl getHomeServer();
|
||||
inline int transactionId();
|
||||
|
|
@ -94,6 +96,8 @@ signals:
|
|||
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);
|
||||
void joinedRoom(const QString &room_id);
|
||||
void leftRoom(const QString &room_id);
|
||||
|
||||
private slots:
|
||||
void onResponse(QNetworkReply *reply);
|
||||
|
|
@ -115,6 +119,8 @@ private:
|
|||
Sync,
|
||||
UserAvatar,
|
||||
Versions,
|
||||
JoinRoom,
|
||||
LeaveRoom,
|
||||
};
|
||||
|
||||
// Response handlers.
|
||||
|
|
@ -132,6 +138,8 @@ private:
|
|||
void onSyncResponse(QNetworkReply *reply);
|
||||
void onUserAvatarResponse(QNetworkReply *reply);
|
||||
void onVersionsResponse(QNetworkReply *reply);
|
||||
void onJoinRoomResponse(QNetworkReply *reply);
|
||||
void onLeaveRoomResponse(QNetworkReply *reply);
|
||||
|
||||
// Client API prefix.
|
||||
QString clientApiUrl_;
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ public:
|
|||
|
||||
signals:
|
||||
void clicked(const QString &room_id);
|
||||
void leaveRoom(const QString &room_id);
|
||||
|
||||
public slots:
|
||||
void setPressedState(bool state);
|
||||
|
|
@ -86,6 +87,7 @@ private:
|
|||
|
||||
Menu *menu_;
|
||||
QAction *toggleNotifications_;
|
||||
QAction *leaveRoom_;
|
||||
|
||||
QSharedPointer<RoomSettings> roomSettings_;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,12 +17,16 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QScrollArea>
|
||||
#include <QSharedPointer>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
|
||||
#include "JoinRoomDialog.h"
|
||||
#include "LeaveRoomDialog.h"
|
||||
#include "MatrixClient.h"
|
||||
#include "OverlayModal.h"
|
||||
#include "RoomInfoListItem.h"
|
||||
#include "RoomState.h"
|
||||
#include "Sync.h"
|
||||
|
|
@ -41,6 +45,11 @@ public:
|
|||
|
||||
void clear();
|
||||
|
||||
void addRoom(const QSharedPointer<RoomSettings> &settings,
|
||||
const RoomState &state,
|
||||
const QString &room_id);
|
||||
void removeRoom(const QString &room_id, bool reset);
|
||||
|
||||
signals:
|
||||
void roomChanged(const QString &room_id);
|
||||
void totalUnreadMessageCountUpdated(int count);
|
||||
|
|
@ -50,6 +59,9 @@ public slots:
|
|||
void highlightSelectedRoom(const QString &room_id);
|
||||
void updateUnreadMessageCount(const QString &roomid, int count);
|
||||
void updateRoomDescription(const QString &roomid, const DescInfo &info);
|
||||
void closeJoinRoomDialog(bool isJoining, QString roomAlias);
|
||||
void openLeaveRoomDialog(const QString &room_id);
|
||||
void closeLeaveRoomDialog(bool leaving, const QString &room_id);
|
||||
|
||||
private:
|
||||
void calculateUnreadMessageCount();
|
||||
|
|
@ -59,6 +71,14 @@ private:
|
|||
QScrollArea *scrollArea_;
|
||||
QWidget *scrollAreaContents_;
|
||||
|
||||
QPushButton *joinRoomButton_;
|
||||
|
||||
OverlayModal *joinRoomModal_;
|
||||
JoinRoomDialog *joinRoomDialog_;
|
||||
|
||||
OverlayModal *leaveRoomModal;
|
||||
LeaveRoomDialog *leaveRoomDialog_;
|
||||
|
||||
QMap<QString, QSharedPointer<RoomInfoListItem>> rooms_;
|
||||
|
||||
QSharedPointer<MatrixClient> client_;
|
||||
|
|
|
|||
|
|
@ -171,15 +171,42 @@ JoinedRoom::timeline() const
|
|||
return timeline_;
|
||||
}
|
||||
|
||||
class LeftRoom : public Deserializable
|
||||
{
|
||||
public:
|
||||
inline State state() const;
|
||||
inline Timeline timeline() const;
|
||||
|
||||
void deserialize(const QJsonValue &data) override;
|
||||
|
||||
private:
|
||||
State state_;
|
||||
Timeline timeline_;
|
||||
};
|
||||
|
||||
inline State
|
||||
LeftRoom::state() const
|
||||
{
|
||||
return state_;
|
||||
}
|
||||
|
||||
inline Timeline
|
||||
LeftRoom::timeline() const
|
||||
{
|
||||
return timeline_;
|
||||
}
|
||||
|
||||
// TODO: Add support for invited and left rooms.
|
||||
class Rooms : public Deserializable
|
||||
{
|
||||
public:
|
||||
inline QMap<QString, JoinedRoom> join() const;
|
||||
inline QMap<QString, LeftRoom> leave() const;
|
||||
void deserialize(const QJsonValue &data) override;
|
||||
|
||||
private:
|
||||
QMap<QString, JoinedRoom> join_;
|
||||
QMap<QString, LeftRoom> leave_;
|
||||
};
|
||||
|
||||
inline QMap<QString, JoinedRoom>
|
||||
|
|
@ -188,6 +215,12 @@ Rooms::join() const
|
|||
return join_;
|
||||
}
|
||||
|
||||
inline QMap<QString, LeftRoom>
|
||||
Rooms::leave() const
|
||||
{
|
||||
return leave_;
|
||||
}
|
||||
|
||||
class SyncResponse : public Deserializable
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -40,6 +40,10 @@ public:
|
|||
void initialize(const Rooms &rooms);
|
||||
// Empty initialization.
|
||||
void initialize(const QList<QString> &rooms);
|
||||
|
||||
void addRoom(const JoinedRoom &room, const QString &room_id);
|
||||
void addRoom(const QString &room_id);
|
||||
|
||||
void sync(const Rooms &rooms);
|
||||
void clearAll();
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,9 @@
|
|||
|
||||
#include "Avatar.h"
|
||||
#include "FlatButton.h"
|
||||
#include "LeaveRoomDialog.h"
|
||||
#include "Menu.h"
|
||||
#include "OverlayModal.h"
|
||||
#include "RoomSettings.h"
|
||||
|
||||
static const QString URL_HTML = "<a href=\"\\1\" style=\"color: #333333\">\\1</a>";
|
||||
|
|
@ -51,9 +53,15 @@ public:
|
|||
|
||||
void reset();
|
||||
|
||||
signals:
|
||||
void leaveRoom();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void closeLeaveRoomDialog(bool leaving);
|
||||
|
||||
private:
|
||||
QHBoxLayout *topLayout_;
|
||||
QVBoxLayout *textLayout_;
|
||||
|
|
@ -65,9 +73,13 @@ private:
|
|||
|
||||
QMenu *menu_;
|
||||
QAction *toggleNotifications_;
|
||||
QAction *leaveRoom_;
|
||||
|
||||
FlatButton *settingsBtn_;
|
||||
|
||||
OverlayModal *leaveRoomModal;
|
||||
LeaveRoomDialog *leaveRoomDialog_;
|
||||
|
||||
Avatar *avatar_;
|
||||
|
||||
int buttonSize_;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue