mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 03:00:46 +03:00
Add basic support for replies (#292)
This commit is contained in:
parent
d56446ce97
commit
5b5d35fd1f
7 changed files with 41 additions and 1 deletions
|
@ -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…
Reference in a new issue