sparkle/libs/api/Message.hpp

33 lines
1.1 KiB
C++
Raw Normal View History

2024-12-31 02:20:56 +05:00
#ifndef API_MESSAGE_HPP_
#define API_MESSAGE_HPP_
2025-01-06 21:57:27 +05:00
#include <utils/types.hpp>
2024-12-31 02:20:56 +05:00
#include <string>
2025-01-13 14:40:21 +05:00
#include <tls/Network.hpp>
#include <gateway/Websocket.hpp>
2024-12-31 02:20:56 +05:00
using std::string;
using std::cout;
using std::endl;
class Message {
private:
json data;
WebSocket& web;
NetworkManager& req;
public:
2025-01-13 14:40:21 +05:00
Message(const json& data) : data(data), web(WebSocket::getInstance()), req(NetworkManager::getInstance()) {};
2024-12-31 02:20:56 +05:00
string send(const string& id, const json& msg) {
2024-12-31 05:58:15 +05:00
return req.request("POST", dapi + "/channels/" + id + "/messages", msg.dump());
2024-12-31 02:20:56 +05:00
}
2025-01-13 14:40:21 +05:00
string getMessages(const string& id, const string& count, const string& before = "") {
if (before.empty()) {
return req.request("GET", dapi + "/channels/" + id + "/messages?limit=" + count);
}
else {
return req.request("GET", dapi + "/channels/" + id + "/messages?before=" + before + "&limit=" + count);
}
return "pizda";
}
string deleteMessage(const string& channel_id, const string& message_id) {
return req.request("DELETE", dapi + "/channels/" + channel_id + "/messages/" + message_id);
}
2024-12-31 02:20:56 +05:00
};
#endif