diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-05-08 13:30:04 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2018-05-08 13:30:10 +0200 |
commit | 4f6c843523f45708d8bbed25b3677f69c4208a38 (patch) | |
tree | 402299331c9e28bc9021f596e06b5d68df8aa5b1 /src | |
parent | 4a1e4c9883cdf70f0e9d3f8961a5c03e3675bb3e (diff) |
Merge messages from same user sent within 1 minute
Diffstat (limited to 'src')
-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; } |