Skip to content

Commit

Permalink
fix(ui): add date message before info messages
Browse files Browse the repository at this point in the history
Fixes qTox#4388.
Separated date message in its own function.
Also added date message before info messages like it is already done with normal chat messages.
  • Loading branch information
ezavod committed Jun 3, 2017
1 parent 331a8f1 commit ed45359
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/widget/form/genericchatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,7 @@ ChatMessage::Ptr GenericChatForm::createMessage(const ToxPk& author, const QStri
bool isSelf = author == core->getSelfId().getPublicKey();
QString authorStr = isSelf ? core->getUsername() : resolveToxPk(author);
if (getLatestDate() != QDate::currentDate()) {
const Settings& s = Settings::getInstance();
QString dateText = QDate::currentDate().toString(s.getDateFormat());
addSystemInfoMessage(dateText, ChatMessage::INFO, QDateTime());
addSystemDateMessage();
}

ChatMessage::Ptr msg;
Expand Down Expand Up @@ -553,10 +551,23 @@ void GenericChatForm::onChatMessageFontChanged(const QFont& font)
void GenericChatForm::addSystemInfoMessage(const QString& message, ChatMessage::SystemMessageType type,
const QDateTime& datetime)
{
if (getLatestDate() != QDate::currentDate()) {
addSystemDateMessage();
}

previousId = ToxPk();
insertChatMessage(ChatMessage::createChatInfoMessage(message, type, datetime));
}

void GenericChatForm::addSystemDateMessage()
{
const Settings& s = Settings::getInstance();
QString dateText = QDate::currentDate().toString(s.getDateFormat());

previousId = ToxPk();
insertChatMessage(ChatMessage::createChatInfoMessage(dateText, ChatMessage::INFO, QDateTime()));
}

void GenericChatForm::clearChatArea()
{
clearChatArea(true);
Expand Down
1 change: 1 addition & 0 deletions src/widget/form/genericchatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ protected slots:

private:
void retranslateUi();
void addSystemDateMessage();

protected:
ChatMessage::Ptr createMessage(const ToxPk& author, const QString& message,
Expand Down

0 comments on commit ed45359

Please sign in to comment.