Add write support for m.emote events

closes #41
This commit is contained in:
Konstantinos Sideris 2017-09-03 11:43:45 +03:00
parent a44a4f36af
commit b5ae84c3c3
11 changed files with 747 additions and 686 deletions

View File

@ -19,6 +19,7 @@
#include <QtNetwork/QNetworkAccessManager>
#include "MessageEvent.h"
#include "Profile.h"
#include "RoomMessages.h"
#include "Sync.h"
@ -29,145 +30,152 @@
*/
class MatrixClient : public QNetworkAccessManager
{
Q_OBJECT
Q_OBJECT
public:
MatrixClient(QString server, QObject *parent = 0);
MatrixClient(QString server, QObject *parent = 0);
// Client API.
void initialSync() noexcept;
void sync() noexcept;
void sendTextMessage(const QString &roomid, const QString &msg) noexcept;
void login(const QString &username, const QString &password) noexcept;
void registerUser(const QString &username, const QString &password, const QString &server) noexcept;
void versions() noexcept;
void fetchRoomAvatar(const QString &roomid, const QUrl &avatar_url);
void fetchUserAvatar(const QString &userId, const QUrl &avatarUrl);
void fetchOwnAvatar(const QUrl &avatar_url);
void downloadImage(const QString &event_id, const QUrl &url);
void messages(const QString &room_id, const QString &from_token, int limit = 20) noexcept;
// Client API.
void initialSync() noexcept;
void sync() noexcept;
void sendRoomMessage(matrix::events::MessageEventType ty,
const QString &roomid,
const QString &msg) noexcept;
void login(const QString &username, const QString &password) noexcept;
void registerUser(const QString &username,
const QString &password,
const QString &server) noexcept;
void versions() noexcept;
void fetchRoomAvatar(const QString &roomid, const QUrl &avatar_url);
void fetchUserAvatar(const QString &userId, const QUrl &avatarUrl);
void fetchOwnAvatar(const QUrl &avatar_url);
void downloadImage(const QString &event_id, const QUrl &url);
void messages(const QString &room_id, const QString &from_token, int limit = 20) noexcept;
inline QUrl getHomeServer();
inline int transactionId();
inline void incrementTransactionId();
inline QUrl getHomeServer();
inline int transactionId();
inline void incrementTransactionId();
void reset() noexcept;
void reset() noexcept;
public slots:
void getOwnProfile() noexcept;
void logout() noexcept;
void getOwnProfile() noexcept;
void logout() noexcept;
inline void setServer(const QString &server);
inline void setAccessToken(const QString &token);
inline void setNextBatchToken(const QString &next_batch);
inline void setServer(const QString &server);
inline void setAccessToken(const QString &token);
inline void setNextBatchToken(const QString &next_batch);
signals:
void loginError(const QString &error);
void registerError(const QString &error);
void versionError(const QString &error);
void loginError(const QString &error);
void registerError(const QString &error);
void versionError(const QString &error);
void loggedOut();
void loggedOut();
void loginSuccess(const QString &userid, const QString &homeserver, const QString &token);
void registerSuccess(const QString &userid, const QString &homeserver, const QString &token);
void versionSuccess();
void loginSuccess(const QString &userid, const QString &homeserver, const QString &token);
void registerSuccess(const QString &userid,
const QString &homeserver,
const QString &token);
void versionSuccess();
void roomAvatarRetrieved(const QString &roomid, const QPixmap &img);
void userAvatarRetrieved(const QString &userId, const QImage &img);
void ownAvatarRetrieved(const QPixmap &img);
void imageDownloaded(const QString &event_id, const QPixmap &img);
void roomAvatarRetrieved(const QString &roomid, const QPixmap &img);
void userAvatarRetrieved(const QString &userId, const QImage &img);
void ownAvatarRetrieved(const QPixmap &img);
void imageDownloaded(const QString &event_id, const QPixmap &img);
// Returned profile data for the user's account.
void getOwnProfileResponse(const QUrl &avatar_url, const QString &display_name);
void initialSyncCompleted(const SyncResponse &response);
void syncCompleted(const SyncResponse &response);
void syncFailed(const QString &msg);
void messageSent(const QString &event_id, const QString &roomid, const int txn_id);
void messagesRetrieved(const QString &room_id, const RoomMessages &msgs);
// Returned profile data for the user's account.
void getOwnProfileResponse(const QUrl &avatar_url, const QString &display_name);
void initialSyncCompleted(const SyncResponse &response);
void syncCompleted(const SyncResponse &response);
void syncFailed(const QString &msg);
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);
private slots:
void onResponse(QNetworkReply *reply);
void onResponse(QNetworkReply *reply);
private:
enum class Endpoint {
GetOwnAvatar,
GetOwnProfile,
GetProfile,
Image,
InitialSync,
Login,
Logout,
Messages,
Register,
RoomAvatar,
UserAvatar,
SendTextMessage,
Sync,
Versions,
};
enum class Endpoint {
GetOwnAvatar,
GetOwnProfile,
GetProfile,
Image,
InitialSync,
Login,
Logout,
Messages,
Register,
RoomAvatar,
SendRoomMessage,
Sync,
UserAvatar,
Versions,
};
// Response handlers.
void onLoginResponse(QNetworkReply *reply);
void onLogoutResponse(QNetworkReply *reply);
void onRegisterResponse(QNetworkReply *reply);
void onVersionsResponse(QNetworkReply *reply);
void onGetOwnProfileResponse(QNetworkReply *reply);
void onGetOwnAvatarResponse(QNetworkReply *reply);
void onSendTextMessageResponse(QNetworkReply *reply);
void onInitialSyncResponse(QNetworkReply *reply);
void onSyncResponse(QNetworkReply *reply);
void onRoomAvatarResponse(QNetworkReply *reply);
void onUserAvatarResponse(QNetworkReply *reply);
void onImageResponse(QNetworkReply *reply);
void onMessagesResponse(QNetworkReply *reply);
// Response handlers.
void onGetOwnAvatarResponse(QNetworkReply *reply);
void onGetOwnProfileResponse(QNetworkReply *reply);
void onImageResponse(QNetworkReply *reply);
void onInitialSyncResponse(QNetworkReply *reply);
void onLoginResponse(QNetworkReply *reply);
void onLogoutResponse(QNetworkReply *reply);
void onMessagesResponse(QNetworkReply *reply);
void onRegisterResponse(QNetworkReply *reply);
void onRoomAvatarResponse(QNetworkReply *reply);
void onSendRoomMessage(QNetworkReply *reply);
void onSyncResponse(QNetworkReply *reply);
void onUserAvatarResponse(QNetworkReply *reply);
void onVersionsResponse(QNetworkReply *reply);
// Client API prefix.
QString api_url_;
// Client API prefix.
QString api_url_;
// The Matrix server used for communication.
QUrl server_;
// The Matrix server used for communication.
QUrl server_;
// The access token used for authentication.
QString token_;
// The access token used for authentication.
QString token_;
// Increasing transaction ID.
int txn_id_;
// Increasing transaction ID.
int txn_id_;
// Token to be used for the next sync.
QString next_batch_;
// Token to be used for the next sync.
QString next_batch_;
};
inline QUrl
MatrixClient::getHomeServer()
{
return server_;
return server_;
}
inline int
MatrixClient::transactionId()
{
return txn_id_;
return txn_id_;
}
inline void
MatrixClient::setServer(const QString &server)
{
server_ = QUrl(QString("https://%1").arg(server));
server_ = QUrl(QString("https://%1").arg(server));
}
inline void
MatrixClient::setAccessToken(const QString &token)
{
token_ = token;
token_ = token;
}
inline void
MatrixClient::setNextBatchToken(const QString &next_batch)
{
next_batch_ = next_batch;
next_batch_ = next_batch;
}
inline void
MatrixClient::incrementTransactionId()
{
txn_id_ += 1;
txn_id_ += 1;
}

View File

@ -25,49 +25,51 @@
#include "EmojiPickButton.h"
#include "FlatButton.h"
static const QString EMOTE_COMMAND("/me ");
class FilteredTextEdit : public QTextEdit
{
Q_OBJECT
Q_OBJECT
public:
explicit FilteredTextEdit(QWidget *parent = nullptr);
void keyPressEvent(QKeyEvent *event);
explicit FilteredTextEdit(QWidget *parent = nullptr);
void keyPressEvent(QKeyEvent *event);
signals:
void enterPressed();
void enterPressed();
};
class TextInputWidget : public QWidget
class TextInputWidget : public QFrame
{
Q_OBJECT
Q_OBJECT
public:
TextInputWidget(QWidget *parent = 0);
~TextInputWidget();
TextInputWidget(QWidget *parent = 0);
~TextInputWidget();
public slots:
void onSendButtonClicked();
inline void focusLineEdit();
void onSendButtonClicked();
inline void focusLineEdit();
private slots:
void addSelectedEmoji(const QString &emoji);
void addSelectedEmoji(const QString &emoji);
signals:
void sendTextMessage(QString msg);
protected:
void paintEvent(QPaintEvent *event) override;
void sendTextMessage(QString msg);
void sendEmoteMessage(QString msg);
private:
QHBoxLayout *top_layout_;
FilteredTextEdit *input_;
QString parseEmoteCommand(const QString &cmd);
FlatButton *send_file_button_;
FlatButton *send_message_button_;
EmojiPickButton *emoji_button_;
QHBoxLayout *top_layout_;
FilteredTextEdit *input_;
FlatButton *send_file_button_;
FlatButton *send_message_button_;
EmojiPickButton *emoji_button_;
};
inline void
TextInputWidget::focusLineEdit()
{
input_->setFocus();
input_->setFocus();
}

View File

@ -50,8 +50,11 @@ public:
QWidget *parent = 0);
// For local messages.
TimelineItem(const QString &userid, QString body, QWidget *parent = 0);
TimelineItem(QString body, QWidget *parent = 0);
TimelineItem(events::MessageEventType ty,
const QString &userid,
QString body,
bool withSender,
QWidget *parent = 0);
TimelineItem(ImageItem *img,
const events::MessageEvent<msgs::Image> &e,

View File

@ -27,8 +27,9 @@
#include "Sync.h"
#include "TimelineItem.h"
#include "Image.h"
#include "Emote.h"
#include "Image.h"
#include "MessageEvent.h"
#include "Notice.h"
#include "RoomInfoListItem.h"
#include "Text.h"
@ -83,7 +84,7 @@ public:
// Add new events at the end of the timeline.
int addEvents(const Timeline &timeline);
void addUserTextMessage(const QString &msg, int txn_id);
void addUserMessage(matrix::events::MessageEventType ty, const QString &msg, int txn_id);
void updatePendingMessage(int txn_id, QString event_id);
void scrollDown();
@ -100,14 +101,19 @@ signals:
private:
void init();
void removePendingMessage(const events::MessageEvent<msgs::Text> &e);
void addTimelineItem(TimelineItem *item, TimelineDirection direction);
void updateLastSender(const QString &user_id, TimelineDirection direction);
void notifyForLastEvent();
// Used to determine whether or not we should prefix a message with the sender's name.
bool isSenderRendered(const QString &user_id, TimelineDirection direction);
bool isPendingMessage(const events::MessageEvent<msgs::Text> &e, const QString &userid);
template<class T>
bool isPendingMessage(const events::MessageEvent<T> &e, const QString &userid);
template<class T>
void removePendingMessage(const events::MessageEvent<T> &e);
inline bool isDuplicate(const QString &event_id);
// Return nullptr if the event couldn't be parsed.
@ -153,3 +159,32 @@ TimelineView::isDuplicate(const QString &event_id)
{
return eventIds_.contains(event_id);
}
template<class T>
bool
TimelineView::isPendingMessage(const events::MessageEvent<T> &e, const QString &local_userid)
{
if (e.sender() != local_userid)
return false;
for (const auto &msg : pending_msgs_) {
if (msg.event_id == e.eventId() || msg.body == e.content().body())
return true;
}
return false;
}
template<class T>
void
TimelineView::removePendingMessage(const events::MessageEvent<T> &e)
{
for (auto it = pending_msgs_.begin(); it != pending_msgs_.end(); it++) {
int index = std::distance(pending_msgs_.begin(), it);
if (it->event_id == e.eventId() || it->body == e.content().body()) {
pending_msgs_.removeAt(index);
break;
}
}
}

View File

@ -23,6 +23,7 @@
#include <QWidget>
#include "MatrixClient.h"
#include "MessageEvent.h"
#include "RoomInfoListItem.h"
#include "Sync.h"
#include "TimelineView.h"
@ -54,6 +55,7 @@ signals:
public slots:
void setHistoryView(const QString &room_id);
void sendTextMessage(const QString &msg);
void sendEmoteMessage(const QString &msg);
private slots:
void messageSent(const QString &eventid, const QString &roomid, int txnid);

View File

@ -148,6 +148,11 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
view_manager_,
SLOT(sendTextMessage(const QString &)));
connect(text_input_,
SIGNAL(sendEmoteMessage(const QString &)),
view_manager_,
SLOT(sendEmoteMessage(const QString &)));
connect(client_.data(),
SIGNAL(roomAvatarRetrieved(const QString &, const QPixmap &)),
this,

File diff suppressed because it is too large Load Diff

View File

@ -26,123 +26,133 @@
FilteredTextEdit::FilteredTextEdit(QWidget *parent)
: QTextEdit(parent)
{
setAcceptRichText(false);
setAcceptRichText(false);
}
void
FilteredTextEdit::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)
emit enterPressed();
else
QTextEdit::keyPressEvent(event);
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)
emit enterPressed();
else
QTextEdit::keyPressEvent(event);
}
TextInputWidget::TextInputWidget(QWidget *parent)
: QWidget(parent)
: QFrame(parent)
{
setFont(QFont("Emoji One"));
setFont(QFont("Emoji One"));
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setCursor(Qt::ArrowCursor);
setStyleSheet("background-color: #f8fbfe; height: 45px;");
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setCursor(Qt::ArrowCursor);
setStyleSheet("background-color: #f8fbfe; height: 45px;");
top_layout_ = new QHBoxLayout();
top_layout_->setSpacing(0);
top_layout_->setMargin(0);
top_layout_ = new QHBoxLayout();
top_layout_->setSpacing(0);
top_layout_->setMargin(0);
send_file_button_ = new FlatButton(this);
send_file_button_ = new FlatButton(this);
QIcon send_file_icon;
send_file_icon.addFile(":/icons/icons/clip-dark.png", QSize(), QIcon::Normal, QIcon::Off);
send_file_button_->setForegroundColor(QColor("#acc7dc"));
send_file_button_->setIcon(send_file_icon);
send_file_button_->setIconSize(QSize(24, 24));
QIcon send_file_icon;
send_file_icon.addFile(":/icons/icons/clip-dark.png", QSize(), QIcon::Normal, QIcon::Off);
send_file_button_->setForegroundColor(QColor("#acc7dc"));
send_file_button_->setIcon(send_file_icon);
send_file_button_->setIconSize(QSize(24, 24));
QFont font;
font.setPixelSize(conf::fontSize);
QFont font;
font.setPixelSize(conf::fontSize);
input_ = new FilteredTextEdit(this);
input_->setFixedHeight(45);
input_->setFont(font);
input_->setPlaceholderText(tr("Write a message..."));
input_->setStyleSheet("color: #333333; border-radius: 0; padding-top: 10px;");
input_ = new FilteredTextEdit(this);
input_->setFixedHeight(45);
input_->setFont(font);
input_->setPlaceholderText(tr("Write a message..."));
input_->setStyleSheet("color: #333333; border-radius: 0; padding-top: 10px;");
send_message_button_ = new FlatButton(this);
send_message_button_->setForegroundColor(QColor("#acc7dc"));
send_message_button_ = new FlatButton(this);
send_message_button_->setForegroundColor(QColor("#acc7dc"));
QIcon send_message_icon;
send_message_icon.addFile(":/icons/icons/share-dark.png", QSize(), QIcon::Normal, QIcon::Off);
send_message_button_->setIcon(send_message_icon);
send_message_button_->setIconSize(QSize(24, 24));
QIcon send_message_icon;
send_message_icon.addFile(
":/icons/icons/share-dark.png", QSize(), QIcon::Normal, QIcon::Off);
send_message_button_->setIcon(send_message_icon);
send_message_button_->setIconSize(QSize(24, 24));
emoji_button_ = new EmojiPickButton(this);
emoji_button_->setForegroundColor(QColor("#acc7dc"));
emoji_button_ = new EmojiPickButton(this);
emoji_button_->setForegroundColor(QColor("#acc7dc"));
QIcon emoji_icon;
emoji_icon.addFile(":/icons/icons/smile.png", QSize(), QIcon::Normal, QIcon::Off);
emoji_button_->setIcon(emoji_icon);
emoji_button_->setIconSize(QSize(24, 24));
QIcon emoji_icon;
emoji_icon.addFile(":/icons/icons/smile.png", QSize(), QIcon::Normal, QIcon::Off);
emoji_button_->setIcon(emoji_icon);
emoji_button_->setIconSize(QSize(24, 24));
top_layout_->addWidget(send_file_button_);
top_layout_->addWidget(input_);
top_layout_->addWidget(emoji_button_);
top_layout_->addWidget(send_message_button_);
top_layout_->addWidget(send_file_button_);
top_layout_->addWidget(input_);
top_layout_->addWidget(emoji_button_);
top_layout_->addWidget(send_message_button_);
setLayout(top_layout_);
setLayout(top_layout_);
connect(send_message_button_, SIGNAL(clicked()), this, SLOT(onSendButtonClicked()));
connect(input_, SIGNAL(enterPressed()), send_message_button_, SIGNAL(clicked()));
connect(emoji_button_, SIGNAL(emojiSelected(const QString &)), this, SLOT(addSelectedEmoji(const QString &)));
connect(send_message_button_, SIGNAL(clicked()), this, SLOT(onSendButtonClicked()));
connect(input_, SIGNAL(enterPressed()), send_message_button_, SIGNAL(clicked()));
connect(emoji_button_,
SIGNAL(emojiSelected(const QString &)),
this,
SLOT(addSelectedEmoji(const QString &)));
}
void
TextInputWidget::addSelectedEmoji(const QString &emoji)
{
QTextCursor cursor = input_->textCursor();
QTextCursor cursor = input_->textCursor();
QFont emoji_font("Emoji One");
emoji_font.setPixelSize(conf::emojiSize);
QFont emoji_font("Emoji One");
emoji_font.setPixelSize(conf::emojiSize);
QFont text_font("Open Sans");
text_font.setPixelSize(conf::fontSize);
QFont text_font("Open Sans");
text_font.setPixelSize(conf::fontSize);
QTextCharFormat charfmt;
charfmt.setFont(emoji_font);
input_->setCurrentCharFormat(charfmt);
QTextCharFormat charfmt;
charfmt.setFont(emoji_font);
input_->setCurrentCharFormat(charfmt);
input_->insertPlainText(emoji);
cursor.movePosition(QTextCursor::End);
input_->insertPlainText(emoji);
cursor.movePosition(QTextCursor::End);
charfmt.setFont(text_font);
input_->setCurrentCharFormat(charfmt);
charfmt.setFont(text_font);
input_->setCurrentCharFormat(charfmt);
input_->show();
input_->show();
}
void
TextInputWidget::onSendButtonClicked()
{
auto msg_text = input_->document()->toPlainText().trimmed();
auto msgText = input_->document()->toPlainText().trimmed();
if (msg_text.isEmpty())
return;
if (msgText.isEmpty())
return;
emit sendTextMessage(msg_text);
if (msgText.startsWith(EMOTE_COMMAND)) {
auto text = parseEmoteCommand(msgText);
input_->clear();
if (!text.isEmpty())
emit sendEmoteMessage(text);
} else {
emit sendTextMessage(msgText);
}
input_->clear();
}
void
TextInputWidget::paintEvent(QPaintEvent *event)
QString
TextInputWidget::parseEmoteCommand(const QString &cmd)
{
Q_UNUSED(event);
auto text = cmd.right(cmd.size() - EMOTE_COMMAND.size()).trimmed();
QStyleOption option;
option.initFrom(this);
if (!text.isEmpty())
return text;
QPainter painter(this);
style()->drawPrimitive(QStyle::PE_Widget, &option, &painter, this);
return QString("");
}
TextInputWidget::~TextInputWidget()

View File

@ -67,46 +67,42 @@ TimelineItem::init()
}
/*
* For messages created locally. The avatar and the username are displayed.
* For messages created locally.
*/
TimelineItem::TimelineItem(const QString &userid, QString body, QWidget *parent)
TimelineItem::TimelineItem(events::MessageEventType ty,
const QString &userid,
QString body,
bool withSender,
QWidget *parent)
: QWidget(parent)
{
init();
descriptionMsg_ = { "You: ", userid, body, descriptiveTime(QDateTime::currentDateTime()) };
body.replace(URL_REGEX, URL_HTML);
auto displayName = TimelineViewManager::displayName(userid);
auto timestamp = QDateTime::currentDateTime();
generateTimestamp(QDateTime::currentDateTime());
generateBody(displayName, body);
setupAvatarLayout(displayName);
mainLayout_->addLayout(headerLayout_);
mainLayout_->addWidget(body_);
AvatarProvider::resolve(userid, this);
}
/*
* For messages created locally. Only the text is displayed.
*/
TimelineItem::TimelineItem(QString body, QWidget *parent)
: QWidget(parent)
{
QSettings settings;
auto userid = settings.value("auth/user_id").toString();
init();
descriptionMsg_ = { "You: ", userid, body, descriptiveTime(QDateTime::currentDateTime()) };
if (ty == events::MessageEventType::Emote) {
body = QString("* %1 %2").arg(displayName).arg(body);
descriptionMsg_ = { "", userid, body, descriptiveTime(timestamp) };
} else {
descriptionMsg_ = {
"You: ", userid, body, descriptiveTime(QDateTime::currentDateTime())
};
}
body.replace(URL_REGEX, URL_HTML);
generateTimestamp(timestamp);
generateTimestamp(QDateTime::currentDateTime());
generateBody(body);
if (withSender) {
generateBody(displayName, body);
setupAvatarLayout(displayName);
mainLayout_->addLayout(headerLayout_);
setupSimpleLayout();
AvatarProvider::resolve(userid, this);
} else {
generateBody(body);
setupSimpleLayout();
}
mainLayout_->addWidget(body_);
}

View File

@ -289,7 +289,10 @@ TimelineView::parseMessageEvent(const QJsonObject &event, TimelineDirection dire
eventIds_[emote.eventId()] = true;
// TODO Check if it's a message waiting for validation
if (isPendingMessage(emote, local_user_)) {
removePendingMessage(emote);
return nullptr;
}
auto with_sender = isSenderRendered(emote.sender(), direction);
@ -452,55 +455,19 @@ TimelineView::updatePendingMessage(int txn_id, QString event_id)
}
}
bool
TimelineView::isPendingMessage(const events::MessageEvent<msgs::Text> &e,
const QString &local_userid)
{
if (e.sender() != local_userid)
return false;
for (const auto &msg : pending_msgs_) {
if (msg.event_id == e.eventId() || msg.body == e.content().body())
return true;
}
return false;
}
void
TimelineView::removePendingMessage(const events::MessageEvent<msgs::Text> &e)
{
for (auto it = pending_msgs_.begin(); it != pending_msgs_.end(); it++) {
int index = std::distance(pending_msgs_.begin(), it);
if (it->event_id == e.eventId() || it->body == e.content().body()) {
pending_msgs_.removeAt(index);
break;
}
}
}
void
TimelineView::addUserTextMessage(const QString &body, int txn_id)
TimelineView::addUserMessage(matrix::events::MessageEventType ty, const QString &body, int txn_id)
{
QSettings settings;
auto user_id = settings.value("auth/user_id").toString();
auto user_id = settings.value("auth/user_id").toString();
auto with_sender = lastSender_ != user_id;
TimelineItem *view_item;
if (with_sender)
view_item = new TimelineItem(user_id, body, scroll_widget_);
else
view_item = new TimelineItem(body, scroll_widget_);
TimelineItem *view_item = new TimelineItem(ty, user_id, body, with_sender, scroll_widget_);
scroll_layout_->addWidget(view_item);
lastSender_ = user_id;
PendingMessage message(txn_id, body, "", view_item);
pending_msgs_.push_back(message);
}

View File

@ -32,10 +32,8 @@ TimelineViewManager::TimelineViewManager(QSharedPointer<MatrixClient> client, QW
{
setStyleSheet("QWidget { background: #f8fbfe; color: #e8e8e8; border: none;}");
connect(client_.data(),
SIGNAL(messageSent(const QString &, const QString &, int)),
this,
SLOT(messageSent(const QString &, const QString &, int)));
connect(
client_.data(), &MatrixClient::messageSent, this, &TimelineViewManager::messageSent);
}
TimelineViewManager::~TimelineViewManager()
@ -59,8 +57,19 @@ TimelineViewManager::sendTextMessage(const QString &msg)
auto room_id = active_room_;
auto view = views_[room_id];
view->addUserTextMessage(msg, client_->transactionId());
client_->sendTextMessage(room_id, msg);
view->addUserMessage(matrix::events::MessageEventType::Text, msg, client_->transactionId());
client_->sendRoomMessage(matrix::events::MessageEventType::Text, room_id, msg);
}
void
TimelineViewManager::sendEmoteMessage(const QString &msg)
{
auto room_id = active_room_;
auto view = views_[room_id];
view->addUserMessage(
matrix::events::MessageEventType::Emote, msg, client_->transactionId());
client_->sendRoomMessage(matrix::events::MessageEventType::Emote, room_id, msg);
}
void