diff --git a/privmx-endpoint/src/main/cpp/modules/EventApi.cpp b/privmx-endpoint/src/main/cpp/modules/EventApi.cpp index 055f82c8..5591cce5 100644 --- a/privmx-endpoint/src/main/cpp/modules/EventApi.cpp +++ b/privmx-endpoint/src/main/cpp/modules/EventApi.cpp @@ -106,47 +106,111 @@ Java_com_simplito_java_privmx_1endpoint_modules_event_EventApi_emitEvent( } extern "C" -JNIEXPORT void JNICALL -Java_com_simplito_java_privmx_1endpoint_modules_event_EventApi_subscribeForCustomEvents( +JNIEXPORT jobject JNICALL +Java_com_simplito_java_privmx_1endpoint_modules_event_EventApi_subscribeFor( JNIEnv *env, jobject thiz, - jstring context_id, - jstring channel_name + jobject subscription_queries ) { JniContextUtils ctx(env); - - if (ctx.nullCheck(context_id, "Context ID") || - ctx.nullCheck(channel_name, "Channel name")) { - return; + if (ctx.nullCheck(subscription_queries, "Subscription queries")) { + return nullptr; } - ctx.callVoidEndpointApi([&ctx, &thiz, &context_id, &channel_name]() { - getEventApi(ctx, thiz)->subscribeForCustomEvents( - ctx.jString2string(context_id), - ctx.jString2string(channel_name) - ); - }); + jobject result = nullptr; + ctx.callResultEndpointApi( + &result, + [&ctx, &env, &thiz, &subscription_queries]() { + jclass arrayListCls = env->FindClass("java/util/ArrayList"); + jmethodID initMID = env->GetMethodID(arrayListCls, "", "()V"); + jmethodID addToListMID = env->GetMethodID(arrayListCls, "add", "(Ljava/lang/Object;)Z"); + + auto subscription_queries_arr = ctx.jObject2jArray(subscription_queries); + auto subscription_queries_c = std::vector(); + + int length = ctx->GetArrayLength(subscription_queries_arr); + for (int i = 0; i < length; i++) { + jobject arrayElement = ctx->GetObjectArrayElement(subscription_queries_arr, i); + subscription_queries_c.push_back(ctx.jString2string((jstring) arrayElement)); + } + + jobject arrayList = env->NewObject(arrayListCls, initMID); + auto subscription_ids_c = getEventApi(ctx, thiz)-> + subscribeFor(subscription_queries_c); + + for (auto &id_str : subscription_ids_c) { + jstring java_id_str = ctx->NewStringUTF(id_str.c_str()); + env->CallBooleanMethod(arrayList, addToListMID, java_id_str); + } + return arrayList; + } + ); + if (ctx->ExceptionCheck()) { + return nullptr; + } + return result; } + extern "C" JNIEXPORT void JNICALL -Java_com_simplito_java_privmx_1endpoint_modules_event_EventApi_unsubscribeFromCustomEvents( +Java_com_simplito_java_privmx_1endpoint_modules_event_EventApi_unsubscribeFrom( JNIEnv *env, jobject thiz, - jstring context_id, - jstring channel_name + jobject subscription_ids ) { JniContextUtils ctx(env); - - if (ctx.nullCheck(context_id, "Context ID") || - ctx.nullCheck(channel_name, "Channel name")) { + if (ctx.nullCheck(subscription_ids, "Subscription IDs")) { return; } - ctx.callVoidEndpointApi([&ctx, &thiz, &context_id, &channel_name]() { - getEventApi(ctx, thiz)->unsubscribeFromCustomEvents( - ctx.jString2string(context_id), - ctx.jString2string(channel_name) - ); + ctx.callVoidEndpointApi([&ctx, &env, &thiz, &subscription_ids]() { + auto subscription_ids_arr = ctx.jObject2jArray(subscription_ids); + auto subscription_ids_c = std::vector(); + + int length = ctx->GetArrayLength(subscription_ids_arr); + for (int i = 0; i < length; i++) { + jobject arrayElement = ctx->GetObjectArrayElement(subscription_ids_arr, i); + if (ctx.nullCheck(arrayElement, "Subscription ids array elements")) { + return; + } + subscription_ids_c.push_back(ctx.jString2string((jstring) arrayElement)); + } + + getEventApi(ctx, thiz)->unsubscribeFrom(subscription_ids_c); }); -} \ No newline at end of file +} + + +extern "C" +JNIEXPORT jstring JNICALL +Java_com_simplito_java_privmx_1endpoint_modules_event_EventApi_buildSubscriptionQuery( + JNIEnv *env, + jobject thiz, + jstring channel_name, + jlong selector_type, + jstring selector_id +) { + JniContextUtils ctx(env); + if (ctx.nullCheck(channel_name, "ChannelName") || + ctx.nullCheck(selector_id, "SelectorID")) { + return nullptr; + } + + jstring result = nullptr; + ctx.callResultEndpointApi( + &result, + [&ctx, &env, &thiz, &channel_name, &selector_type, &selector_id]() { + std::string query_result_c = getEventApi(ctx, thiz)->buildSubscriptionQuery( + ctx.jString2string(channel_name), + static_cast(selector_type), + ctx.jString2string(selector_id) + ); + return ctx->NewStringUTF(query_result_c.c_str()); + } + ); + if (ctx->ExceptionCheck()) { + return nullptr; + } + return result; +} diff --git a/privmx-endpoint/src/main/cpp/modules/InboxApi.cpp b/privmx-endpoint/src/main/cpp/modules/InboxApi.cpp index 0c771d2f..959e8c4b 100644 --- a/privmx-endpoint/src/main/cpp/modules/InboxApi.cpp +++ b/privmx-endpoint/src/main/cpp/modules/InboxApi.cpp @@ -652,8 +652,8 @@ Java_com_simplito_java_privmx_1endpoint_modules_inbox_InboxApi_closeFile( &result, [&ctx, &thiz, &file_handle]() { return ctx->NewStringUTF( - getInboxApi(ctx, thiz)->closeFile(file_handle) - .c_str() + getInboxApi(ctx, thiz)-> + closeFile(file_handle).c_str() ); }); if (ctx->ExceptionCheck()) { @@ -663,58 +663,109 @@ Java_com_simplito_java_privmx_1endpoint_modules_inbox_InboxApi_closeFile( } extern "C" -JNIEXPORT void JNICALL -Java_com_simplito_java_privmx_1endpoint_modules_inbox_InboxApi_subscribeForInboxEvents( +JNIEXPORT jobject JNICALL +Java_com_simplito_java_privmx_1endpoint_modules_inbox_InboxApi_subscribeFor( JNIEnv *env, - jobject thiz + jobject thiz, + jobject subscription_queries ) { JniContextUtils ctx(env); - ctx.callVoidEndpointApi([&ctx, &thiz]() { - getInboxApi(ctx, thiz)->subscribeForInboxEvents(); - }); -} + if (ctx.nullCheck(subscription_queries, "Subscription queries")) { + return nullptr; + } -extern "C" -JNIEXPORT void JNICALL -Java_com_simplito_java_privmx_1endpoint_modules_inbox_InboxApi_unsubscribeFromInboxEvents( - JNIEnv *env, - jobject thiz -) { - JniContextUtils ctx(env); - ctx.callVoidEndpointApi([&ctx, &thiz]() { - getInboxApi(ctx, thiz)->unsubscribeFromInboxEvents(); - }); + jobject result = nullptr; + ctx.callResultEndpointApi( + &result, + [&ctx, &env, &thiz, &subscription_queries]() { + jclass arrayListCls = env->FindClass("java/util/ArrayList"); + jmethodID initMID = env->GetMethodID(arrayListCls, "", "()V"); + jmethodID addToListMID = env->GetMethodID(arrayListCls, "add", "(Ljava/lang/Object;)Z"); + + auto subscription_queries_arr = ctx.jObject2jArray(subscription_queries); + auto subscription_queries_c = std::vector(); + + int length = ctx->GetArrayLength(subscription_queries_arr); + for (int i = 0; i < length; i++) { + jobject arrayElement = ctx->GetObjectArrayElement(subscription_queries_arr, i); + subscription_queries_c.push_back(ctx.jString2string((jstring) arrayElement)); + } + + auto subscription_ids_c = getInboxApi(ctx, thiz)->subscribeFor( + subscription_queries_c); + jobject arrayList = env->NewObject(arrayListCls, initMID); + + for (auto &id_str : subscription_ids_c) { + jstring java_id_str = ctx->NewStringUTF(id_str.c_str()); + env->CallBooleanMethod(arrayList, addToListMID, java_id_str); + } + return arrayList; + } + ); + if (ctx->ExceptionCheck()) { + return nullptr; + } + return result; } extern "C" JNIEXPORT void JNICALL -Java_com_simplito_java_privmx_1endpoint_modules_inbox_InboxApi_subscribeForEntryEvents( +Java_com_simplito_java_privmx_1endpoint_modules_inbox_InboxApi_unsubscribeFrom( JNIEnv *env, jobject thiz, - jstring inbox_id + jobject subscription_ids ) { JniContextUtils ctx(env); - if (ctx.nullCheck(inbox_id, "Inbox ID")) { + if (ctx.nullCheck(subscription_ids, "Subscription IDs")) { return; } - ctx.callVoidEndpointApi([&ctx, &thiz, &inbox_id]() { - getInboxApi(ctx, thiz)->subscribeForEntryEvents( - ctx.jString2string(inbox_id) - ); + + ctx.callVoidEndpointApi([&ctx, &env, &thiz, &subscription_ids]() { + auto subscription_ids_arr = ctx.jObject2jArray(subscription_ids); + auto subscription_ids_c = std::vector(); + + int length = ctx->GetArrayLength(subscription_ids_arr); + for (int i = 0; i < length; i++) { + jobject arrayElement = ctx->GetObjectArrayElement(subscription_ids_arr, i); + if (ctx.nullCheck(arrayElement, "Subscription ids array elements")) { + return; + } + subscription_ids_c.push_back(ctx.jString2string((jstring) arrayElement)); + } + + getInboxApi(ctx, thiz)->unsubscribeFrom(subscription_ids_c); }); } + extern "C" -JNIEXPORT void JNICALL -Java_com_simplito_java_privmx_1endpoint_modules_inbox_InboxApi_unsubscribeFromEntryEvents( +JNIEXPORT jstring JNICALL +Java_com_simplito_java_privmx_1endpoint_modules_inbox_InboxApi_buildSubscriptionQuery( JNIEnv *env, jobject thiz, - jstring inbox_id + jlong event_type, + jlong selector_type, + jstring selector_id ) { JniContextUtils ctx(env); - ctx.callVoidEndpointApi([&ctx, &thiz, &inbox_id]() { - getInboxApi(ctx, thiz)->unsubscribeFromEntryEvents( - ctx.jString2string(inbox_id) - ); - }); + if (ctx.nullCheck(selector_id, "Selector ID")) { + return nullptr; + } + + jstring result = nullptr; + ctx.callResultEndpointApi( + &result, + [&ctx, &env, &thiz, &event_type, &selector_type, &selector_id]() { + std::string query_result_c = getInboxApi(ctx, thiz)->buildSubscriptionQuery( + static_cast(event_type), + static_cast(selector_type), + ctx.jString2string(selector_id) + ); + return ctx->NewStringUTF(query_result_c.c_str()); + } + ); + if (ctx->ExceptionCheck()) { + return nullptr; + } + return result; } \ No newline at end of file diff --git a/privmx-endpoint/src/main/cpp/modules/KvdbApi.cpp b/privmx-endpoint/src/main/cpp/modules/KvdbApi.cpp index 7b33afdc..ddb77d46 100644 --- a/privmx-endpoint/src/main/cpp/modules/KvdbApi.cpp +++ b/privmx-endpoint/src/main/cpp/modules/KvdbApi.cpp @@ -615,55 +615,110 @@ Java_com_simplito_java_privmx_1endpoint_modules_kvdb_KvdbApi_deleteEntries( return result; } -extern "C" JNIEXPORT void JNICALL -Java_com_simplito_java_privmx_1endpoint_modules_kvdb_KvdbApi_subscribeForKvdbEvents( +extern "C" +JNIEXPORT jobject JNICALL +Java_com_simplito_java_privmx_1endpoint_modules_kvdb_KvdbApi_subscribeFor( JNIEnv *env, - jobject thiz + jobject thiz, + jobject subscription_queries ) { JniContextUtils ctx(env); + if (ctx.nullCheck(subscription_queries, "Subscription queries")) { + return nullptr; + } - ctx.callVoidEndpointApi([&ctx, &thiz]() { - getKvdbApi(ctx, thiz)->subscribeForKvdbEvents(); - }); -} -extern "C" JNIEXPORT void JNICALL -Java_com_simplito_java_privmx_1endpoint_modules_kvdb_KvdbApi_unsubscribeFromKvdbEvents( - JNIEnv *env, - jobject thiz -) { - JniContextUtils ctx(env); + jobject result = nullptr; + ctx.callResultEndpointApi( + &result, + [&ctx, &env, &thiz, &subscription_queries]() { + jclass arrayListCls = env->FindClass("java/util/ArrayList"); + jmethodID initMID = env->GetMethodID(arrayListCls, "", "()V"); + jmethodID addToListMID = env->GetMethodID(arrayListCls, "add", "(Ljava/lang/Object;)Z"); + + auto subscription_queries_arr = ctx.jObject2jArray(subscription_queries); + auto subscription_queries_c = std::vector(); + + int length = ctx->GetArrayLength(subscription_queries_arr); + for (int i = 0; i < length; i++) { + jobject arrayElement = ctx->GetObjectArrayElement(subscription_queries_arr, i); + subscription_queries_c.push_back(ctx.jString2string((jstring) arrayElement)); + } - ctx.callVoidEndpointApi([&ctx, &thiz]() { - getKvdbApi(ctx, thiz)->unsubscribeFromKvdbEvents(); - }); + jobject arrayList = env->NewObject(arrayListCls, initMID); + auto subscription_ids_c = getKvdbApi(ctx, thiz)->subscribeFor( + subscription_queries_c); + + for (auto &id_str : subscription_ids_c) { + jstring java_id_str = ctx->NewStringUTF(id_str.c_str()); + env->CallBooleanMethod(arrayList, addToListMID, java_id_str); + } + return arrayList; + } + ); + if (ctx->ExceptionCheck()) { + return nullptr; + } + return result; } -extern "C" JNIEXPORT void JNICALL -Java_com_simplito_java_privmx_1endpoint_modules_kvdb_KvdbApi_subscribeForEntryEvents( + +extern "C" +JNIEXPORT void JNICALL +Java_com_simplito_java_privmx_1endpoint_modules_kvdb_KvdbApi_unsubscribeFrom( JNIEnv *env, jobject thiz, - jstring kvdb_id + jobject subscription_ids ) { JniContextUtils ctx(env); - if (ctx.nullCheck(kvdb_id, "Kvdb ID")) { + if (ctx.nullCheck(subscription_ids, "Subscription IDs")) { return; } - ctx.callVoidEndpointApi([&ctx, &thiz, &kvdb_id]() { - getKvdbApi(ctx, thiz)->subscribeForEntryEvents(ctx.jString2string(kvdb_id)); + ctx.callVoidEndpointApi([&ctx, &env, &thiz, &subscription_ids]() { + auto subscription_ids_arr = ctx.jObject2jArray(subscription_ids); + auto subscription_ids_c = std::vector(); + + int length = ctx->GetArrayLength(subscription_ids_arr); + for (int i = 0; i < length; i++) { + jobject arrayElement = ctx->GetObjectArrayElement(subscription_ids_arr, i); + if (ctx.nullCheck(arrayElement, "Subscription ids array elements")) { + return; + } + subscription_ids_c.push_back(ctx.jString2string((jstring) arrayElement)); + } + + getKvdbApi(ctx, thiz)->unsubscribeFrom(subscription_ids_c); }); } -extern "C" JNIEXPORT void JNICALL -Java_com_simplito_java_privmx_1endpoint_modules_kvdb_KvdbApi_unsubscribeFromEntryEvents( + + +extern "C" +JNIEXPORT jstring JNICALL +Java_com_simplito_java_privmx_1endpoint_modules_kvdb_KvdbApi_buildSubscriptionQuery( JNIEnv *env, jobject thiz, - jstring kvdb_id + jlong event_type, + jlong selector_type, + jstring selector_id ) { JniContextUtils ctx(env); - if (ctx.nullCheck(kvdb_id, "Kvdb ID")) { - return; + if (ctx.nullCheck(selector_id, "SelectorID")) { + return nullptr; } - ctx.callVoidEndpointApi([&ctx, &thiz, &kvdb_id]() { - getKvdbApi(ctx, thiz)->unsubscribeFromEntryEvents(ctx.jString2string(kvdb_id)); - }); + jstring result = nullptr; + ctx.callResultEndpointApi( + &result, + [&ctx, &env, &thiz, &event_type, &selector_type, &selector_id]() { + std::string query_result_c = getKvdbApi(ctx, thiz)->buildSubscriptionQuery( + static_cast(event_type), + static_cast(selector_type), + ctx.jString2string(selector_id) + ); + return ctx->NewStringUTF(query_result_c.c_str()); + } + ); + if (ctx->ExceptionCheck()) { + return nullptr; + } + return result; } diff --git a/privmx-endpoint/src/main/cpp/modules/StoreApi.cpp b/privmx-endpoint/src/main/cpp/modules/StoreApi.cpp index 94a685f7..05c7f99b 100644 --- a/privmx-endpoint/src/main/cpp/modules/StoreApi.cpp +++ b/privmx-endpoint/src/main/cpp/modules/StoreApi.cpp @@ -620,60 +620,113 @@ Java_com_simplito_java_privmx_1endpoint_modules_store_StoreApi_closeFile( } extern "C" -JNIEXPORT void JNICALL -Java_com_simplito_java_privmx_1endpoint_modules_store_StoreApi_subscribeForStoreEvents( - JNIEnv *env, - jobject thiz -) { - JniContextUtils ctx(env); - ctx.callVoidEndpointApi([&ctx, &thiz]() { - getStoreApi(ctx, thiz)->subscribeForStoreEvents(); - }); -} -extern "C" -JNIEXPORT void JNICALL -Java_com_simplito_java_privmx_1endpoint_modules_store_StoreApi_unsubscribeFromStoreEvents( +JNIEXPORT jobject JNICALL +Java_com_simplito_java_privmx_1endpoint_modules_store_StoreApi_subscribeFor( JNIEnv *env, - jobject thiz + jobject thiz, + jobject subscription_queries ) { JniContextUtils ctx(env); - ctx.callVoidEndpointApi([&ctx, &thiz]() { - getStoreApi(ctx, thiz)->unsubscribeFromStoreEvents(); - }); + if (ctx.nullCheck(subscription_queries, "Subscription queries")) { + return nullptr; + } + + jobject result; + ctx.callResultEndpointApi( + &result, + [&ctx, &env, &thiz, &subscription_queries]() { + jclass arrayListCls = env->FindClass("java/util/ArrayList"); + jmethodID initMID = env->GetMethodID(arrayListCls, "", "()V"); + jmethodID addToListMID = env->GetMethodID(arrayListCls, "add", + "(Ljava/lang/Object;)Z"); + + auto subscription_queries_arr = ctx.jObject2jArray(subscription_queries); + auto subscription_queries_c = std::vector(); + + for (int i = 0; i < ctx->GetArrayLength(subscription_queries_arr); i++) { + jobject arrayElement = ctx->GetObjectArrayElement(subscription_queries_arr, i); + subscription_queries_c.push_back(ctx.jString2string((jstring) arrayElement)); + } + + auto subscription_ids_c = getStoreApi(ctx, thiz)->subscribeFor( + subscription_queries_c); + + jobject array = env->NewObject(arrayListCls, initMID); + for (auto &id: subscription_ids_c) { + ctx->CallBooleanMethod( + array, + addToListMID, + ctx->NewStringUTF(id.c_str()) + ); + } + return array; + } + ); + if (ctx->ExceptionCheck()) { + return nullptr; + } + return result; } + extern "C" JNIEXPORT void JNICALL -Java_com_simplito_java_privmx_1endpoint_modules_store_StoreApi_subscribeForFileEvents( +Java_com_simplito_java_privmx_1endpoint_modules_store_StoreApi_unsubscribeFrom( JNIEnv *env, jobject thiz, - jstring store_id + jobject subscription_ids ) { JniContextUtils ctx(env); - if (ctx.nullCheck(store_id, "Store ID")) { + if (ctx.nullCheck(subscription_ids, "Subscription IDs")) { return; } - ctx.callVoidEndpointApi([&ctx, &thiz, &store_id]() { - getStoreApi(ctx, thiz)->subscribeForFileEvents( - ctx.jString2string(store_id) - ); + + ctx.callVoidEndpointApi([&ctx, &thiz, &subscription_ids]() { + auto subscription_ids_arr = ctx.jObject2jArray(subscription_ids); + auto subscription_ids_c = std::vector(); + + for (int i = 0; i < ctx->GetArrayLength(subscription_ids_arr); i++) { + jobject arrayElement = ctx->GetObjectArrayElement(subscription_ids_arr, i); + if (ctx.nullCheck(arrayElement, "Subscription ids array elements")) { + return; + } + + subscription_ids_c.push_back(ctx.jString2string((jstring) arrayElement)); + } + + getStoreApi(ctx, thiz)->unsubscribeFrom(subscription_ids_c); }); } + extern "C" -JNIEXPORT void JNICALL -Java_com_simplito_java_privmx_1endpoint_modules_store_StoreApi_unsubscribeFromFileEvents( +JNIEXPORT jstring JNICALL +Java_com_simplito_java_privmx_1endpoint_modules_store_StoreApi_buildSubscriptionQuery( JNIEnv *env, jobject thiz, - jstring store_id + jlong event_type, + jlong selector_type, + jstring selector_id ) { JniContextUtils ctx(env); - if (ctx.nullCheck(store_id, "Store ID")) { - return; + if (ctx.nullCheck(selector_id, "Selector ID")) { + return nullptr; } - ctx.callVoidEndpointApi([&ctx, &thiz, &store_id]() { - getStoreApi(ctx, thiz)->unsubscribeFromFileEvents( - ctx.jString2string(store_id) - ); - }); + + jstring result; + ctx.callResultEndpointApi( + &result, + [&ctx, &thiz, &event_type, &selector_type, &selector_id]() { + auto result = getStoreApi(ctx, thiz)->buildSubscriptionQuery( + static_cast(event_type), + static_cast(selector_type), + ctx.jString2string(selector_id) + ); + return ctx->NewStringUTF(result.c_str()); + } + ); + if (ctx->ExceptionCheck()) { + return nullptr; + } + return result; } extern "C" diff --git a/privmx-endpoint/src/main/cpp/modules/ThreadApi.cpp b/privmx-endpoint/src/main/cpp/modules/ThreadApi.cpp index 5d69a731..cb997690 100644 --- a/privmx-endpoint/src/main/cpp/modules/ThreadApi.cpp +++ b/privmx-endpoint/src/main/cpp/modules/ThreadApi.cpp @@ -471,59 +471,113 @@ Java_com_simplito_java_privmx_1endpoint_modules_thread_ThreadApi_updateMessage( ); }); } + extern "C" -JNIEXPORT void JNICALL -Java_com_simplito_java_privmx_1endpoint_modules_thread_ThreadApi_subscribeForThreadEvents( - JNIEnv *env, - jobject thiz -) { - JniContextUtils ctx(env); - ctx.callVoidEndpointApi([&ctx, &thiz]() { - getThreadApi(ctx, thiz)->subscribeForThreadEvents(); - }); -} -extern "C" -JNIEXPORT void JNICALL -Java_com_simplito_java_privmx_1endpoint_modules_thread_ThreadApi_unsubscribeFromThreadEvents( +JNIEXPORT jobject JNICALL +Java_com_simplito_java_privmx_1endpoint_modules_thread_ThreadApi_subscribeFor( JNIEnv *env, - jobject thiz + jobject thiz, + jobject subscription_queries ) { JniContextUtils ctx(env); - ctx.callVoidEndpointApi([&ctx, &thiz]() { - getThreadApi(ctx, thiz)->unsubscribeFromThreadEvents(); - }); + if (ctx.nullCheck(subscription_queries, "Subscription queries")) { + return nullptr; + } + + jobject result; + ctx.callResultEndpointApi( + &result, + [&ctx, &env, &thiz, &subscription_queries]() { + jclass arrayListCls = env->FindClass("java/util/ArrayList"); + jmethodID initMID = env->GetMethodID(arrayListCls, "", "()V"); + jmethodID addToListMID = env->GetMethodID(arrayListCls, "add", + "(Ljava/lang/Object;)Z"); + + auto subscription_queries_arr = ctx.jObject2jArray(subscription_queries); + auto subscription_queries_c = std::vector(); + + int length = ctx->GetArrayLength(subscription_queries_arr); + for (int i = 0; i < length; i++) { + jobject arrayElement = ctx->GetObjectArrayElement(subscription_queries_arr, i); + subscription_queries_c.push_back(ctx.jString2string((jstring) arrayElement)); + } + + jobject arrayList = env->NewObject(arrayListCls, initMID); + auto subscription_ids_c = getThreadApi(ctx, thiz)->subscribeFor( + subscription_queries_c); + + for (auto &id_str: subscription_ids_c) { + jstring java_id_str = ctx->NewStringUTF(id_str.c_str()); + env->CallBooleanMethod(arrayList, addToListMID, java_id_str); + } + return arrayList; + } + ); + + if (ctx->ExceptionCheck()) { + return nullptr; + } + return result; } + extern "C" JNIEXPORT void JNICALL -Java_com_simplito_java_privmx_1endpoint_modules_thread_ThreadApi_subscribeForMessageEvents( +Java_com_simplito_java_privmx_1endpoint_modules_thread_ThreadApi_unsubscribeFrom( JNIEnv *env, jobject thiz, - jstring thread_id + jobject subscription_ids ) { JniContextUtils ctx(env); - if (ctx.nullCheck(thread_id, "Thread ID")) { + if (ctx.nullCheck(subscription_ids, "Subscription IDs")) { return; } - ctx.callVoidEndpointApi([&ctx, &thiz, &thread_id]() { - getThreadApi(ctx, thiz)->subscribeForMessageEvents( - ctx.jString2string(thread_id) - ); + + ctx.callVoidEndpointApi([&ctx, &env, &thiz, &subscription_ids]() { + auto subscription_ids_arr = ctx.jObject2jArray(subscription_ids); + auto subscription_ids_c = std::vector(); + + int length = ctx->GetArrayLength(subscription_ids_arr); + for (int i = 0; i < length; i++) { + jobject arrayElement = ctx->GetObjectArrayElement(subscription_ids_arr, i); + if (ctx.nullCheck(arrayElement, "Subscription ids array elements")) { + return; + } + subscription_ids_c.push_back(ctx.jString2string((jstring) arrayElement)); + } + + getThreadApi(ctx, thiz)->unsubscribeFrom(subscription_ids_c); }); } + + extern "C" -JNIEXPORT void JNICALL -Java_com_simplito_java_privmx_1endpoint_modules_thread_ThreadApi_unsubscribeFromMessageEvents( +JNIEXPORT jstring JNICALL +Java_com_simplito_java_privmx_1endpoint_modules_thread_ThreadApi_buildSubscriptionQuery( JNIEnv *env, jobject thiz, - jstring thread_id + jlong event_type, + jlong selector_type, + jstring selector_id ) { JniContextUtils ctx(env); - if (ctx.nullCheck(thread_id, "Thread ID")) { - return; + if (ctx.nullCheck(selector_id, "Selector ID")) { + return nullptr; } - ctx.callVoidEndpointApi([&ctx, &thiz, &thread_id]() { - getThreadApi(ctx, thiz)->unsubscribeFromMessageEvents( - ctx.jString2string(thread_id) - ); - }); + + jstring result; + ctx.callResultEndpointApi( + &result, + [&ctx, &env, &thiz, &event_type, &selector_type, &selector_id]() { + std::string query_result_c = getThreadApi(ctx, thiz)->buildSubscriptionQuery( + static_cast(event_type), + static_cast(selector_type), + ctx.jString2string(selector_id) + ); + return ctx->NewStringUTF(query_result_c.c_str()); + } + ); + if (ctx->ExceptionCheck()) { + return nullptr; + } + return result; } \ No newline at end of file diff --git a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventSelectorTypes/CustomEventSelectorType.java b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventSelectorTypes/CustomEventSelectorType.java new file mode 100644 index 00000000..8c5d71b3 --- /dev/null +++ b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventSelectorTypes/CustomEventSelectorType.java @@ -0,0 +1,14 @@ +package com.simplito.java.privmx_endpoint.model.events.eventSelectorTypes; + +/** + * Specifies the type of identifier used to select a custom event. + * This enum defines the possible types of selectors for custom events. + * + * @category event + */ +public enum CustomEventSelectorType implements EventSelectorType { + /** + * Selects events based on the ID of the context. + */ + CONTEXT_ID +} \ No newline at end of file diff --git a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventSelectorTypes/EventSelectorType.java b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventSelectorTypes/EventSelectorType.java new file mode 100644 index 00000000..2c1a1c9f --- /dev/null +++ b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventSelectorTypes/EventSelectorType.java @@ -0,0 +1,8 @@ +package com.simplito.java.privmx_endpoint.model.events.eventSelectorTypes; + +/** + * The base interface for enums specifying selector event types. + * + * @category core + */ +public interface EventSelectorType { } \ No newline at end of file diff --git a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventSelectorTypes/InboxEventSelectorType.java b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventSelectorTypes/InboxEventSelectorType.java new file mode 100644 index 00000000..4bc458f1 --- /dev/null +++ b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventSelectorTypes/InboxEventSelectorType.java @@ -0,0 +1,23 @@ +package com.simplito.java.privmx_endpoint.model.events.eventSelectorTypes; + +/** + * Specifies the type of identifier used to select an inbox event. + * Inbox events can be targeted based on different levels of granularity within the inbox structure. + * This enum defines the possible types of selectors for these events. + * + * @category inbox + */ +public enum InboxEventSelectorType implements EventSelectorType { + /** + * Selects events based on the ID of the context. + */ + CONTEXT_ID, + /** + * Selects events based on the ID of the inbox. + */ + INBOX_ID, + /** + * Selects events based on the ID of a specific entry. + */ + ENTRY_ID +} \ No newline at end of file diff --git a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventSelectorTypes/KvdbEventSelectorType.java b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventSelectorTypes/KvdbEventSelectorType.java new file mode 100644 index 00000000..041b6400 --- /dev/null +++ b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventSelectorTypes/KvdbEventSelectorType.java @@ -0,0 +1,20 @@ +package com.simplito.java.privmx_endpoint.model.events.eventSelectorTypes; + + +/** + * Specifies the type of identifier used to select a KVDB event. + * KVDB events can be targeted based on different levels of granularity within the KVDB structure. + * This enum defines the possible types of selectors for these events. + * + * @category kvdb + */ +public enum KvdbEventSelectorType implements EventSelectorType { + /** + * Selects events based on the ID of the context. + */ + CONTEXT_ID, + /** + * Selects events based on the ID of the KVDB. + */ + KVDB_ID +} diff --git a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventSelectorTypes/StoreEventSelectorType.java b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventSelectorTypes/StoreEventSelectorType.java new file mode 100644 index 00000000..382f3641 --- /dev/null +++ b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventSelectorTypes/StoreEventSelectorType.java @@ -0,0 +1,23 @@ +package com.simplito.java.privmx_endpoint.model.events.eventSelectorTypes; + +/** + * Specifies the type of identifier used to select a store event. + * Store events can be targeted based on different levels of granularity within the store structure. + * This enum defines the possible types of selectors for these events. + * + * @category store + */ +public enum StoreEventSelectorType implements EventSelectorType { + /** + * Selects events based on the ID of the context. + */ + CONTEXT_ID, + /** + * Selects events based on the ID of the store. + */ + STORE_ID, + /** + * Selects events based on the ID of a specific file. + */ + FILE_ID +} diff --git a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventSelectorTypes/ThreadEventSelectorType.java b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventSelectorTypes/ThreadEventSelectorType.java new file mode 100644 index 00000000..c5862603 --- /dev/null +++ b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventSelectorTypes/ThreadEventSelectorType.java @@ -0,0 +1,23 @@ +package com.simplito.java.privmx_endpoint.model.events.eventSelectorTypes; + +/** + * Specifies the type of identifier used to select a thread event. + * Thread events can be targeted based on different levels of granularity within the thread structure. + * This enum defines the possible types of selectors for these events. + * + * @category thread + */ +public enum ThreadEventSelectorType implements EventSelectorType { + /** + * Selects events based on the ID of the context. + */ + CONTEXT_ID, + /** + * Selects events based on the ID of the thread. + */ + THREAD_ID, + /** + * Selects events based on the ID of a specific message. + */ + MESSAGE_ID +} diff --git a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventTypes/EventType.java b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventTypes/EventType.java new file mode 100644 index 00000000..eab1bedf --- /dev/null +++ b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventTypes/EventType.java @@ -0,0 +1,9 @@ +package com.simplito.java.privmx_endpoint.model.events.eventTypes; + +/** + * The base interface for enums specifying event types. + * + * @category core + */ +public interface EventType { +} \ No newline at end of file diff --git a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventTypes/InboxEventType.java b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventTypes/InboxEventType.java new file mode 100644 index 00000000..8df4f3ae --- /dev/null +++ b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventTypes/InboxEventType.java @@ -0,0 +1,35 @@ +package com.simplito.java.privmx_endpoint.model.events.eventTypes; + +/** + * Defines the types of events that can occur within the inbox for which a client can subscribe. + * This enum lists the various actions or changes that can happen to + * inboxes and their entries, allowing observers to be notified of specific occurrences. + * + * @category inbox + */ +public enum InboxEventType implements EventType { + /** + * Type of event triggered when a new inbox is created. + */ + INBOX_CREATE, + /** + * Type of event triggered when an existing inbox is updated. + */ + INBOX_UPDATE, + /** + * Type of event triggered when an inbox is deleted. + */ + INBOX_DELETE, + /** + * Type of event triggered when a new entry is created within an inbox. + */ + ENTRY_CREATE, + /** + * Type of event triggered when a new entry is created within an inbox. + */ + ENTRY_DELETE, + /** + * Type of event triggered when a collection changes. + */ + COLLECTION_CHANGE +} \ No newline at end of file diff --git a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventTypes/KvdbEventType.java b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventTypes/KvdbEventType.java new file mode 100644 index 00000000..f9b2c2cb --- /dev/null +++ b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventTypes/KvdbEventType.java @@ -0,0 +1,43 @@ +package com.simplito.java.privmx_endpoint.model.events.eventTypes; + +/** + * Defines the types of events that can occur within the KVDB for which a client can subscribe. + * This enum lists the various actions or changes that can happen to + * KVDBs and their entries, allowing observers to be notified of specific occurrences. + * + * @category kvdb + */ +public enum KvdbEventType implements EventType { + /** + * Type of event triggered when a new KVDB is created. + */ + KVDB_CREATE, + /** + * Type of event triggered when an existing KVDB is updated. + */ + KVDB_UPDATE, + /** + * Type of event triggered when a KVDB is deleted. + */ + KVDB_DELETE, + /** + * Type of event triggered when a KVDB statistics are updated. + */ + KVDB_STATS, + /** + * Type of event triggered when a new entry is created within a KVDB. + */ + ENTRY_CREATE, + /** + * Type of event triggered when an existing KVDB entry is updated. + */ + ENTRY_UPDATE, + /** + * Type of event triggered when a KVDB entry is deleted. + */ + ENTRY_DELETE, + /** + * Type of event triggered when a collection changes. + */ + COLLECTION_CHANGE +} diff --git a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventTypes/StoreEventType.java b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventTypes/StoreEventType.java new file mode 100644 index 00000000..6d1dcbed --- /dev/null +++ b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventTypes/StoreEventType.java @@ -0,0 +1,43 @@ +package com.simplito.java.privmx_endpoint.model.events.eventTypes; + +/** + * Defines the types of events that can occur within the store for which a client can subscribe. + * This enum lists the various actions or changes that can happen to + * stores and their files, allowing observers to be notified of specific occurrences. + * + * @category store + */ +public enum StoreEventType implements EventType { + /** + * Type of event triggered when a new store is created. + */ + STORE_CREATE, + /** + * Type of event triggered when an existing store is updated. + */ + STORE_UPDATE, + /** + * Type of event triggered when a store is deleted. + */ + STORE_DELETE, + /** + * Type of event triggered when a store statistics are updated. + */ + STORE_STATS, + /** + * Type of event triggered when a new file is created within a store. + */ + FILE_CREATE, + /** + * Type of event triggered when an existing file is updated. + */ + FILE_UPDATE, + /** + * Type of event triggered when a file is deleted. + */ + FILE_DELETE, + /** + * Type of event triggered when a collection changes. + */ + COLLECTION_CHANGE +} diff --git a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventTypes/ThreadEventType.java b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventTypes/ThreadEventType.java new file mode 100644 index 00000000..161ead74 --- /dev/null +++ b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/model/events/eventTypes/ThreadEventType.java @@ -0,0 +1,43 @@ +package com.simplito.java.privmx_endpoint.model.events.eventTypes; + +/** + * Defines the types of events that can occur within the thread for which a client can subscribe. + * This enum lists the various actions or changes that can happen to + * threads and their messages, allowing observers to be notified of specific occurrences. + * + * @category thread + */ +public enum ThreadEventType implements EventType { + /** + * Type of event triggered when a new thread is created. + */ + THREAD_CREATE, + /** + * Type of event triggered when an existing thread is updated. + */ + THREAD_UPDATE, + /** + * Type of event triggered when a thread is deleted. + */ + THREAD_DELETE, + /** + * Type of event triggered when a thread statistics are updated. + */ + THREAD_STATS, + /** + * Type of event triggered when a new message is created within a thread. + */ + MESSAGE_CREATE, + /** + * Type of event triggered when an existing message is updated. + */ + MESSAGE_UPDATE, + /** + * Type of event triggered when a message is deleted. + */ + MESSAGE_DELETE, + /** + * Type of event triggered when a collection changes. + */ + COLLECTION_CHANGE +} diff --git a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/event/EventApi.java b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/event/EventApi.java index a53a43bd..2fd952e0 100644 --- a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/event/EventApi.java +++ b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/event/EventApi.java @@ -12,6 +12,8 @@ package com.simplito.java.privmx_endpoint.modules.event; import com.simplito.java.privmx_endpoint.model.UserWithPubKey; +import com.simplito.java.privmx_endpoint.model.events.ContextCustomEventData; +import com.simplito.java.privmx_endpoint.model.events.eventSelectorTypes.CustomEventSelectorType; import com.simplito.java.privmx_endpoint.model.exceptions.NativeException; import com.simplito.java.privmx_endpoint.model.exceptions.PrivmxException; import com.simplito.java.privmx_endpoint.modules.core.Connection; @@ -60,26 +62,42 @@ public EventApi(Connection connection) throws IllegalStateException { public native void emitEvent(String contextId, List users, String channelName, byte[] eventData) throws PrivmxException, NativeException, IllegalStateException; /** - * Subscribe for the custom events on the given channel. + * Subscribe for the custom events on the given subscription query. * - * @param contextId ID of the Context - * @param channelName name of the Channel + * @param subscriptionQueries list of queries + * @return list of subscriptionIds in matching order to subscriptionQueries * @throws IllegalStateException thrown when instance is closed. * @throws PrivmxException thrown when method encounters an exception. * @throws NativeException thrown when method encounters an unknown exception. */ - public native void subscribeForCustomEvents(String contextId, String channelName) throws PrivmxException, NativeException, IllegalStateException; + public native List subscribeFor(List subscriptionQueries) throws PrivmxException, NativeException, IllegalStateException; /** - * Unsubscribe from the custom events on the given channel. + * Unsubscribe from events for the given subscriptionId. * - * @param contextId ID of the Context - * @param channelName name of the Channel + * @param subscriptionIds list of subscriptionId * @throws IllegalStateException thrown when instance is closed. * @throws PrivmxException thrown when method encounters an exception. * @throws NativeException thrown when method encounters an unknown exception. */ - public native void unsubscribeFromCustomEvents(String contextId, String channelName) throws PrivmxException, NativeException, IllegalStateException; + public native void unsubscribeFrom(List subscriptionIds) throws PrivmxException, NativeException, IllegalStateException; + + private native String buildSubscriptionQuery(String channelName, long selectorType, String selectorId) throws PrivmxException, NativeException, IllegalStateException; + + /** + * Generate subscription Query for the custom events. + * + * @param channelName name of the Channel + * @param selectorType selector of scope on which you listen for events + * @param selectorId ID of the selector + * @return // todo - add return description + * @throws IllegalStateException thrown when instance is closed. + * @throws PrivmxException thrown when method encounters an exception. + * @throws NativeException thrown when method encounters an unknown exception. + */ + public String buildSubscriptionQuery(String channelName, CustomEventSelectorType selectorType, String selectorId) throws PrivmxException, NativeException, IllegalStateException { + return buildSubscriptionQuery(channelName, (long) selectorType.ordinal(), selectorId); + } /** * Frees memory. diff --git a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/inbox/InboxApi.java b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/inbox/InboxApi.java index 12dda844..5cf08227 100644 --- a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/inbox/InboxApi.java +++ b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/inbox/InboxApi.java @@ -18,8 +18,8 @@ import com.simplito.java.privmx_endpoint.model.InboxPublicView; import com.simplito.java.privmx_endpoint.model.PagingList; import com.simplito.java.privmx_endpoint.model.UserWithPubKey; -import com.simplito.java.privmx_endpoint.model.events.InboxDeletedEventData; -import com.simplito.java.privmx_endpoint.model.events.InboxEntryDeletedEventData; +import com.simplito.java.privmx_endpoint.model.events.eventSelectorTypes.InboxEventSelectorType; +import com.simplito.java.privmx_endpoint.model.events.eventTypes.InboxEventType; import com.simplito.java.privmx_endpoint.model.exceptions.NativeException; import com.simplito.java.privmx_endpoint.model.exceptions.PrivmxException; import com.simplito.java.privmx_endpoint.modules.core.Connection; @@ -680,42 +680,42 @@ public native void writeToFile( public native String closeFile(long fileHandle) throws PrivmxException, NativeException, IllegalStateException; /** - * Subscribes for the Inbox module main events. + * Subscribe for the Inbox events on the given subscription query. * - * @throws PrivmxException thrown when method encounters an exception. - * @throws NativeException thrown when method encounters an unknown exception. + * @param subscriptionQueries list of queries + * @return list of subscriptionIds in matching order to subscriptionQueries * @throws IllegalStateException thrown when instance is closed. - */ - public native void subscribeForInboxEvents() throws PrivmxException, NativeException, IllegalStateException; - - /** - * Subscribes for the Inbox module main events. - * * @throws PrivmxException thrown when method encounters an exception. * @throws NativeException thrown when method encounters an unknown exception. - * @throws IllegalStateException thrown when instance is closed. */ - public native void unsubscribeFromInboxEvents() throws PrivmxException, NativeException, IllegalStateException; + public native List subscribeFor(List subscriptionQueries) throws PrivmxException, NativeException, IllegalStateException; /** - * Subscribes for events in given Inbox. + * Unsubscribe from events with the given subscriptionId. * - * @param inboxId ID of the Inbox to subscribe + * @param subscriptionIds list of subscriptionId + * @throws IllegalStateException thrown when instance is closed. * @throws PrivmxException thrown when method encounters an exception. * @throws NativeException thrown when method encounters an unknown exception. - * @throws IllegalStateException thrown when instance is closed. */ - public native void subscribeForEntryEvents(String inboxId) throws PrivmxException, NativeException, IllegalStateException; + public native void unsubscribeFrom(List subscriptionIds) throws PrivmxException, NativeException, IllegalStateException; + + private native String buildSubscriptionQuery(long eventType, long selectorType, String selectorId) throws PrivmxException, NativeException, IllegalStateException; /** - * Unsubscribes from events in given Inbox. + * Generate subscription Query for the Inbox events. * - * @param inboxId ID of the Inbox to unsubscribe + * @param eventType type of event you listen for + * @param selectorType scope on which you listen for events + * @param selectorId ID of the selector + * @return // todo - add return description + * @throws IllegalStateException thrown when instance is closed. * @throws PrivmxException thrown when method encounters an exception. * @throws NativeException thrown when method encounters an unknown exception. - * @throws IllegalStateException thrown when instance is closed. */ - public native void unsubscribeFromEntryEvents(String inboxId) throws PrivmxException, NativeException, IllegalStateException; + public String buildSubscriptionQuery(InboxEventType eventType, InboxEventSelectorType selectorType, String selectorId) throws PrivmxException, NativeException, IllegalStateException { + return buildSubscriptionQuery((long) eventType.ordinal(), (long) selectorType.ordinal(), selectorId); + } /** * Frees memory. diff --git a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/kvdb/KvdbApi.java b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/kvdb/KvdbApi.java index ad53dd34..99b4d702 100644 --- a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/kvdb/KvdbApi.java +++ b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/kvdb/KvdbApi.java @@ -16,6 +16,8 @@ import com.simplito.java.privmx_endpoint.model.KvdbEntry; import com.simplito.java.privmx_endpoint.model.PagingList; import com.simplito.java.privmx_endpoint.model.UserWithPubKey; +import com.simplito.java.privmx_endpoint.model.events.eventSelectorTypes.KvdbEventSelectorType; +import com.simplito.java.privmx_endpoint.model.events.eventTypes.KvdbEventType; import com.simplito.java.privmx_endpoint.model.exceptions.NativeException; import com.simplito.java.privmx_endpoint.model.exceptions.PrivmxException; import com.simplito.java.privmx_endpoint.modules.core.Connection; @@ -573,42 +575,43 @@ public native Map deleteEntries( ) throws PrivmxException, NativeException, IllegalStateException; /** - * Subscribes for the KVDB module main events. + * Subscribe for the KVDB events on the given subscription query. * - * @throws PrivmxException thrown when method encounters an exception. - * @throws NativeException thrown when method encounters an unknown exception. + * @param subscriptionQueries list of queries + * @return list of subscriptionIds in matching order to subscriptionQueries * @throws IllegalStateException thrown when instance is closed. - */ - public native void subscribeForKvdbEvents() throws PrivmxException, NativeException, IllegalStateException; - - /** - * Unsubscribes from the KVDB module main events. - * * @throws PrivmxException thrown when method encounters an exception. * @throws NativeException thrown when method encounters an unknown exception. - * @throws IllegalStateException thrown when instance is closed. */ - public native void unsubscribeFromKvdbEvents() throws PrivmxException, NativeException, IllegalStateException; + public native List subscribeFor(List subscriptionQueries) throws PrivmxException, NativeException, IllegalStateException; /** - * Subscribes for events in given KVDB. + * Unsubscribe form events with the given subscriptionId. * - * @param kvdbId ID of the KVDB to subscribe + * @param subscriptionIds list of subscriptionId + * @throws IllegalStateException thrown when instance is closed. * @throws PrivmxException thrown when method encounters an exception. * @throws NativeException thrown when method encounters an unknown exception. - * @throws IllegalStateException thrown when instance is closed. */ - public native void subscribeForEntryEvents(String kvdbId) throws PrivmxException, NativeException, IllegalStateException; + public native void unsubscribeFrom(List subscriptionIds) throws PrivmxException, NativeException, IllegalStateException; + + private native String buildSubscriptionQuery(long eventType, long selectorType, String selectorId) throws PrivmxException, NativeException, IllegalStateException; + /** - * Unsubscribes from events in given KVDB. + * Generate subscription Query for the KVDB events. * - * @param kvdbId ID of the KVDB to unsubscribe + * @param eventType type of event you listen for + * @param selectorType scope on which you listen for events + * @param selectorId ID of the selector + * @return // todo - add return description + * @throws IllegalStateException thrown when instance is closed. * @throws PrivmxException thrown when method encounters an exception. * @throws NativeException thrown when method encounters an unknown exception. - * @throws IllegalStateException thrown when instance is closed. */ - public native void unsubscribeFromEntryEvents(String kvdbId) throws PrivmxException, NativeException, IllegalStateException; + public String buildSubscriptionQuery(KvdbEventType eventType, KvdbEventSelectorType selectorType, String selectorId) throws PrivmxException, NativeException, IllegalStateException { + return buildSubscriptionQuery((long) eventType.ordinal(), (long) selectorType.ordinal(), selectorId); + } /** * Frees memory. diff --git a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/store/StoreApi.java b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/store/StoreApi.java index 754c71d2..f5e39637 100644 --- a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/store/StoreApi.java +++ b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/store/StoreApi.java @@ -17,6 +17,8 @@ import com.simplito.java.privmx_endpoint.model.Store; import com.simplito.java.privmx_endpoint.model.UserWithPubKey; import com.simplito.java.privmx_endpoint.model.events.StoreDeletedEventData; +import com.simplito.java.privmx_endpoint.model.events.eventSelectorTypes.StoreEventSelectorType; +import com.simplito.java.privmx_endpoint.model.events.eventTypes.StoreEventType; import com.simplito.java.privmx_endpoint.model.events.StoreFileDeletedEventData; import com.simplito.java.privmx_endpoint.model.events.StoreStatsChangedEventData; import com.simplito.java.privmx_endpoint.model.exceptions.NativeException; @@ -486,44 +488,43 @@ public PagingList listFiles(String storeId, long skip, long limit, String */ public native String closeFile(long fileHandle) throws PrivmxException, NativeException, IllegalStateException; - /** - * Subscribes for the Store module main events. + * Subscribe for the Store events on the given subscription query. * + * @param subscriptionQueries list of queries + * @return list of subscriptionIds in matching order to subscriptionQueries * @throws IllegalStateException thrown when instance is closed. * @throws PrivmxException thrown when method encounters an exception. * @throws NativeException thrown when method encounters an unknown exception. */ - public native void subscribeForStoreEvents() throws PrivmxException, NativeException, IllegalStateException; + public native List subscribeFor(List subscriptionQueries) throws PrivmxException, NativeException, IllegalStateException; /** - * Unsubscribes from the Store module main events. + * Unsubscribe from events with the given subscriptionId. * + * @param subscriptionIds list of subscriptionId * @throws IllegalStateException thrown when instance is closed. * @throws PrivmxException thrown when method encounters an exception. * @throws NativeException thrown when method encounters an unknown exception. */ - public native void unsubscribeFromStoreEvents() throws PrivmxException, NativeException, IllegalStateException; + public native void unsubscribeFrom(List subscriptionIds) throws PrivmxException, NativeException, IllegalStateException; - /** - * Subscribes for events in given Store. - * - * @param storeId ID of the Store to subscribe - * @throws IllegalStateException thrown when instance is closed. - * @throws PrivmxException thrown when method encounters an exception. - * @throws NativeException thrown when method encounters an unknown exception. - */ - public native void subscribeForFileEvents(String storeId) throws PrivmxException, NativeException, IllegalStateException; + private native String buildSubscriptionQuery(long eventType, long selectorType, String selectorId) throws PrivmxException, NativeException, IllegalStateException; /** - * Unsubscribes from events in given Store. + * Generate subscription Query for the Store events. * - * @param storeId ID of the {@code Store} to unsubscribe + * @param eventType type of event you listen for + * @param selectorType scope on which you listen for events + * @param selectorId ID of the selector + * @return // todo - add return description * @throws IllegalStateException thrown when instance is closed. * @throws PrivmxException thrown when method encounters an exception. * @throws NativeException thrown when method encounters an unknown exception. */ - public native void unsubscribeFromFileEvents(String storeId) throws PrivmxException, NativeException, IllegalStateException; + public String buildSubscriptionQuery(StoreEventType eventType, StoreEventSelectorType selectorType, String selectorId) throws PrivmxException, NativeException, IllegalStateException { + return buildSubscriptionQuery((long) eventType.ordinal(), (long) selectorType.ordinal(), selectorId); + } /** * Synchronize file handle data with newest data on server diff --git a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/thread/ThreadApi.java b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/thread/ThreadApi.java index 35daf215..1f64d49f 100644 --- a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/thread/ThreadApi.java +++ b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/thread/ThreadApi.java @@ -19,6 +19,8 @@ import com.simplito.java.privmx_endpoint.model.events.ThreadDeletedEventData; import com.simplito.java.privmx_endpoint.model.events.ThreadDeletedMessageEventData; import com.simplito.java.privmx_endpoint.model.events.ThreadStatsEventData; +import com.simplito.java.privmx_endpoint.model.events.eventSelectorTypes.ThreadEventSelectorType; +import com.simplito.java.privmx_endpoint.model.events.eventTypes.ThreadEventType; import com.simplito.java.privmx_endpoint.model.exceptions.NativeException; import com.simplito.java.privmx_endpoint.model.exceptions.PrivmxException; import com.simplito.java.privmx_endpoint.modules.core.Connection; @@ -403,42 +405,42 @@ public PagingList listMessages(String threadId, long skip, long limit, public native void updateMessage(String messageId, byte[] publicMeta, byte[] privateMeta, byte[] data) throws PrivmxException, NativeException, IllegalStateException; /** - * Subscribes for the Thread module main events. + * Subscribe for the Thread events on the given subscription query. * + * @param subscriptionQueries list of queries + * @return list of subscriptionIds in matching order to subscriptionQueries * @throws IllegalStateException thrown when instance is closed. * @throws PrivmxException thrown when method encounters an exception. * @throws NativeException thrown when method encounters an unknown exception. */ - public native void subscribeForThreadEvents() throws PrivmxException, NativeException, IllegalStateException; + public native List subscribeFor(List subscriptionQueries) throws PrivmxException, NativeException, IllegalStateException; /** - * Unsubscribes from the Thread module main events. + * Unsubscribe from events with the given subscriptionId. * + * @param subscriptionIds list of subscriptionId * @throws IllegalStateException thrown when instance is closed. * @throws PrivmxException thrown when method encounters an exception. * @throws NativeException thrown when method encounters an unknown exception. */ - public native void unsubscribeFromThreadEvents() throws PrivmxException, NativeException, IllegalStateException; + public native void unsubscribeFrom(List subscriptionIds) throws PrivmxException, NativeException, IllegalStateException; - /** - * Subscribes for events in given Thread. - * - * @param threadId ID of the Thread to subscribe - * @throws IllegalStateException thrown when instance is closed. - * @throws PrivmxException thrown when method encounters an exception. - * @throws NativeException thrown when method encounters an unknown exception. - */ - public native void subscribeForMessageEvents(String threadId) throws PrivmxException, NativeException, IllegalStateException; + private native String buildSubscriptionQuery(long eventType, long selectorType, String selectorId) throws PrivmxException, NativeException, IllegalStateException; /** - * Unsubscribes from events in given Thread. + * Generate subscription Query for the Thread events. * - * @param threadId ID of the Thread to unsubscribe + * @param eventType type of event you listen for + * @param selectorType scope on which you listen for events + * @param selectorId ID of the selector + * @return // todo - add return description * @throws IllegalStateException thrown when instance is closed. * @throws PrivmxException thrown when method encounters an exception. * @throws NativeException thrown when method encounters an unknown exception. */ - public native void unsubscribeFromMessageEvents(String threadId) throws PrivmxException, NativeException, IllegalStateException; + public String buildSubscriptionQuery(ThreadEventType eventType, ThreadEventSelectorType selectorType, String selectorId) throws PrivmxException, NativeException, IllegalStateException { + return buildSubscriptionQuery((long) eventType.ordinal(), (long) selectorType.ordinal(), selectorId); + } /** * Frees memory.