1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge pull request #4620

anthony.bilinski (1):
      fix(chatform): Hide author on history like on new messages
This commit is contained in:
Diadlo 2017-09-11 08:42:42 +03:00
commit c49959711e
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
3 changed files with 11 additions and 8 deletions

View File

@ -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();
}

View File

@ -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()

View File

@ -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;