|
|
|
|
@ -1923,7 +1923,21 @@ JNIEXPORT jstring JNICALL Java_com_utun_chat_data_NativeLib_nativeGetMessages(
|
|
|
|
|
(void)thiz; |
|
|
|
|
const char* ch = (*env)->GetStringUTFChars(env, channelId, NULL); |
|
|
|
|
char* json = utun_bridge_get_messages_json(ch, (int)limit); |
|
|
|
|
jstring result = (*env)->NewStringUTF(env, json); |
|
|
|
|
/* String(byte[], UTF-8) корректно восстанавливает четырёхбайтовые emoji. */ |
|
|
|
|
jclass strings = (*env)->FindClass(env, "java/lang/String"); |
|
|
|
|
jmethodID constructor = strings ? (*env)->GetMethodID(env, strings, "<init>", "([BLjava/lang/String;)V") : NULL; |
|
|
|
|
size_t bytes = json ? strlen(json) : 0; |
|
|
|
|
jbyteArray data = (*env)->NewByteArray(env, (jsize)bytes); |
|
|
|
|
jstring charset = (*env)->NewStringUTF(env, "UTF-8"); |
|
|
|
|
jstring result = NULL; |
|
|
|
|
if (constructor && data && charset) { |
|
|
|
|
(*env)->SetByteArrayRegion(env, data, 0, (jsize)bytes, (const jbyte*)json); |
|
|
|
|
if (!(*env)->ExceptionCheck(env)) result = (jstring)(*env)->NewObject(env, strings, constructor, data, charset); |
|
|
|
|
} |
|
|
|
|
if (!result) DEBUG_ERROR(DEBUG_CATEGORY_CHAT, "bridge: UTF-8 message result allocation failed"); |
|
|
|
|
if (data) (*env)->DeleteLocalRef(env, data); |
|
|
|
|
if (charset) (*env)->DeleteLocalRef(env, charset); |
|
|
|
|
if (strings) (*env)->DeleteLocalRef(env, strings); |
|
|
|
|
u_free(json); |
|
|
|
|
(*env)->ReleaseStringUTFChars(env, channelId, ch); |
|
|
|
|
return result; |
|
|
|
|
|