|
|
|
|
@ -21,6 +21,7 @@
|
|
|
|
|
#include "../../../src/radio/radio.h" |
|
|
|
|
#include "../../../src/radio/radio_audio.h" |
|
|
|
|
#include "../../../src/dm/dm_core.h" |
|
|
|
|
#include "../../../src/dm/dm_media.h" |
|
|
|
|
#include "../../../lib/debug_config.h" |
|
|
|
|
#include "../../../lib/u_async.h" |
|
|
|
|
#include "../../../lib/mem.h" |
|
|
|
|
@ -639,28 +640,38 @@ void utun_bridge_dm_send(const char* conv_id, const char* text) {
|
|
|
|
|
uasync_post(ua, dm_send_trampoline, req); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char* utun_bridge_dm_list_conversations_json(void) { |
|
|
|
|
struct UTUN_INSTANCE* inst = instance_lite_get_instance(); |
|
|
|
|
char buf[16384]; size_t len = 0; |
|
|
|
|
if (!inst || dm_list_conversations_json(inst, buf, sizeof(buf), &len) < 0) |
|
|
|
|
return u_strdup("[]"); |
|
|
|
|
return u_strdup(buf); |
|
|
|
|
void utun_bridge_dm_request_conversations(void) { |
|
|
|
|
struct UASYNC* ua = instance_lite_get_uasync(); |
|
|
|
|
if (!uasync_is_running(ua)) { bridge_log(BLEV_WARN, "DM conversations: core stopped"); return; } |
|
|
|
|
struct dm_conversations_req* req = u_calloc(1, sizeof(*req)); |
|
|
|
|
if (!req) { bridge_log(BLEV_ERROR, "DM conversations: OOM"); return; } |
|
|
|
|
req->inst = instance_lite_get_instance(); |
|
|
|
|
uasync_post(ua, dm_conversations_trampoline, req); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char* utun_bridge_dm_list_messages_json(const char* conv_id, int count, int offset) { |
|
|
|
|
struct UTUN_INSTANCE* inst = instance_lite_get_instance(); |
|
|
|
|
if (!inst || !conv_id || !conv_id[0]) return u_strdup("[]"); |
|
|
|
|
size_t cap = 262144; |
|
|
|
|
char* buf = u_malloc(cap); |
|
|
|
|
if (!buf) { bridge_log(BLEV_ERROR, "dm_list_messages: OOM"); return u_strdup("[]"); } |
|
|
|
|
size_t len = 0; |
|
|
|
|
if (dm_list_messages_json(inst, conv_id, count, offset, buf, cap, &len) < 0) { |
|
|
|
|
u_free(buf); |
|
|
|
|
return u_strdup("[]"); |
|
|
|
|
void utun_bridge_dm_request_messages(const char* conv_id) { |
|
|
|
|
struct UASYNC* ua = instance_lite_get_uasync(); |
|
|
|
|
if (!conv_id || !conv_id[0] || !uasync_is_running(ua)) { bridge_log(BLEV_WARN, "DM history: invalid request/core stopped"); return; } |
|
|
|
|
struct dm_messages_req* req = u_calloc(1, sizeof(*req)); |
|
|
|
|
if (!req) { bridge_log(BLEV_ERROR, "DM history: OOM"); return; } |
|
|
|
|
req->inst = instance_lite_get_instance(); |
|
|
|
|
snprintf(req->conv_id, sizeof(req->conv_id), "%s", conv_id); |
|
|
|
|
uasync_post(ua, dm_messages_trampoline, req); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void utun_bridge_dm_send_file(const char* conv_id, const char* path, const char* name) { |
|
|
|
|
struct UASYNC* ua = instance_lite_get_uasync(); |
|
|
|
|
if (!conv_id || !path || !name || !uasync_is_running(ua)) { bridge_log(BLEV_WARN, "DM file: invalid request/core stopped"); return; } |
|
|
|
|
struct dm_file_req* req = u_calloc(1, sizeof(*req)); |
|
|
|
|
if (!req) { bridge_log(BLEV_ERROR, "DM file: OOM"); return; } |
|
|
|
|
if (strlen(conv_id) >= sizeof(req->conv) || strlen(path) >= sizeof(req->path) || strlen(name) >= sizeof(req->name)) { |
|
|
|
|
bridge_log(BLEV_ERROR, "DM file: path, conversation or name too long"); u_free(req); return; |
|
|
|
|
} |
|
|
|
|
char* out = u_strdup(buf); |
|
|
|
|
u_free(buf); |
|
|
|
|
return out; |
|
|
|
|
req->inst = instance_lite_get_instance(); |
|
|
|
|
snprintf(req->conv, sizeof(req->conv), "%s", conv_id); |
|
|
|
|
snprintf(req->path, sizeof(req->path), "%s", path); |
|
|
|
|
snprintf(req->name, sizeof(req->name), "%s", name); |
|
|
|
|
uasync_post(ua, dm_send_file_trampoline, req); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void utun_bridge_set_debug_level(const char* category, const char* level) { |
|
|
|
|
@ -1887,24 +1898,30 @@ JNIEXPORT void JNICALL Java_com_utun_chat_data_NativeLib_nativeDmSend(
|
|
|
|
|
if (c) (*env)->ReleaseStringUTFChars(env, convId, c); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
JNIEXPORT jstring JNICALL Java_com_utun_chat_data_NativeLib_nativeDmListConversations( |
|
|
|
|
JNIEXPORT void JNICALL Java_com_utun_chat_data_NativeLib_nativeDmRequestConversations( |
|
|
|
|
JNIEnv* env, jobject thiz) { |
|
|
|
|
(void)env; (void)thiz; |
|
|
|
|
utun_bridge_dm_request_conversations(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_com_utun_chat_data_NativeLib_nativeDmRequestMessages( |
|
|
|
|
JNIEnv* env, jobject thiz, jstring convId) { |
|
|
|
|
(void)thiz; |
|
|
|
|
char* json = utun_bridge_dm_list_conversations_json(); |
|
|
|
|
jstring result = (*env)->NewStringUTF(env, json); |
|
|
|
|
u_free(json); |
|
|
|
|
return result; |
|
|
|
|
const char* c = (*env)->GetStringUTFChars(env, convId, NULL); |
|
|
|
|
utun_bridge_dm_request_messages(c); |
|
|
|
|
if (c) (*env)->ReleaseStringUTFChars(env, convId, c); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
JNIEXPORT jstring JNICALL Java_com_utun_chat_data_NativeLib_nativeDmListMessages( |
|
|
|
|
JNIEnv* env, jobject thiz, jstring convId, jint count, jint offset) { |
|
|
|
|
JNIEXPORT void JNICALL Java_com_utun_chat_data_NativeLib_nativeDmSendFile( |
|
|
|
|
JNIEnv* env, jobject thiz, jstring convId, jstring path, jstring name) { |
|
|
|
|
(void)thiz; |
|
|
|
|
const char* c = (*env)->GetStringUTFChars(env, convId, NULL); |
|
|
|
|
char* json = utun_bridge_dm_list_messages_json(c, (int)count, (int)offset); |
|
|
|
|
jstring result = (*env)->NewStringUTF(env, json); |
|
|
|
|
u_free(json); |
|
|
|
|
const char* p = (*env)->GetStringUTFChars(env, path, NULL); |
|
|
|
|
const char* n = (*env)->GetStringUTFChars(env, name, NULL); |
|
|
|
|
utun_bridge_dm_send_file(c, p, n); |
|
|
|
|
if (n) (*env)->ReleaseStringUTFChars(env, name, n); |
|
|
|
|
if (p) (*env)->ReleaseStringUTFChars(env, path, p); |
|
|
|
|
if (c) (*env)->ReleaseStringUTFChars(env, convId, c); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
JNIEXPORT jlong JNICALL Java_com_utun_chat_data_NativeLib_nativeGetMyNodeId( |
|
|
|
|
|