Improve reply popup after thread update (#4923)

Co-authored-by: nerix <nero.9@hotmail.de>
Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
iProdigy
2023-11-05 08:25:26 -08:00
committed by GitHub
parent 9dd83b040b
commit 5209e47df1
12 changed files with 177 additions and 59 deletions
+1 -1
View File
@@ -189,7 +189,7 @@ ReplyThreadPopup::ReplyThreadPopup(bool closeAutomatically, QWidget *parent,
void ReplyThreadPopup::setThread(std::shared_ptr<MessageThread> thread)
{
this->thread_ = std::move(thread);
this->ui_.replyInput->setReply(this->thread_);
this->ui_.replyInput->setReply(this->thread_->root());
this->addMessagesFromThread();
this->updateInputUI();
+8 -6
View File
@@ -2331,6 +2331,10 @@ void ChannelView::addMessageContextMenuItems(QMenu *menu,
if (messagePtr->replyThread != nullptr)
{
menu->addAction("Reply to &original thread", [this, &messagePtr] {
this->setInputReply(messagePtr->replyThread->root());
});
menu->addAction("View &thread", [this, &messagePtr] {
this->showReplyThreadPopup(messagePtr);
});
@@ -2871,19 +2875,17 @@ void ChannelView::setInputReply(const MessagePtr &message)
return;
}
auto thread = message->replyThread;
if (!thread)
if (!message->replyThread)
{
// Message did not already have a thread attached, try to find or create one
if (auto *tc =
dynamic_cast<TwitchChannel *>(this->underlyingChannel_.get()))
{
thread = tc->getOrCreateThread(message);
tc->getOrCreateThread(message);
}
else if (auto *tc = dynamic_cast<TwitchChannel *>(this->channel_.get()))
{
thread = tc->getOrCreateThread(message);
tc->getOrCreateThread(message);
}
else
{
@@ -2894,7 +2896,7 @@ void ChannelView::setInputReply(const MessagePtr &message)
}
}
this->split_->setInputReply(thread);
this->split_->setInputReply(message);
}
void ChannelView::showReplyThreadPopup(const MessagePtr &message)
+1 -1
View File
@@ -1542,7 +1542,7 @@ void Split::drag()
stopDraggingSplit();
}
void Split::setInputReply(const std::shared_ptr<MessageThread> &reply)
void Split::setInputReply(const MessagePtr &reply)
{
this->input_->setReply(reply);
}
+1 -2
View File
@@ -15,7 +15,6 @@
namespace chatterino {
class ChannelView;
class MessageThread;
class SplitHeader;
class SplitInput;
class SplitContainer;
@@ -75,7 +74,7 @@ public:
void setContainer(SplitContainer *container);
void setInputReply(const std::shared_ptr<MessageThread> &reply);
void setInputReply(const MessagePtr &reply);
static pajlada::Signals::Signal<Qt::KeyboardModifiers>
modifierStatusChanged;
+21 -7
View File
@@ -359,7 +359,7 @@ QString SplitInput::handleSendMessage(std::vector<QString> &arguments)
if (this->enableInlineReplying_)
{
// Remove @username prefix that is inserted when doing inline replies
message.remove(0, this->replyThread_->root()->displayName.length() +
message.remove(0, this->replyThread_->displayName.length() +
1); // remove "@username"
if (!message.isEmpty() && message.at(0) == ' ')
@@ -373,7 +373,7 @@ QString SplitInput::handleSendMessage(std::vector<QString> &arguments)
getApp()->commands->execCommand(message, c, false);
// Reply within TwitchChannel
tc->sendReply(sendMessage, this->replyThread_->rootId());
tc->sendReply(sendMessage, this->replyThread_->id);
this->postMessageSend(message, arguments);
return "";
@@ -992,7 +992,7 @@ void SplitInput::editTextChanged()
// We need to verify that
// 1. the @username prefix exists and
// 2. if a character exists after the @username, it is a space
QString replyPrefix = "@" + this->replyThread_->root()->displayName;
QString replyPrefix = "@" + this->replyThread_->displayName;
if (!text.startsWith(replyPrefix) ||
(text.length() > replyPrefix.length() &&
text.at(replyPrefix.length()) != ' '))
@@ -1065,15 +1065,29 @@ void SplitInput::giveFocus(Qt::FocusReason reason)
this->ui_.textEdit->setFocus(reason);
}
void SplitInput::setReply(std::shared_ptr<MessageThread> reply,
bool showReplyingLabel)
void SplitInput::setReply(MessagePtr reply, bool showReplyingLabel)
{
auto oldParent = this->replyThread_;
if (this->enableInlineReplying_ && oldParent)
{
// Remove old reply prefix
auto replyPrefix = "@" + oldParent->displayName;
auto plainText = this->ui_.textEdit->toPlainText().trimmed();
if (plainText.startsWith(replyPrefix))
{
plainText.remove(0, replyPrefix.length());
}
this->ui_.textEdit->setPlainText(plainText.trimmed());
this->ui_.textEdit->moveCursor(QTextCursor::EndOfBlock);
this->ui_.textEdit->resetCompletion();
}
this->replyThread_ = std::move(reply);
if (this->enableInlineReplying_)
{
// Only enable reply label if inline replying
auto replyPrefix = "@" + this->replyThread_->root()->displayName;
auto replyPrefix = "@" + this->replyThread_->displayName;
auto plainText = this->ui_.textEdit->toPlainText().trimmed();
if (!plainText.startsWith(replyPrefix))
{
@@ -1086,7 +1100,7 @@ void SplitInput::setReply(std::shared_ptr<MessageThread> reply,
this->ui_.textEdit->resetCompletion();
}
this->ui_.replyLabel->setText("Replying to @" +
this->replyThread_->root()->displayName);
this->replyThread_->displayName);
}
}
+3 -4
View File
@@ -1,5 +1,6 @@
#pragma once
#include "messages/Message.hpp"
#include "widgets/BaseWidget.hpp"
#include <QHBoxLayout>
@@ -19,7 +20,6 @@ class Split;
class EmotePopup;
class InputCompletionPopup;
class EffectLabel;
class MessageThread;
class ResizingTextEdit;
class ChannelView;
enum class CompletionKind;
@@ -40,8 +40,7 @@ public:
QString getInputText() const;
void insertText(const QString &text);
void setReply(std::shared_ptr<MessageThread> reply,
bool showInlineReplying = true);
void setReply(MessagePtr reply, bool showInlineReplying = true);
void setPlaceholderText(const QString &text);
/**
@@ -135,7 +134,7 @@ protected:
EffectLabel *cancelReplyButton;
} ui_{};
std::shared_ptr<MessageThread> replyThread_ = nullptr;
MessagePtr replyThread_ = nullptr;
bool enableInlineReplying_;
pajlada::Signals::SignalHolder managedConnections_;