From e4cc9c03bf2578cbe2b8c9e909e9803ff856dd9d Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 17 May 2018 03:34:41 +0200 Subject: Fix url parsing in text, sort messages by timestamp --- src/MessageBoard.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/MessageBoard.cpp') diff --git a/src/MessageBoard.cpp b/src/MessageBoard.cpp index b1f8b0b..bc53ae3 100644 --- a/src/MessageBoard.cpp +++ b/src/MessageBoard.cpp @@ -59,6 +59,17 @@ namespace dchat } } + // TODO: Optimize this with binary search + usize MessageBoard::findPositionToInsertMessageByTimestamp(Message *message) + { + for(usize i = 0; i < messages.size(); ++i) + { + if(message->timestampSeconds < messages[i]->timestampSeconds) + return i; + } + return messages.size(); + } + void MessageBoard::updateStaticContentTexture(const sf::Vector2u &newSize) { //if(!staticContentTexture.create(newSize.x, newSize.y)) @@ -69,7 +80,7 @@ namespace dchat void MessageBoard::addMessage(Message *message, const odhtdb::Hash &id) { lock_guard lock(messageProcessMutex); - messages.push_back(message); + messages.insert(messages.begin() + findPositionToInsertMessageByTimestamp(message), message); if(!id.isEmpty()) messageIdMap[id] = message; dirty = true; -- cgit v1.2.3