Add basic support for replies (#292)

remotes/origin/HEAD
Konstantinos Sideris 6 years ago
parent d56446ce97
commit 5b5d35fd1f
  1. 2
      include/ChatPage.h
  2. 1
      include/TextInputWidget.h
  3. 3
      include/timeline/TimelineItem.h
  4. 1
      src/ChatPage.cc
  5. 11
      src/TextInputWidget.cc
  6. 22
      src/timeline/TimelineItem.cc
  7. 2
      src/timeline/TimelineView.cc

@ -76,6 +76,8 @@ signals:
void connectionLost();
void connectionRestored();
void messageReply(const QString &username, const QString &msg);
void notificationsRetrieved(const mtx::responses::Notifications &);
void uploadFailed(const QString &msg);

@ -144,6 +144,7 @@ public slots:
void openFileSelection();
void hideUploadSpinner();
void focusLineEdit() { input_->setFocus(); }
void addReply(const QString &username, const QString &msg);
private slots:
void addSelectedEmoji(const QString &emoji);

@ -212,6 +212,8 @@ private:
void init();
//! Add a context menu option to save the image of the timeline item.
void addSaveImageAction(ImageItem *image);
//! Add the reply action in the context menu for widgets that support it.
void addReplyAction();
template<class Widget>
void setupLocalWidgetLayout(Widget *widget, const QString &userid, bool withSender);
@ -240,6 +242,7 @@ private:
QAction *showReadReceipts_;
QAction *markAsRead_;
QAction *redactMsg_;
QAction *replyMsg_;
QHBoxLayout *topLayout_ = nullptr;
QHBoxLayout *messageLayout_ = nullptr;

@ -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;
}

@ -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);
}

@ -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);
@ -610,6 +614,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()
{

@ -143,7 +143,7 @@ TimelineView::fetchHistory()
isPaginationInProgress_ = true;
getMessages();
paginationTimer_->start(5000);
paginationTimer_->start(2000);
return;
}

Loading…
Cancel
Save