diff options
author | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2017-04-13 04:11:22 +0300 |
---|---|---|
committer | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2017-04-13 04:11:22 +0300 |
commit | 27f7142cd86a46d1b13d99a6b86c126892fa86ca (patch) | |
tree | f52d2ecf2ec2893cea67551b7c7fdde2fe39fe72 /include | |
parent | Don't use icons as room avatars (diff) | |
download | nheko-27f7142cd86a46d1b13d99a6b86c126892fa86ca.tar.xz |
Initial implementation for local echo
Each HistoryView maintains a list of pending events. Each pending message is validated from the homeserver with either the returned EventId or the body of the message. Currently there is no support to remove invalid messages. Also some small refactoring: - ChatPage doesn't know about the message being sent. The message delivery is solely handled by HistoryViewManager. - Nick coloring function moved to HistoryViewManager.
Diffstat (limited to 'include')
-rw-r--r-- | include/ChatPage.h | 2 | ||||
-rw-r--r-- | include/HistoryView.h | 15 | ||||
-rw-r--r-- | include/HistoryViewItem.h | 12 | ||||
-rw-r--r-- | include/HistoryViewManager.h | 11 | ||||
-rw-r--r-- | include/MatrixClient.h | 8 |
5 files changed, 44 insertions, 4 deletions
diff --git a/include/ChatPage.h b/include/ChatPage.h index d0edac3a..fd0b63dc 100644 --- a/include/ChatPage.h +++ b/include/ChatPage.h @@ -57,8 +57,6 @@ private slots: void syncCompleted(const SyncResponse &response); void syncFailed(const QString &msg); void changeTopRoomInfo(const RoomInfo &info); - void sendTextMessage(const QString &msg); - void messageSent(const QString event_id, int txn_id); void startSync(); void logout(); diff --git a/include/HistoryView.h b/include/HistoryView.h index 9eb0783f..ba267ad4 100644 --- a/include/HistoryView.h +++ b/include/HistoryView.h @@ -27,6 +27,15 @@ #include "HistoryViewItem.h" #include "Sync.h" +// Contains info about a message shown in the history view +// but not yet confirmed by the homeserver through sync. +struct PendingMessage { + int txn_id; + QString body; + QString event_id; + HistoryViewItem *widget; +}; + class HistoryView : public QWidget { Q_OBJECT @@ -38,6 +47,8 @@ public: void addHistoryItem(const Event &event, const QString &color, bool with_sender); void addEvents(const QList<Event> &events); + void addUserTextMessage(const QString &msg, int txn_id); + void updatePendingMessage(int txn_id, QString event_id); void clear(); public slots: @@ -45,6 +56,8 @@ public slots: private: void init(); + void removePendingMessage(const Event &event); + bool isPendingMessage(const Event &event, const QString &userid); QVBoxLayout *top_layout_; QVBoxLayout *scroll_layout_; @@ -53,6 +66,8 @@ private: QWidget *scroll_widget_; QString last_sender_; + + QList<PendingMessage> pending_msgs_; }; #endif // HISTORY_VIEW_H diff --git a/include/HistoryViewItem.h b/include/HistoryViewItem.h index 2d93e451..e1ed3374 100644 --- a/include/HistoryViewItem.h +++ b/include/HistoryViewItem.h @@ -28,10 +28,22 @@ class HistoryViewItem : public QWidget { Q_OBJECT public: + // For remote messages. HistoryViewItem(const Event &event, bool with_sender, const QString &color, QWidget *parent = 0); + + // For local messages. + HistoryViewItem(const QString &userid, const QString &color, const QString &body, QWidget *parent = 0); + HistoryViewItem(const QString &body, QWidget *parent = 0); + ~HistoryViewItem(); private: + void generateBody(const QString &body); + void generateBody(const QString &userid, const QString &color, const QString &body); + void generateTimestamp(const QDateTime &time); + + void setupLayout(); + QHBoxLayout *top_layout_; QLabel *time_label_; diff --git a/include/HistoryViewManager.h b/include/HistoryViewManager.h index cdb20e98..9f07f064 100644 --- a/include/HistoryViewManager.h +++ b/include/HistoryViewManager.h @@ -19,10 +19,12 @@ #define HISTORY_VIEW_MANAGER_H #include <QDebug> +#include <QSharedPointer> #include <QStackedWidget> #include <QWidget> #include "HistoryView.h" +#include "MatrixClient.h" #include "RoomInfo.h" #include "Sync.h" @@ -31,7 +33,7 @@ class HistoryViewManager : public QStackedWidget Q_OBJECT public: - HistoryViewManager(QWidget *parent); + HistoryViewManager(QSharedPointer<MatrixClient> client, QWidget *parent); ~HistoryViewManager(); void initialize(const Rooms &rooms); @@ -39,14 +41,21 @@ public: void clearAll(); static QString chooseRandomColor(); + static QString getUserColor(const QString &userid); static QMap<QString, QString> NICK_COLORS; static const QList<QString> COLORS; public slots: void setHistoryView(const RoomInfo &info); + void sendTextMessage(const QString &msg); + +private slots: + void messageSent(const QString &eventid, const QString &roomid, int txnid); private: + RoomInfo active_room_; QMap<QString, HistoryView *> views_; + QSharedPointer<MatrixClient> client_; }; #endif diff --git a/include/MatrixClient.h b/include/MatrixClient.h index 021a2594..8d517b9a 100644 --- a/include/MatrixClient.h +++ b/include/MatrixClient.h @@ -44,6 +44,7 @@ public: void fetchOwnAvatar(const QUrl &avatar_url); inline QString getHomeServer(); + inline int transactionId(); inline void incrementTransactionId(); void reset() noexcept; @@ -73,7 +74,7 @@ signals: void initialSyncCompleted(const SyncResponse &response); void syncCompleted(const SyncResponse &response); void syncFailed(const QString &msg); - void messageSent(const QString &event_id, const int txn_id); + void messageSent(const QString &event_id, const QString &roomid, const int txn_id); private slots: void onResponse(QNetworkReply *reply); @@ -126,6 +127,11 @@ inline QString MatrixClient::getHomeServer() return server_; } +inline int MatrixClient::transactionId() +{ + return txn_id_; +} + inline void MatrixClient::setServer(const QString &server) { server_ = "https://" + server; |