summary refs log tree commit diff
path: root/src/HistoryViewManager.cc
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2017-04-13 04:11:22 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2017-04-13 04:11:22 +0300
commit27f7142cd86a46d1b13d99a6b86c126892fa86ca (patch)
treef52d2ecf2ec2893cea67551b7c7fdde2fe39fe72 /src/HistoryViewManager.cc
parentDon't use icons as room avatars (diff)
downloadnheko-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 'src/HistoryViewManager.cc')
-rw-r--r--src/HistoryViewManager.cc41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/HistoryViewManager.cc b/src/HistoryViewManager.cc

index a91dcc4f..706a42f1 100644 --- a/src/HistoryViewManager.cc +++ b/src/HistoryViewManager.cc
@@ -18,14 +18,16 @@ #include <random> #include <QDebug> +#include <QSettings> #include <QStackedWidget> #include <QWidget> #include "HistoryView.h" #include "HistoryViewManager.h" -HistoryViewManager::HistoryViewManager(QWidget *parent) +HistoryViewManager::HistoryViewManager(QSharedPointer<MatrixClient> client, QWidget *parent) : QStackedWidget(parent) + , client_(client) { setStyleSheet( "QWidget {background: #171919; color: #ebebeb;}" @@ -33,12 +35,36 @@ HistoryViewManager::HistoryViewManager(QWidget *parent) "QScrollBar::handle:vertical { border-radius : 50px; background-color : #1c3133; }" "QScrollBar::add-line:vertical { border: none; background: none; }" "QScrollBar::sub-line:vertical { border: none; background: none; }"); + + connect(client_.data(), + SIGNAL(messageSent(const QString &, const QString &, int)), + this, + SLOT(messageSent(const QString &, const QString &, int))); } HistoryViewManager::~HistoryViewManager() { } +void HistoryViewManager::messageSent(const QString &event_id, const QString &roomid, int txn_id) +{ + // We save the latest valid transaction ID for later use. + QSettings settings; + settings.setValue("client/transaction_id", txn_id + 1); + + auto view = views_[roomid]; + view->updatePendingMessage(txn_id, event_id); +} + +void HistoryViewManager::sendTextMessage(const QString &msg) +{ + auto room = active_room_; + auto view = views_[room.id()]; + + view->addUserTextMessage(msg, client_->transactionId()); + client_->sendTextMessage(room.id(), msg); +} + void HistoryViewManager::clearAll() { NICK_COLORS.clear(); @@ -92,6 +118,7 @@ void HistoryViewManager::setHistoryView(const RoomInfo &info) return; } + active_room_ = info; auto widget = views_.value(info.id()); setCurrentWidget(widget); @@ -132,3 +159,15 @@ QString HistoryViewManager::chooseRandomColor() return HistoryViewManager::COLORS[dist(engine)]; } + +QString HistoryViewManager::getUserColor(const QString &userid) +{ + auto color = NICK_COLORS.value(userid); + + if (color.isEmpty()) { + color = chooseRandomColor(); + NICK_COLORS.insert(userid, color); + } + + return color; +}