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

View file

@ -404,6 +404,10 @@ void Client::setRoomInfoCallback(roomInfoCallback cb) {
callbacks.roomInfo = cb;
}
void Client::setRoomLimitedCallback(roomLimitedCallback cb) {
callbacks.roomLimited = cb;
}
void Client::processSync(json_t* sync) {
json_t* rooms = json_object_get(sync, "rooms");
if (!rooms) {
@ -558,6 +562,13 @@ void Client::processSync(json_t* sync) {
}
}
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) {
json_t* events = json_object_get(timeline, "events");
if (events) {