Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3381674
D13188.id43873.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D13188.id43873.diff
View Options
diff --git a/native/android/app/src/cpp/CommMMKV.cpp b/native/android/app/src/cpp/CommMMKV.cpp
--- a/native/android/app/src/cpp/CommMMKV.cpp
+++ b/native/android/app/src/cpp/CommMMKV.cpp
@@ -125,6 +125,22 @@
return result;
}
+
+ static bool
+ setStringSet(std::string key, const std::vector<std::string> &elements) {
+ static const auto cls = javaClassStatic();
+ static auto method = cls->getStaticMethod<jboolean(
+ std::string, local_ref<JArrayClass<JString>>)>("setStringSet");
+
+ local_ref<JArrayClass<JString>> elementsJava =
+ JArrayClass<JString>::newArray(elements.size());
+
+ for (int i = 0; i < elements.size(); i++) {
+ elementsJava->setElement(i, *make_jstring(elements[i]));
+ }
+
+ return method(cls, key, elementsJava);
+ }
};
namespace comm {
@@ -206,4 +222,13 @@
[&]() { result = CommMMKVJavaClass::getStringSet(setKey); });
return result;
}
+
+bool CommMMKV::setStringSet(
+ std::string key,
+ const std::vector<std::string> &elements) {
+ bool result;
+ NativeAndroidAccessProvider::runTask(
+ [&]() { result = CommMMKVJavaClass::setStringSet(key, elements); });
+ return result;
+}
} // namespace comm
diff --git a/native/android/app/src/main/java/app/comm/android/fbjni/CommMMKV.java b/native/android/app/src/main/java/app/comm/android/fbjni/CommMMKV.java
--- a/native/android/app/src/main/java/app/comm/android/fbjni/CommMMKV.java
+++ b/native/android/app/src/main/java/app/comm/android/fbjni/CommMMKV.java
@@ -180,4 +180,11 @@
return stringSet.toArray(new String[stringSet.size()]);
}
+
+ public static boolean setStringSet(String key, String[] elements) {
+ initialize();
+ Set<String> stringSet = Set.of(elements);
+ return getMMKVInstance(mmkvIdentifier, mmkvEncryptionKey)
+ .encode(key, stringSet);
+ }
}
diff --git a/native/cpp/CommonCpp/Tools/CommMMKV.h b/native/cpp/CommonCpp/Tools/CommMMKV.h
--- a/native/cpp/CommonCpp/Tools/CommMMKV.h
+++ b/native/cpp/CommonCpp/Tools/CommMMKV.h
@@ -31,6 +31,8 @@
static void
removeElementFromStringSet(std::string setKey, std::string element);
static std::vector<std::string> getStringSet(std::string setKey);
+ static bool
+ setStringSet(std::string key, const std::vector<std::string> &elements);
class InitFromNSEForbiddenError : public std::runtime_error {
public:
diff --git a/native/ios/Comm/CommMMKV.mm b/native/ios/Comm/CommMMKV.mm
--- a/native/ios/Comm/CommMMKV.mm
+++ b/native/ios/Comm/CommMMKV.mm
@@ -270,4 +270,26 @@
return stringSetCpp;
}
+bool CommMMKV::setStringSet(
+ std::string key,
+ const std::vector<std::string> &elements) {
+ CommMMKV::initialize();
+ NSString *keyObjC = [NSString stringWithCString:key.c_str()
+ encoding:NSUTF8StringEncoding];
+
+ NSMutableSet *stringSet = [[NSMutableSet alloc] init];
+ for (const auto &element : elements) {
+ [stringSet addObject:[NSString stringWithCString:element.c_str()
+ encoding:NSUTF8StringEncoding]];
+ }
+
+ MMKV *mmkv = getMMKVInstance(mmkvIdentifier, mmkvEncryptionKey);
+ BOOL result = [mmkv setObject:stringSet forKey:keyObjC];
+
+ if (!result) {
+ Logger::log("Attempt to write in background or failure during write.");
+ }
+ return result;
+}
+
} // namespace comm
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 29, 5:48 AM (18 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2595631
Default Alt Text
D13188.id43873.diff (3 KB)
Attached To
Mode
D13188: Add method to set entire sttring set at once in MMKV
Attached
Detach File
Event Timeline
Log In to Comment