From 28979f577165b0ce2a8e67b8eea870218bdd0b21 Mon Sep 17 00:00:00 2001 From: "anthony.bilinski" Date: Tue, 5 Sep 2017 11:29:46 -0700 Subject: [PATCH] fix(chatform): Hide author on history like on new messages Fix #4619 --- src/widget/form/chatform.cpp | 2 +- src/widget/form/genericchatform.cpp | 15 +++++++++------ src/widget/form/genericchatform.h | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index 79b2f8f42..2f7d182bf 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -743,7 +743,7 @@ void ChatForm::loadHistory(const QDateTime& since, bool processUndelivered) ChatMessage::MessageType type = isAction ? ChatMessage::ACTION : ChatMessage::NORMAL; QDateTime dateTime = needSending ? QDateTime() : msgDateTime; auto msg = ChatMessage::createChatMessage(authorStr, messageText, type, isSelf, dateTime); - if (!isAction && needsToHideName(authorPk)) { + if (!isAction && needsToHideName(authorPk, msgDateTime)) { msg->hideSender(); } diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index b6b668052..9fae3fc7d 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -378,11 +378,12 @@ void GenericChatForm::onChatContextMenuRequested(QPoint pos) /** * @brief Show, is it needed to hide message author name or not * @param messageAuthor Author of the sent message + * @oaran messageTime DateTime of the sent message * @return True if it's needed to hide name, false otherwise */ -bool GenericChatForm::needsToHideName(const ToxPk& messageAuthor) const +bool GenericChatForm::needsToHideName(const ToxPk& messageAuthor, const QDateTime& messageTime) const { - qint64 messagesTimeDiff = prevMsgDateTime.secsTo(QDateTime::currentDateTime()); + qint64 messagesTimeDiff = prevMsgDateTime.secsTo(messageTime); return messageAuthor == previousId && messagesTimeDiff < chatWidget->repNameAfter; } @@ -411,12 +412,13 @@ ChatMessage::Ptr GenericChatForm::createMessage(const ToxPk& author, const QStri previousId = ToxPk{}; } else { msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::NORMAL, isSelf); - if (needsToHideName(author)) { + const QDateTime newMsgDateTime = QDateTime::currentDateTime(); + if (needsToHideName(author, newMsgDateTime)) { msg->hideSender(); } previousId = author; - prevMsgDateTime = QDateTime::currentDateTime(); + prevMsgDateTime = newMsgDateTime; } if (isSent) { @@ -459,13 +461,14 @@ void GenericChatForm::addAlertMessage(const ToxPk& author, const QString& msg, c QString authorStr = resolveToxPk(author); bool isSelf = author == Core::getInstance()->getSelfId().getPublicKey(); auto chatMsg = ChatMessage::createChatMessage(authorStr, msg, ChatMessage::ALERT, isSelf, dt); - if (needsToHideName(author)) { + const QDateTime newMsgDateTime = QDateTime::currentDateTime(); + if (needsToHideName(author, newMsgDateTime)) { chatMsg->hideSender(); } insertChatMessage(chatMsg); previousId = author; - prevMsgDateTime = QDateTime::currentDateTime(); + prevMsgDateTime = newMsgDateTime; } void GenericChatForm::onEmoteButtonClicked() diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index 785666b1c..f05acf773 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -108,7 +108,7 @@ protected: const QDateTime& datetime, bool isAction, bool isSent); ChatMessage::Ptr createSelfMessage(const QString& message, const QDateTime& datetime, bool isAction, bool isSent); - bool needsToHideName(const ToxPk& author) const; + bool needsToHideName(const ToxPk& messageAuthor, const QDateTime& messageTime) const; void showNetcam(); void hideNetcam(); virtual GenericNetCamView* createNetcam() = 0;