add sync_event_callback
This commit is contained in:
parent
0abfac1ff4
commit
29a44c9371
2 changed files with 14 additions and 4 deletions
|
@ -24,8 +24,10 @@ public:
|
||||||
bool stopSyncing = false;
|
bool stopSyncing = false;
|
||||||
bool isSyncing = false;
|
bool isSyncing = false;
|
||||||
Thread syncThread;
|
Thread syncThread;
|
||||||
|
void (* sync_event_callback)(std::string roomId, json_t* event) = 0;
|
||||||
void processSync(json_t* sync);
|
void processSync(json_t* sync);
|
||||||
json_t* doSync(std::string token);
|
json_t* doSync(std::string token);
|
||||||
|
void startSync();
|
||||||
json_t* doRequest(const char* method, std::string path, json_t* body = NULL);
|
json_t* doRequest(const char* method, std::string path, json_t* body = NULL);
|
||||||
public:
|
public:
|
||||||
Client(std::string homeserverUrl, std::string matrixToken = "", Store* clientStore = NULL);
|
Client(std::string homeserverUrl, std::string matrixToken = "", Store* clientStore = NULL);
|
||||||
|
@ -40,9 +42,9 @@ public:
|
||||||
std::string sendEvent(std::string roomId, std::string eventType, json_t* content);
|
std::string sendEvent(std::string roomId, std::string eventType, json_t* content);
|
||||||
std::string sendStateEvent(std::string roomId, std::string type, std::string stateKey, json_t* content);
|
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 = "");
|
std::string redactEvent(std::string roomId, std::string eventId, std::string reason = "");
|
||||||
|
void setSyncEventCallback(void (*cb)(std::string roomId, json_t* event));
|
||||||
void startSyncLoop();
|
void startSyncLoop();
|
||||||
void stopSyncLoop();
|
void stopSyncLoop();
|
||||||
void startSync();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}; // namespace Matrix
|
}; // namespace Matrix
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
#define SOC_BUFFERSIZE 0x100000
|
#define SOC_BUFFERSIZE 0x100000
|
||||||
#define SYNC_TIMEOUT 10000
|
#define SYNC_TIMEOUT 10000
|
||||||
|
|
||||||
#define DEBUG 1
|
#define DEBUG 0
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
#define D
|
#define D
|
||||||
|
@ -215,6 +215,10 @@ void Client::stopSyncLoop() {
|
||||||
isSyncing = false;
|
isSyncing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Client::setSyncEventCallback(void (*cb)(std::string roomId, json_t* event)) {
|
||||||
|
sync_event_callback = cb;
|
||||||
|
}
|
||||||
|
|
||||||
void Client::processSync(json_t* sync) {
|
void Client::processSync(json_t* sync) {
|
||||||
json_t* rooms = json_object_get(sync, "rooms");
|
json_t* rooms = json_object_get(sync, "rooms");
|
||||||
if (!rooms) {
|
if (!rooms) {
|
||||||
|
@ -226,10 +230,13 @@ void Client::processSync(json_t* sync) {
|
||||||
|
|
||||||
const char* roomId;
|
const char* roomId;
|
||||||
json_t* room;
|
json_t* room;
|
||||||
|
size_t index;
|
||||||
|
json_t* event;
|
||||||
|
|
||||||
if (leftRooms) {
|
if (leftRooms) {
|
||||||
json_object_foreach(leftRooms, roomId, room) {
|
json_object_foreach(leftRooms, roomId, room) {
|
||||||
// rooms that we left
|
// rooms that we left
|
||||||
|
// emit leave event with roomId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,11 +260,12 @@ void Client::processSync(json_t* sync) {
|
||||||
D printf("no events\n");
|
D printf("no events\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
size_t index;
|
|
||||||
json_t* event;
|
|
||||||
json_array_foreach(events, index, event) {
|
json_array_foreach(events, index, event) {
|
||||||
json_t* eventType = json_object_get(event, "type");
|
json_t* eventType = json_object_get(event, "type");
|
||||||
D printf("%s\n", json_string_value(eventType));
|
D printf("%s\n", json_string_value(eventType));
|
||||||
|
if (sync_event_callback) {
|
||||||
|
sync_event_callback(roomId, event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue