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/Channel.cpp | 1 + src/MessageBoard.cpp | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Channel.cpp b/src/Channel.cpp index 06c0b79..c1e63ea 100644 --- a/src/Channel.cpp +++ b/src/Channel.cpp @@ -22,6 +22,7 @@ namespace dchat addLocalMessage(u8"[emoji](https://discordemoji.com/assets/emoji/PepeDab.gif) deaf [emoji](https://discordemoji.com/assets/emoji/COGGERS.gif)", &systemUser, 0, odhtdb::Hash()); addLocalMessage(u8"[emoji](https://discordemoji.com/assets/emoji/PepeDab.gif)[emoji](https://discordemoji.com/assets/emoji/COGGERS.gif)", &systemUser, 0, odhtdb::Hash()); addLocalMessage(u8"pepedab https://discordemoji.com/assets/emoji/PepeDab.gif coggers https://discordemoji.com/assets/emoji/COGGERS.gif check out this url http://www.grandtournation.com/6808/start-date-of-the-grand-tour-season-3-confirmed-mark-your-calendars/ owo", &systemUser, 0, odhtdb::Hash()); + addLocalMessage(u8"ht clic", &systemUser, 0, odhtdb::Hash()); if(database) database->seed(databaseNodeInfo); 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