aboutsummaryrefslogtreecommitdiff
path: root/src/Channel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Channel.cpp')
-rw-r--r--src/Channel.cpp42
1 files changed, 35 insertions, 7 deletions
diff --git a/src/Channel.cpp b/src/Channel.cpp
index e433aee..678dddd 100644
--- a/src/Channel.cpp
+++ b/src/Channel.cpp
@@ -15,15 +15,15 @@ namespace dchat
database(_database),
databaseNodeInfo(_databaseNodeInfo),
name(_name),
- messageBoard(sf::Vector2u(1.0f, 1.0f)),
+ messageBoard(this),
localUser(_localUser ? _localUser : new OfflineUser("You"))
{
addUserLocally(localUser);
localUser->avatarUrl = "https://discordemoji.com/assets/emoji/HanekawaSmug.gif";
- addLocalMessage(u8"[emoji](https://discordemoji.com/assets/emoji/PepeDab.gif) deaf [emoji](https://discordemoji.com/assets/emoji/COGGERS.gif)", &systemUser);
- addLocalMessage(u8"[emoji](https://discordemoji.com/assets/emoji/PepeDab.gif)[emoji](https://discordemoji.com/assets/emoji/COGGERS.gif)", &systemUser);
- 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);
+ 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());
if(database)
database->seed(databaseNodeInfo);
@@ -80,12 +80,17 @@ namespace dchat
void Channel::addLocalMessage(const std::string &msg, User *owner, u64 timestampSeconds)
{
+ addLocalMessage(msg, owner, timestampSeconds, odhtdb::Hash());
+ }
+
+ void Channel::addLocalMessage(const std::string &msg, User *owner, u64 timestampSeconds, const odhtdb::Hash &id)
+ {
assert(owner);
if(timestampSeconds == 0)
{
timestampSeconds = time(NULL);
}
- messageBoard.addMessage(new Message(owner, msg, timestampSeconds));
+ messageBoard.addMessage(new Message(owner, msg, timestampSeconds), id);
}
void Channel::addMessage(const std::string &msg)
@@ -96,14 +101,37 @@ namespace dchat
assert(localOnlineUser->databaseUser->getType() == odhtdb::User::Type::LOCAL);
sibs::SafeSerializer serializer;
- serializer.add(ChannelDataType::MESSAGE);
+ serializer.add(ChannelDataType::ADD_MESSAGE);
serializer.add((const u8*)msg.data(), msg.size());
database->addData(databaseNodeInfo, static_cast<const odhtdb::LocalUser*>(localOnlineUser->databaseUser), odhtdb::DataView(serializer.getBuffer().data(), serializer.getBuffer().size()));
database->commit();
}
else
- addLocalMessage(msg, localUser, 0);
+ addLocalMessage(msg, localUser, 0, odhtdb::Hash());
+ }
+
+ void Channel::deleteLocalMessage(const odhtdb::Hash &id)
+ {
+ messageBoard.deleteMessage(id);
+ }
+
+ void Channel::deleteMessage(const odhtdb::Hash &id)
+ {
+ if(database && localUser->type == User::Type::ONLINE)
+ {
+ auto localOnlineUser = static_cast<OnlineUser*>(localUser);
+ assert(localOnlineUser->databaseUser->getType() == odhtdb::User::Type::LOCAL);
+
+ sibs::SafeSerializer serializer;
+ serializer.add(ChannelDataType::DELETE_MESSAGE);
+ serializer.add((const u8*)id.getData(), odhtdb::HASH_BYTE_SIZE);
+
+ database->addData(databaseNodeInfo, static_cast<const odhtdb::LocalUser*>(localOnlineUser->databaseUser), odhtdb::DataView(serializer.getBuffer().data(), serializer.getBuffer().size()));
+ database->commit();
+ }
+ else
+ deleteLocalMessage(id);
}
void Channel::addUserLocally(User *user)