mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(chatlog): Store ChatLine::Ptr in messages instead of ChatMessage
* This simplifies future refactoring since the rest of ChatLog expects to be working with the base class
This commit is contained in:
parent
b7a88cde6e
commit
a9f7c0ca7e
|
@ -53,8 +53,8 @@ T clamp(T x, T min, T max)
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatMessage::Ptr getChatMessageForIdx(ChatLogIdx idx,
|
ChatLine::Ptr getChatMessageForIdx(ChatLogIdx idx,
|
||||||
const std::map<ChatLogIdx, ChatMessage::Ptr>& messages)
|
const std::map<ChatLogIdx, ChatLine::Ptr>& messages)
|
||||||
{
|
{
|
||||||
auto existingMessageIt = messages.find(idx);
|
auto existingMessageIt = messages.find(idx);
|
||||||
|
|
||||||
|
@ -104,8 +104,14 @@ ChatMessage::Ptr createMessage(const QString& displayName, bool isSelf, bool col
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderMessageRaw(const QString& displayName, bool isSelf, bool colorizeNames,
|
void renderMessageRaw(const QString& displayName, bool isSelf, bool colorizeNames,
|
||||||
const ChatLogMessage& chatLogMessage, ChatMessage::Ptr& chatMessage)
|
const ChatLogMessage& chatLogMessage, ChatLine::Ptr& chatLine)
|
||||||
{
|
{
|
||||||
|
// HACK: This is kind of gross, but there's not an easy way to fit this into
|
||||||
|
// the existing architecture. This shouldn't ever fail since we should only
|
||||||
|
// correlate ChatMessages created here, however a logic bug could turn into
|
||||||
|
// a crash due to this dangerous cast. The alternative would be to make
|
||||||
|
// ChatLine a QObject which I didn't think was worth it.
|
||||||
|
auto chatMessage = static_cast<ChatMessage*>(chatLine.get());
|
||||||
|
|
||||||
if (chatMessage) {
|
if (chatMessage) {
|
||||||
if (chatLogMessage.state == MessageState::complete) {
|
if (chatLogMessage.state == MessageState::complete) {
|
||||||
|
@ -114,7 +120,7 @@ void renderMessageRaw(const QString& displayName, bool isSelf, bool colorizeName
|
||||||
chatMessage->markAsBroken();
|
chatMessage->markAsBroken();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
chatMessage = createMessage(displayName, isSelf, colorizeNames, chatLogMessage);
|
chatLine = createMessage(displayName, isSelf, colorizeNames, chatLogMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,10 +245,13 @@ ChatLog::ChatLog(IChatLog& chatLog, const Core& core, QWidget* parent)
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
Translator::registerHandler(std::bind(&ChatLog::retranslateUi, this), this);
|
Translator::registerHandler(std::bind(&ChatLog::retranslateUi, this), this);
|
||||||
|
|
||||||
|
connect(&chatLog, &IChatLog::itemUpdated, this, &ChatLog::renderMessage);
|
||||||
|
|
||||||
auto chatLogIdxRange = chatLog.getNextIdx() - chatLog.getFirstIdx();
|
auto chatLogIdxRange = chatLog.getNextIdx() - chatLog.getFirstIdx();
|
||||||
auto firstChatLogIdx = (chatLogIdxRange < 100) ? chatLog.getFirstIdx() : chatLog.getNextIdx() - 100;
|
auto firstChatLogIdx = (chatLogIdxRange < 100) ? chatLog.getFirstIdx() : chatLog.getNextIdx() - 100;
|
||||||
|
|
||||||
renderMessages(firstChatLogIdx, chatLog.getNextIdx());
|
renderMessages(firstChatLogIdx, chatLog.getNextIdx());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatLog::~ChatLog()
|
ChatLog::~ChatLog()
|
||||||
|
@ -1278,7 +1287,7 @@ void ChatLog::setTypingNotification()
|
||||||
updateTypingNotification();
|
updateTypingNotification();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatLog::renderItem(const ChatLogItem& item, bool hideName, bool colorizeNames, ChatMessage::Ptr& chatMessage)
|
void ChatLog::renderItem(const ChatLogItem& item, bool hideName, bool colorizeNames, ChatLine::Ptr& chatMessage)
|
||||||
{
|
{
|
||||||
const auto& sender = item.getSender();
|
const auto& sender = item.getSender();
|
||||||
|
|
||||||
|
@ -1310,12 +1319,12 @@ void ChatLog::renderItem(const ChatLogItem& item, bool hideName, bool colorizeNa
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hideName) {
|
if (hideName) {
|
||||||
chatMessage->hideSender();
|
chatMessage->getContent(0)->hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatLog::renderFile(QString displayName, ToxFile file, bool isSelf, QDateTime timestamp,
|
void ChatLog::renderFile(QString displayName, ToxFile file, bool isSelf, QDateTime timestamp,
|
||||||
ChatMessage::Ptr& chatMessage)
|
ChatLine::Ptr& chatMessage)
|
||||||
{
|
{
|
||||||
if (!chatMessage) {
|
if (!chatMessage) {
|
||||||
CoreFile* coreFile = core.getCoreFile();
|
CoreFile* coreFile = core.getCoreFile();
|
||||||
|
|
|
@ -138,8 +138,8 @@ private:
|
||||||
void moveMultiSelectionDown(int offset);
|
void moveMultiSelectionDown(int offset);
|
||||||
void setTypingNotification();
|
void setTypingNotification();
|
||||||
|
|
||||||
void renderItem(const ChatLogItem &item, bool hideName, bool colorizeNames, ChatMessage::Ptr &chatMessage);
|
void renderItem(const ChatLogItem &item, bool hideName, bool colorizeNames, ChatLine::Ptr &chatMessage);
|
||||||
void renderFile(QString displayName, ToxFile file, bool isSelf, QDateTime timestamp, ChatMessage::Ptr &chatMessage);
|
void renderFile(QString displayName, ToxFile file, bool isSelf, QDateTime timestamp, ChatLine::Ptr &chatMessage);
|
||||||
bool needsToHideName(ChatLogIdx idx) const;
|
bool needsToHideName(ChatLogIdx idx) const;
|
||||||
void disableSearchText();
|
void disableSearchText();
|
||||||
private:
|
private:
|
||||||
|
@ -193,7 +193,7 @@ private:
|
||||||
qreal lineSpacing = 5.0f;
|
qreal lineSpacing = 5.0f;
|
||||||
|
|
||||||
IChatLog& chatLog;
|
IChatLog& chatLog;
|
||||||
std::map<ChatLogIdx, ChatMessage::Ptr> messages;
|
std::map<ChatLogIdx, ChatLine::Ptr> messages;
|
||||||
bool colorizeNames = false;
|
bool colorizeNames = false;
|
||||||
SearchPos searchPos;
|
SearchPos searchPos;
|
||||||
const Core& core;
|
const Core& core;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user