provide roomLimited callback

This commit is contained in:
Sorunome 2019-10-26 12:54:09 +02:00
parent 05385723ee
commit d6f56e8b2d
No known key found for this signature in database
GPG key ID: 63E31F7B5993A9C4
2 changed files with 14 additions and 0 deletions

View file

@ -40,6 +40,7 @@ enum struct RequestError : u8 {
typedef void (*eventCallback)(std::string roomId, json_t* event); typedef void (*eventCallback)(std::string roomId, json_t* event);
typedef void (*roomInfoCallback)(std::string roomId, RoomInfo info); typedef void (*roomInfoCallback)(std::string roomId, RoomInfo info);
typedef void (*roomLimitedCallback)(std::string roomId, std::string prevBatch);
class Client { class Client {
private: private:
@ -58,6 +59,7 @@ public:
eventCallback leaveRoom = NULL; eventCallback leaveRoom = NULL;
eventCallback inviteRoom = NULL; eventCallback inviteRoom = NULL;
roomInfoCallback roomInfo = NULL; roomInfoCallback roomInfo = NULL;
roomLimitedCallback roomLimited = NULL;
} callbacks; } callbacks;
void processSync(json_t* sync); void processSync(json_t* sync);
void registerFilter(); void registerFilter();
@ -95,6 +97,7 @@ public:
void setLeaveRoomCallback(eventCallback cb); void setLeaveRoomCallback(eventCallback cb);
void setInviteRoomCallback(eventCallback cb); void setInviteRoomCallback(eventCallback cb);
void setRoomInfoCallback(roomInfoCallback cb); void setRoomInfoCallback(roomInfoCallback cb);
void setRoomLimitedCallback(roomLimitedCallback cb);
}; };
}; // namespace Matrix }; // namespace Matrix

View file

@ -404,6 +404,10 @@ void Client::setRoomInfoCallback(roomInfoCallback cb) {
callbacks.roomInfo = cb; callbacks.roomInfo = cb;
} }
void Client::setRoomLimitedCallback(roomLimitedCallback cb) {
callbacks.roomLimited = 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) {
@ -558,6 +562,13 @@ void Client::processSync(json_t* sync) {
} }
} }
json_t* timeline = json_object_get(room, "timeline"); json_t* timeline = json_object_get(room, "timeline");
if (callbacks.roomLimited && timeline) {
json_t* limited = json_object_get(timeline, "limited");
const char* prevBatch = json_object_get_string_value(timeline, "prev_batch");
if (limited && prevBatch && json_typeof(limited) == JSON_TRUE) {
callbacks.roomLimited(roomId, prevBatch);
}
}
if (callbacks.event && timeline) { if (callbacks.event && timeline) {
json_t* events = json_object_get(timeline, "events"); json_t* events = json_object_get(timeline, "events");
if (events) { if (events) {