From 81145987d90c5df093822e5f3c6dcccbd156f330 Mon Sep 17 00:00:00 2001 From: Kenneth Geisshirt Date: Wed, 20 Dec 2017 15:44:45 +0100 Subject: [PATCH] Adding get_query_status. --- src/js_realm.hpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/js_realm.hpp b/src/js_realm.hpp index 5aa948cd..81086cc3 100644 --- a/src/js_realm.hpp +++ b/src/js_realm.hpp @@ -188,6 +188,7 @@ public: static void object_for_object_id(ContextType, ObjectType, Arguments, ReturnValue&); #if REALM_ENABLE_SYNC static void subscribe_to_objects(ContextType, ObjectType, Arguments, ReturnValue &); + static void get_query_status(ContextType, ObjectType, Arguments, ReturnValue &); #endif // properties @@ -249,6 +250,7 @@ public: {"_objectForObjectId", wrap}, #if REALM_ENABLE_SYNC {"_subscribeToObjects", wrap}, + {"getQueryStatus", wrap}, #endif }; @@ -1121,6 +1123,25 @@ void RealmClass::subscribe_to_objects(ContextType ctx, ObjectType this_object partial_sync::register_query(realm, object_type, query, std::move(cb)); } } + +template +void RealmClass::get_query_status(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) { + args.validate_count(1); + + SharedRealm realm = *get_internal>(this_object); + + std::string key = Value::validated_to_string(ctx, args[0]); + + partial_sync::SubscriptionState state; + std::string error; + partial_sync::get_query_status(realm->read_group(), key, state, error); + + ObjectType partial_sync_status = Object::create_empty(ctx); + Object::set_property(ctx, partial_sync_status, "error", Value::from_string(ctx, error)); + Object::set_property(ctx, partial_sync_status, "state", Value::from_number(ctx, static_cast(state))); + + return_value.set(partial_sync_status); +} #endif } // js