matrix-3ds-sdk/include/matrixclient.h

53 lines
1.6 KiB
C
Raw Normal View History

2019-10-16 18:39:57 +02:00
#ifndef _matrixclient_h_
#define _matrixclient_h_
#include <string>
#include <3ds.h>
#include <jansson.h>
2019-10-17 10:45:55 +02:00
namespace Matrix {
class Store {
public:
virtual void setSyncToken(std::string token) = 0;
virtual std::string getSyncToken() = 0;
};
class Client {
2019-10-16 18:39:57 +02:00
private:
2019-10-17 10:45:55 +02:00
public:
2019-10-16 18:39:57 +02:00
std::string hsUrl;
std::string token;
2019-10-17 10:45:55 +02:00
Store* store;
2019-10-17 12:54:49 +02:00
std::string userIdCache = "";
int requestId = 0;
bool stopSyncing = false;
2019-10-17 14:00:02 +02:00
bool isSyncing = false;
2019-10-17 12:54:49 +02:00
Thread syncThread;
2019-10-17 21:52:34 +02:00
void (* sync_event_callback)(std::string roomId, json_t* event) = 0;
2019-10-17 10:45:55 +02:00
void processSync(json_t* sync);
json_t* doSync(std::string token);
2019-10-17 21:52:34 +02:00
void startSync();
2019-10-17 10:45:55 +02:00
json_t* doRequest(const char* method, std::string path, json_t* body = NULL);
2019-10-16 18:39:57 +02:00
public:
2019-10-17 14:00:02 +02:00
Client(std::string homeserverUrl, std::string matrixToken = "", Store* clientStore = NULL);
std::string getToken();
bool login(std::string username, std::string password);
2019-10-17 13:22:39 +02:00
std::string getUserId();
std::string resolveRoom(std::string alias);
std::string sendEmote(std::string roomId, std::string text);
std::string sendNotice(std::string roomId, std::string text);
std::string sendText(std::string roomId, std::string text);
2019-10-16 22:57:55 +02:00
std::string sendMessage(std::string roomId, json_t* content);
std::string sendEvent(std::string roomId, std::string eventType, json_t* content);
2019-10-17 13:22:39 +02:00
std::string sendStateEvent(std::string roomId, std::string type, std::string stateKey, json_t* content);
std::string redactEvent(std::string roomId, std::string eventId, std::string reason = "");
2019-10-17 21:52:34 +02:00
void setSyncEventCallback(void (*cb)(std::string roomId, json_t* event));
2019-10-17 12:54:49 +02:00
void startSyncLoop();
void stopSyncLoop();
2019-10-16 18:39:57 +02:00
};
2019-10-17 10:45:55 +02:00
}; // namespace Matrix
2019-10-16 18:39:57 +02:00
#endif // _matrixclient_h_