diff options
-rw-r--r-- | src/MessageBoard.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
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; } |