Preserve Android feedback state and supplementary Unicode characters
This commit is contained in:
1 parent
1d05ff34c6
commit
8dc7595e46
2 files changed
+16
-1
No files matched your search
@@ -1249,6 +1249,7 @@ class ChatViewModel : ViewModel() {
|
||||
r.sendMessage(ch.id, text)
|
||||
viewModelScope.launch {
|
||||
_messages.value = withContext(Dispatchers.IO) { r.getMessages(ch.id) }
|
||||
.map { it.copy(feedback = feedbackCache[it.messageId]) }
|
||||
refreshChannels()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user