aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vscode/launch.json27
-rw-r--r--.vscode/settings.json9
-rw-r--r--include/MessageBoard.hpp2
-rw-r--r--include/StringView.hpp2
-rw-r--r--src/Channel.cpp1
-rw-r--r--src/MessageBoard.cpp13
6 files changed, 52 insertions, 2 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 0000000..d49b13b
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,27 @@
+{
+ // Use IntelliSense to learn about possible attributes.
+ // Hover to view descriptions of existing attributes.
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "name": "(gdb) Launch",
+ "type": "cppdbg",
+ "request": "launch",
+ "program": "${workspaceFolder}/sibs-build/debug/dchat",
+ "args": [],
+ "stopAtEntry": false,
+ "cwd": "${workspaceFolder}",
+ "environment": [],
+ "externalConsole": true,
+ "MIMode": "gdb",
+ "setupCommands": [
+ {
+ "description": "Enable pretty-printing for gdb",
+ "text": "-enable-pretty-printing",
+ "ignoreFailures": true
+ }
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..7a10503
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,9 @@
+{
+ "files.associations": {
+ "*.ipp": "cpp",
+ "hash_map": "cpp",
+ "hash_set": "cpp",
+ "*.tcc": "cpp",
+ "string_view": "cpp"
+ }
+} \ No newline at end of file
diff --git a/include/MessageBoard.hpp b/include/MessageBoard.hpp
index 9025e48..a947c1b 100644
--- a/include/MessageBoard.hpp
+++ b/include/MessageBoard.hpp
@@ -25,6 +25,8 @@ namespace dchat
void processEvent(const sf::Event &event);
void draw(sf::RenderWindow &window, Cache &cache);
private:
+ usize findPositionToInsertMessageByTimestamp(Message *message);
+
void updateStaticContentTexture(const sf::Vector2u &newSize);
void addMessage(Message *message, const odhtdb::Hash &id);
void deleteMessage(const odhtdb::Hash &id, const odhtdb::Signature::PublicKey &requestedByUser);
diff --git a/include/StringView.hpp b/include/StringView.hpp
index c4e7ce3..d320a85 100644
--- a/include/StringView.hpp
+++ b/include/StringView.hpp
@@ -80,7 +80,7 @@ namespace dchat
for(usize i = offset; i < size - (substr.size - 1); ++i)
{
- if(memcmp(data + i, substr.data, substr.size) == 0)
+ if(memcmp(data + i, substr.data, substr.size * sizeof(CharType)) == 0)
return i;
}
return -1;
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<mutex> lock(messageProcessMutex);
- messages.push_back(message);
+ messages.insert(messages.begin() + findPositionToInsertMessageByTimestamp(message), message);
if(!id.isEmpty())
messageIdMap[id] = message;
dirty = true;