Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(chatform): Hide author on history like on new messages
Browse files Browse the repository at this point in the history
Fix #4619
  • Loading branch information
anthonybilinski committed Sep 5, 2017
1 parent 89198f5 commit 28979f5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/widget/form/chatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
15 changes: 9 additions & 6 deletions src/widget/form/genericchatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/widget/form/genericchatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected slots:
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;
Expand Down

0 comments on commit 28979f5

Please sign in to comment.