forked from hiimgoodpack/brainlet-client
Compare commits
2 commits
2b71b7da08
...
ab6eda1a4c
Author | SHA1 | Date | |
---|---|---|---|
|
ab6eda1a4c | ||
|
090418e1df |
3 changed files with 29 additions and 18 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*.o
|
||||
*.out
|
13
brainlet.h
13
brainlet.h
|
@ -46,7 +46,12 @@ namespace Brainlet {
|
|||
} Channel;
|
||||
|
||||
typedef struct {
|
||||
std::string authorId;
|
||||
std::string id;
|
||||
std::string username;
|
||||
} MessageAuthor;
|
||||
|
||||
typedef struct {
|
||||
MessageAuthor author;
|
||||
std::string message;
|
||||
} Message;
|
||||
|
||||
|
@ -271,8 +276,12 @@ namespace Brainlet {
|
|||
.id = data["channel"]["_id"].asString(),
|
||||
.name = data["channel"]["title"].asString()
|
||||
};
|
||||
MessageAuthor author = {
|
||||
.id = data["author"]["_id"].asString(),
|
||||
.username = data["author"]["username"].asString()
|
||||
};
|
||||
Message message = {
|
||||
.authorId = data["author"]["_id"].asString(),
|
||||
.author = author,
|
||||
.message = data["content"].asString()
|
||||
};
|
||||
if (client->onNewMessage)
|
||||
|
|
32
main.cpp
32
main.cpp
|
@ -27,25 +27,25 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
std::unique_ptr<Brainlet::Client> client = nullptr;
|
||||
static std::unique_ptr<Brainlet::Client> client = nullptr;
|
||||
|
||||
std::unordered_map<Gtk::ListBoxRow*, std::string> channelRowToId;
|
||||
std::unordered_map<std::string, std::vector<Brainlet::Message>> messages;
|
||||
std::string currentChannelId;
|
||||
static std::unordered_map<Gtk::ListBoxRow*, std::string> channelRowToId;
|
||||
static std::unordered_map<std::string, std::vector<Brainlet::Message>> messages;
|
||||
static std::string currentChannelId;
|
||||
|
||||
Gtk::Window* window;
|
||||
static Gtk::Window* window;
|
||||
|
||||
Gtk::Widget* loginInterface;
|
||||
Gtk::Entry* domainEntry;
|
||||
Gtk::Entry* usernameEntry;
|
||||
Gtk::Entry* passwordEntry;
|
||||
Gtk::Button* loginButton;
|
||||
static Gtk::Widget* loginInterface;
|
||||
static Gtk::Entry* domainEntry;
|
||||
static Gtk::Entry* usernameEntry;
|
||||
static Gtk::Entry* passwordEntry;
|
||||
static Gtk::Button* loginButton;
|
||||
|
||||
Gtk::Widget* chatInterface;
|
||||
Gtk::ListBox* channelList;
|
||||
Gtk::ListBox* messageList;
|
||||
Gtk::Entry* messageEntry;
|
||||
Gtk::Label* usernameLabel;
|
||||
static Gtk::Widget* chatInterface;
|
||||
static Gtk::ListBox* channelList;
|
||||
static Gtk::ListBox* messageList;
|
||||
static Gtk::Entry* messageEntry;
|
||||
static Gtk::Label* usernameLabel;
|
||||
|
||||
gboolean update(gpointer) {
|
||||
client->processNextEvent();
|
||||
|
@ -80,7 +80,7 @@ void addMessage(const Brainlet::Message message) {
|
|||
text->set_halign(Gtk::ALIGN_START);
|
||||
text->set_line_wrap(true);
|
||||
|
||||
std::string messageFormatted = message.authorId + ": " + message.message;
|
||||
std::string messageFormatted = message.author.username + ": " + message.message;
|
||||
text->set_markup(messageFormatted.c_str());
|
||||
|
||||
row->add(*text);
|
||||
|
|
Reference in a new issue