aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-11-01 07:17:49 +0100
committerdec05eba <dec05eba@protonmail.com>2018-11-01 07:17:52 +0100
commit0469c43a45310b6b92eb704773e3a34beb57f288 (patch)
tree3d79b563fdc99a18f29bf65a8b293fecca8b7a4a /include
parenta535703add6bf29878845cb270997514489cfc16 (diff)
Move room code to dchat_core, add ability to send messages
Diffstat (limited to 'include')
-rw-r--r--include/ChannelDataType.hpp16
-rw-r--r--include/ChatMessage.hpp3
-rw-r--r--include/ChatWindow.hpp26
-rw-r--r--include/LoginWindow.hpp2
-rw-r--r--include/User.hpp13
-rw-r--r--include/Window.hpp4
6 files changed, 15 insertions, 49 deletions
diff --git a/include/ChannelDataType.hpp b/include/ChannelDataType.hpp
deleted file mode 100644
index 21e828d..0000000
--- a/include/ChannelDataType.hpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#pragma once
-
-#include <dchat/types.hpp>
-
-namespace dchat
-{
- enum class ChannelDataType : u8
- {
- ADD_MESSAGE,
- EDIT_MESSAGE,
- DELETE_MESSAGE,
- NICKNAME_CHANGE,
- CHANGE_AVATAR,
- CHANGE_CHANNEL_NAME,
- };
-} \ No newline at end of file
diff --git a/include/ChatMessage.hpp b/include/ChatMessage.hpp
index c13db9d..c1ef459 100644
--- a/include/ChatMessage.hpp
+++ b/include/ChatMessage.hpp
@@ -10,13 +10,12 @@ namespace dchat
class ChatMessage : public Gtk::Grid
{
public:
- ChatMessage(const Glib::ustring &username, const Glib::ustring &text, uint32_t timestampSeconds, const User *user);
+ ChatMessage(const Glib::ustring &username, const Glib::ustring &text, uint32_t timestampSeconds);
Gtk::Grid avatar;
Gtk::Label username;
Gtk::Label text;
uint32_t timestampSeconds;
- const User *user;
private:
bool updateContent(const Cairo::RefPtr<Cairo::Context> &cairo);
};
diff --git a/include/ChatWindow.hpp b/include/ChatWindow.hpp
index 0b58506..988b225 100644
--- a/include/ChatWindow.hpp
+++ b/include/ChatWindow.hpp
@@ -1,6 +1,6 @@
#pragma once
-#include "User.hpp"
+#include <dchat/Room.hpp>
#include <gtkmm/label.h>
#include <gtkmm/togglebutton.h>
#include <gtkmm/grid.h>
@@ -20,13 +20,11 @@ namespace dchat
{
public:
ChatWindow();
- void addChannel(const odhtdb::Hash &nodeHash);
- void addLocalMessage(const odhtdb::Hash &channelId, const odhtdb::Signature::PublicKey &userPublicKey, uint32_t timestampSeconds, Glib::ustring msg);
- void addUser(const odhtdb::Signature::PublicKey &userPublicKey);
- void setUserNickname(const odhtdb::Signature::PublicKey &userPublicKey, const Glib::ustring &name);
-
- // Returns nullptr if user with @publicKey is not found
- User* getUserByPublicKey(const odhtdb::Signature::PublicKey &publicKey) const;
+ void addRoom(std::shared_ptr<Room> room);
+ void addMessage(const RoomAddMessageRequest &request);
+ void addUser(std::shared_ptr<Room> room, std::shared_ptr<User> user);
+ void setUserNickname(const UserChangeNicknameRequest &request);
+ void scrollToBottom();
private:
void setupTopBar();
void setupLeftPanel(Gtk::Paned *sidePanels);
@@ -42,17 +40,15 @@ namespace dchat
Gtk::Grid messageAreaLayout;
Gtk::TextView chatInput;
- struct ChannelData
+ struct RoomData
{
Gtk::ToggleButton *button;
- int messageCount;
};
- odhtdb::MapHash<ChannelData> channelDataById;
- int channelCount;
- std::vector<User*> users;
-
- ChatMessage *lastMessage;
+ odhtdb::MapHash<RoomData> roomDataById;
+ odhtdb::MapHash<ChatMessage*> messageById;
int chatPrevNumLines;
+ int roomCount;
+ std::shared_ptr<Room> currentRoom;
};
} \ No newline at end of file
diff --git a/include/LoginWindow.hpp b/include/LoginWindow.hpp
index ea9b905..d5585a5 100644
--- a/include/LoginWindow.hpp
+++ b/include/LoginWindow.hpp
@@ -22,7 +22,7 @@ namespace dchat
private:
void setupLogin();
void setupRegister();
- private:
+ public:
Gtk::Grid loginLayout;
Gtk::Entry loginUsernameInput;
Gtk::Entry loginPasswordInput;
diff --git a/include/User.hpp b/include/User.hpp
deleted file mode 100644
index 471a5cc..0000000
--- a/include/User.hpp
+++ /dev/null
@@ -1,13 +0,0 @@
-#pragma once
-
-#include <glibmm/ustring.h>
-#include <odhtdb/Signature.hpp>
-
-namespace dchat
-{
- struct User
- {
- const odhtdb::Signature::PublicKey publicKey;
- Glib::ustring name;
- };
-} \ No newline at end of file
diff --git a/include/Window.hpp b/include/Window.hpp
index 4c67a68..a29ec62 100644
--- a/include/Window.hpp
+++ b/include/Window.hpp
@@ -5,7 +5,7 @@
#include <gtkmm/window.h>
#include <gtkmm/stack.h>
#include <gtkmm/overlay.h>
-#include <odhtdb/Database.hpp>
+#include <dchat/Room.hpp>
#include <mutex>
#include <random>
#include <vector>
@@ -26,7 +26,7 @@ namespace dchat
void draw(const Cairo::RefPtr<Cairo::Context> &cairo) { Gtk::Overlay::draw(cairo); }
};
- std::unique_ptr<odhtdb::Database> database;
+ std::shared_ptr<Rooms> rooms;
std::mutex databaseCallbackMutex;
OverlayDrawable overlay;
Gtk::Stack stack;