From 4f6c843523f45708d8bbed25b3677f69c4208a38 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 8 May 2018 13:30:04 +0200 Subject: Merge messages from same user sent within 1 minute --- src/MessageBoard.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/MessageBoard.cpp b/src/MessageBoard.cpp index c56419d..49d84e8 100644 --- a/src/MessageBoard.cpp +++ b/src/MessageBoard.cpp @@ -36,6 +36,9 @@ namespace dchat const float AVATAR_PADDING_SIDE = 30.0f; const double SCROLL_MAX_SPEED = 20.0; + // Merge messages from same user that are sent within one minute + const int MERGE_TEXT_TIMESTAMP_DIFF_SEC = 60; + MessageBoard::MessageBoard(const sf::Vector2u &size) : selectingText(false), leftMouseButtonPressed(false), @@ -98,9 +101,15 @@ namespace dchat if(i > 0) { Message *prevMessage = messages[i - 1]; - mergeTextWithPrev = prevMessage->user == message->user && (message->timestampSeconds == 0 || message->timestampSeconds - prevMessage->timestampSeconds); + mergeTextWithPrev = prevMessage->user == message->user && (message->timestampSeconds == 0 || message->timestampSeconds - prevMessage->timestampSeconds <= MERGE_TEXT_TIMESTAMP_DIFF_SEC); + } + + bool mergeTextWithNext = false; + if(i < numMessages - 1) + { + Message *nextMessage = messages[i + 1]; + mergeTextWithNext = nextMessage->user == message->user && (nextMessage->timestampSeconds == 0 || nextMessage->timestampSeconds - message->timestampSeconds <= MERGE_TEXT_TIMESTAMP_DIFF_SEC); } - mergeTextWithPrev = false; if(!mergeTextWithPrev) { @@ -168,7 +177,7 @@ namespace dchat message->text.setLineSpacing(LINE_SPACING); message->text.draw(window, cache); position.y += message->text.getHeight(); - if(!mergeTextWithPrev) + if(!mergeTextWithNext) { position.y += (MESSAGE_PADDING_BOTTOM * Settings::getScaling()); @@ -181,8 +190,6 @@ namespace dchat position.y += LINE_HEIGHT; } - else - position.y += LINE_SPACING; } totalHeight = (position.y - scroll) - startHeight; } -- cgit v1.2.3