diff options
author | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2018-06-30 15:13:15 +0300 |
---|---|---|
committer | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2018-06-30 15:13:15 +0300 |
commit | 5b5d35fd1f33555f6dacecacaf53a18517218b79 (patch) | |
tree | a0c9dbba27ff5826c906fd6bbc5b6587c2d149ea /src | |
parent | Allow arbitrary resizing of the main window & restore sidebar's size (diff) | |
download | nheko-5b5d35fd1f33555f6dacecacaf53a18517218b79.tar.xz |
Add basic support for replies (#292)
Diffstat (limited to 'src')
-rw-r--r-- | src/ChatPage.cc | 1 | ||||
-rw-r--r-- | src/TextInputWidget.cc | 11 | ||||
-rw-r--r-- | src/timeline/TimelineItem.cc | 22 | ||||
-rw-r--r-- | src/timeline/TimelineView.cc | 2 |
4 files changed, 35 insertions, 1 deletions
diff --git a/src/ChatPage.cc b/src/ChatPage.cc index 3d026ab3..df1ab172 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc @@ -605,6 +605,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent) }); connect(this, &ChatPage::dropToLoginPageCb, this, &ChatPage::dropToLoginPage); + connect(this, &ChatPage::messageReply, text_input_, &TextInputWidget::addReply); instance_ = this; } diff --git a/src/TextInputWidget.cc b/src/TextInputWidget.cc index acb33fa7..7ee7fa16 100644 --- a/src/TextInputWidget.cc +++ b/src/TextInputWidget.cc @@ -614,3 +614,14 @@ TextInputWidget::paintEvent(QPaintEvent *) p.setPen(QPen(borderColor())); p.drawLine(QPointF(0, 0), QPointF(width(), 0)); } + +void +TextInputWidget::addReply(const QString &username, const QString &msg) +{ + input_->setText(QString("> %1: %2\n\n").arg(username).arg(msg)); + input_->setFocus(); + + auto cursor = input_->textCursor(); + cursor.movePosition(QTextCursor::End); + input_->setTextCursor(cursor); +} diff --git a/src/timeline/TimelineItem.cc b/src/timeline/TimelineItem.cc index c104801d..bbe3ff34 100644 --- a/src/timeline/TimelineItem.cc +++ b/src/timeline/TimelineItem.cc @@ -125,6 +125,7 @@ TimelineItem::TimelineItem(mtx::events::MessageType ty, , room_id_{room_id} { init(); + addReplyAction(); auto displayName = Cache::displayName(room_id_, userid); auto timestamp = QDateTime::currentDateTime(); @@ -290,6 +291,7 @@ TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Notice , room_id_{room_id} { init(); + addReplyAction(); event_id_ = QString::fromStdString(event.event_id); const auto sender = QString::fromStdString(event.sender); @@ -341,6 +343,7 @@ TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Emote> , room_id_{room_id} { init(); + addReplyAction(); event_id_ = QString::fromStdString(event.event_id); const auto sender = QString::fromStdString(event.sender); @@ -388,6 +391,7 @@ TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Text> , room_id_{room_id} { init(); + addReplyAction(); event_id_ = QString::fromStdString(event.event_id); const auto sender = QString::fromStdString(event.sender); @@ -611,6 +615,24 @@ TimelineItem::addSaveImageAction(ImageItem *image) } void +TimelineItem::addReplyAction() +{ + if (contextMenu_) { + auto replyAction = new QAction("Reply", this); + contextMenu_->addAction(replyAction); + + connect(replyAction, &QAction::triggered, this, [this]() { + if (!body_) + return; + + emit ChatPage::instance()->messageReply( + Cache::displayName(room_id_, descriptionMsg_.userid), + body_->toPlainText()); + }); + } +} + +void TimelineItem::addAvatar() { if (userAvatar_) diff --git a/src/timeline/TimelineView.cc b/src/timeline/TimelineView.cc index 98ff0983..47e92a3b 100644 --- a/src/timeline/TimelineView.cc +++ b/src/timeline/TimelineView.cc @@ -143,7 +143,7 @@ TimelineView::fetchHistory() isPaginationInProgress_ = true; getMessages(); - paginationTimer_->start(5000); + paginationTimer_->start(2000); return; } |