aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
m---------depends/odhtdb0
-rw-r--r--include/Channel.hpp4
-rw-r--r--include/MessageBoard.hpp3
-rw-r--r--src/Channel.cpp8
-rw-r--r--src/MessageBoard.cpp24
-rw-r--r--src/main.cpp2
6 files changed, 28 insertions, 13 deletions
diff --git a/depends/odhtdb b/depends/odhtdb
-Subproject e3b6538c17884b5985a78e3d7c507d02b7af2e7
+Subproject 95f683eae7a004860eae2bca43f56f98b769cf8
diff --git a/include/Channel.hpp b/include/Channel.hpp
index 7d4cb08..93f3725 100644
--- a/include/Channel.hpp
+++ b/include/Channel.hpp
@@ -47,8 +47,8 @@ namespace dchat
void addLocalMessage(const std::string &msg, User *owner, u64 timestampSeconds = 0);
void addLocalMessage(const std::string &msg, User *owner, u64 timestampSeconds, const odhtdb::Hash &id);
void addMessage(const std::string &msg);
- void deleteLocalMessage(const odhtdb::Hash &id);
- void deleteMessage(const odhtdb::Hash &id);
+ void deleteLocalMessage(const odhtdb::Hash &id, const odhtdb::Signature::PublicKey &requestedByUser);
+ void deleteMessage(const odhtdb::Hash &id, const odhtdb::Signature::PublicKey &requestedByUser);
void addUserLocally(User *user);
bool addUser(const odhtdb::Signature::PublicKey &userId, const std::string &groupId);
diff --git a/include/MessageBoard.hpp b/include/MessageBoard.hpp
index a6867d2..9025e48 100644
--- a/include/MessageBoard.hpp
+++ b/include/MessageBoard.hpp
@@ -7,6 +7,7 @@
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Window/Event.hpp>
#include <odhtdb/Hash.hpp>
+#include <odhtdb/Signature.hpp>
#include <stdexcept>
#include <mutex>
@@ -26,7 +27,7 @@ namespace dchat
private:
void updateStaticContentTexture(const sf::Vector2u &newSize);
void addMessage(Message *message, const odhtdb::Hash &id);
- void deleteMessage(const odhtdb::Hash &id);
+ void deleteMessage(const odhtdb::Hash &id, const odhtdb::Signature::PublicKey &requestedByUser);
void drawDefault(sf::RenderWindow &window, Cache &cache);
void drawSimple(sf::RenderWindow &window, Cache &cache);
diff --git a/src/Channel.cpp b/src/Channel.cpp
index 678dddd..ed037a4 100644
--- a/src/Channel.cpp
+++ b/src/Channel.cpp
@@ -111,12 +111,12 @@ namespace dchat
addLocalMessage(msg, localUser, 0, odhtdb::Hash());
}
- void Channel::deleteLocalMessage(const odhtdb::Hash &id)
+ void Channel::deleteLocalMessage(const odhtdb::Hash &id, const odhtdb::Signature::PublicKey &requestedByUser)
{
- messageBoard.deleteMessage(id);
+ messageBoard.deleteMessage(id, requestedByUser);
}
- void Channel::deleteMessage(const odhtdb::Hash &id)
+ void Channel::deleteMessage(const odhtdb::Hash &id, const odhtdb::Signature::PublicKey &requestedByUser)
{
if(database && localUser->type == User::Type::ONLINE)
{
@@ -131,7 +131,7 @@ namespace dchat
database->commit();
}
else
- deleteLocalMessage(id);
+ deleteLocalMessage(id, requestedByUser);
}
void Channel::addUserLocally(User *user)
diff --git a/src/MessageBoard.cpp b/src/MessageBoard.cpp
index bdaccf3..f2796e5 100644
--- a/src/MessageBoard.cpp
+++ b/src/MessageBoard.cpp
@@ -16,6 +16,7 @@
#include <SFML/Window/Mouse.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/Text.hpp>
+#include <odhtdb/User.hpp>
#include <cmath>
using namespace std;
@@ -76,11 +77,20 @@ namespace dchat
scrollToBottom = true;
}
- void MessageBoard::deleteMessage(const odhtdb::Hash &id)
+ void MessageBoard::deleteMessage(const odhtdb::Hash &id, const odhtdb::Signature::PublicKey &requestedByUser)
{
lock_guard<mutex> lock(messageProcessMutex);
auto it = messageIdMap.find(id);
if(it == messageIdMap.end()) return;
+ if(it->second->user->type == User::Type::ONLINE)
+ {
+ auto onlineUser = static_cast<const OnlineUser*>(it->second->user);
+ if(onlineUser->databaseUser->getPublicKey() != requestedByUser)
+ {
+ fprintf(stderr, "Warning: user %s requested to delete a message owned by user %s, ignoring request\n", requestedByUser.toString().c_str(), onlineUser->databaseUser->getPublicKey().toString().c_str());
+ return;
+ }
+ }
for(usize i = 0; i < messages.size(); ++i)
{
@@ -282,20 +292,24 @@ namespace dchat
message->text.processEvent(event);
}
- if(event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Button::Right)
+ OnlineUser *localOnlineUser = nullptr;
+ if(channel->getLocalUser()->type == User::Type::ONLINE)
+ localOnlineUser = static_cast<OnlineUser*>(channel->getLocalUser());
+
+ if(localOnlineUser && event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Button::Right)
{
for(auto it : messageIdMap)
{
it.second->text.processEvent(event);
auto textPos = it.second->text.getPosition();
- if(event.mouseButton.x >= textPos.x && event.mouseButton.x <= textPos.x + it.second->text.getMaxWidth() && event.mouseButton.y >= textPos.y && event.mouseButton.y <= textPos.y + it.second->text.getHeight())
+ if(it.second->user == channel->getLocalUser() && event.mouseButton.x >= textPos.x && event.mouseButton.x <= textPos.x + it.second->text.getMaxWidth() && event.mouseButton.y >= textPos.y && event.mouseButton.y <= textPos.y + it.second->text.getHeight())
{
auto contextMenu = GlobalContextMenu::getEditMessageContextMenu();
contextMenu->setPosition(sf::Vector2f(event.mouseButton.x, event.mouseButton.y));
contextMenu->setVisible(true);
- GlobalContextMenu::setClickDeleteMessageCallbackFunc([this, it](ContextMenuItem *menuItem)
+ GlobalContextMenu::setClickDeleteMessageCallbackFunc([this, it, localOnlineUser](ContextMenuItem *menuItem)
{
- channel->deleteMessage(it.first);
+ channel->deleteMessage(it.first, localOnlineUser->databaseUser->getPublicKey());
GlobalContextMenu::setClickDeleteMessageCallbackFunc(nullptr);
});
return;
diff --git a/src/main.cpp b/src/main.cpp
index 83ef11a..910724e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -102,7 +102,7 @@ void channelAddStoredMessage(Channel *channel, const odhtdb::Hash &requestHash,
sibs::SafeDeserializer deserializer((const u8*)decryptedData.data, decryptedData.size);
odhtdb::Hash messageId;
deserializer.extract((u8*)messageId.getData(), odhtdb::HASH_BYTE_SIZE);
- channel->deleteLocalMessage(messageId);
+ channel->deleteLocalMessage(messageId, creatorPublicKey);
break;
}
case ChannelDataType::NICKNAME_CHANGE: