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.
This commit is contained in:
parent
718562737c
commit
27f7142cd8
10 changed files with 245 additions and 49 deletions
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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_;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue