Save messages to database
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <sqlite3.h>
|
||||
#include <sys/types.h>
|
||||
#include <vector>
|
||||
|
||||
#include "post.h"
|
||||
@@ -19,13 +20,33 @@ struct User {
|
||||
std::string passwordHash = "";
|
||||
std::string bio = "";
|
||||
|
||||
User(uint64_t id, std::string namein, const std::string& passwordHash, const std::string& bio) :
|
||||
User(uint64_t id, const std::string& namein, const std::string& passwordHash, const std::string& bio) :
|
||||
id(id), passwordHash(passwordHash), bio(bio), name(namein) {}
|
||||
|
||||
User(uint64_t id, std::string namein, const std::string& passwordHash, const std::string& bio, int doSanitize) :
|
||||
id(id), passwordHash(passwordHash), bio(bio) {
|
||||
sanitize(namein);
|
||||
name = namein;
|
||||
}
|
||||
};
|
||||
|
||||
struct Message {
|
||||
uint64_t id = 0;
|
||||
uint64_t sender = 0;
|
||||
uint64_t reciever = 0;
|
||||
std::time_t timestamp;
|
||||
std::string content = "";
|
||||
|
||||
Message(uint64_t id, uint64_t sender, uint64_t reciever, const std::string& content, std::time_t timestamp) :
|
||||
id(id), sender(sender), reciever(reciever), content(content), timestamp(timestamp) {}
|
||||
|
||||
Message(uint64_t id, uint64_t sender, uint64_t reciever, std::string contentin, std::time_t timestamp, int doSanitize) :
|
||||
id(id), sender(sender), reciever(reciever), timestamp(timestamp) {
|
||||
sanitize(contentin);
|
||||
content = contentin;
|
||||
}
|
||||
};
|
||||
|
||||
class Database {
|
||||
|
||||
sqlite3* db;
|
||||
@@ -52,6 +73,10 @@ class Database {
|
||||
void updateUser(const User& user);
|
||||
void invalidateUserSessions(const User& user);
|
||||
|
||||
std::vector<Message> getMessages(uint64_t userA, uint64_t userB, uint64_t amount);
|
||||
// modifies the message to have it's id
|
||||
void addMessage(Message& message);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user