Browse Source

android: carry channel reply references through file and photo sends

master
evgeny 4 days ago
parent
commit
721160fbd9
  1. 16
      tools/chatgui-android/libutun_lite/attachment_sender.c
  2. 4
      tools/chatgui-android/libutun_lite/attachment_sender.h
  3. 15
      tools/chatgui-android/libutun_lite/photo_sender.c
  4. 3
      tools/chatgui-android/libutun_lite/photo_sender.h

16
tools/chatgui-android/libutun_lite/attachment_sender.c

@ -12,14 +12,15 @@
#include <unistd.h> #include <unistd.h>
#include <libgen.h> #include <libgen.h>
int attachment_send(const char* channel_id, const char* src_file_path, const char* db_path) { int attachment_send(const char* channel_id, const char* src_file_path, const char* db_path,
const uint8_t reply_to[32], uint64_t request_id) {
if (!channel_id || !src_file_path || !db_path) { if (!channel_id || !src_file_path || !db_path) {
DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "attachment_send: invalid args"); DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "attachment_send: invalid args");
return -1; return -1;
} }
struct UASYNC* ua = instance_lite_get_uasync(); struct UASYNC* ua = instance_lite_get_uasync();
if (!ua) { DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "attachment_send: no uasync"); return -1; } if (!uasync_is_running(ua)) { DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "attachment_send: core stopped"); return -1; }
/* get original basename for display, then make unique filename for storage */ /* get original basename for display, then make unique filename for storage */
char path_copy[1024]; char path_copy[1024];
@ -52,6 +53,7 @@ int attachment_send(const char* channel_id, const char* src_file_path, const cha
tmp[off++] = media_dir[i]; tmp[off++] = media_dir[i];
if (media_dir[i] == '/' && off > 1) { tmp[off] = '\0'; mkdir(tmp, 0755); } if (media_dir[i] == '/' && off > 1) { tmp[off] = '\0'; mkdir(tmp, 0755); }
} }
tmp[off] = '\0';
mkdir(tmp, 0755); mkdir(tmp, 0755);
} }
@ -64,9 +66,14 @@ int attachment_send(const char* channel_id, const char* src_file_path, const cha
data = original_basename — becomes first part of message "d" field: "name.ext|size|..." */ data = original_basename — becomes first part of message "d" field: "name.ext|size|..." */
size_t datalen = strlen(original_basename); size_t datalen = strlen(original_basename);
struct chat_msg_submit* req = u_calloc(1, sizeof(struct chat_msg_submit) + datalen + 1); struct chat_msg_submit* req = u_calloc(1, sizeof(struct chat_msg_submit) + datalen + 1);
if (!req) return -1; struct posted_task* post = u_calloc(1, sizeof(*post));
if (!req || !post) {
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "attachment_send: allocation failed"); u_free(req); u_free(post); return -1;
}
req->inst = instance_lite_get_instance(); req->inst = instance_lite_get_instance();
memcpy(req->reply_to, reply_to, sizeof(req->reply_to));
req->request_id = request_id;
snprintf(req->channel_id, sizeof(req->channel_id), "%s", channel_id); snprintf(req->channel_id, sizeof(req->channel_id), "%s", channel_id);
snprintf(req->content_type, sizeof(req->content_type), "application/octet-stream"); snprintf(req->content_type, sizeof(req->content_type), "application/octet-stream");
snprintf(req->media_src, sizeof(req->media_src), "%s", src_file_path); snprintf(req->media_src, sizeof(req->media_src), "%s", src_file_path);
@ -80,6 +87,7 @@ int attachment_send(const char* channel_id, const char* src_file_path, const cha
DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "attachment_send: ch=%s src=%s dst=%s name=%s size=%lld", DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "attachment_send: ch=%s src=%s dst=%s name=%s size=%lld",
channel_id, src_file_path, media_file, original_basename, (long long)st.st_size); channel_id, src_file_path, media_file, original_basename, (long long)st.st_size);
uasync_post(ua, chat_core_submit_trampoline, req); post->callback = chat_core_submit_trampoline; post->arg = req;
uasync_post_reserved(ua, post);
return 0; return 0;
} }

4
tools/chatgui-android/libutun_lite/attachment_sender.h

@ -3,12 +3,14 @@
* 0 = запрос поставлен в uasync, -1 = отказ подготовки. Исходный файл нужен до завершения media-задачи. */ * 0 = запрос поставлен в uasync, -1 = отказ подготовки. Исходный файл нужен до завершения media-задачи. */
#ifndef ATTACHMENT_SENDER_H #ifndef ATTACHMENT_SENDER_H
#define ATTACHMENT_SENDER_H #define ATTACHMENT_SENDER_H
#include <stdint.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
int attachment_send(const char* channel_id, const char* src_file_path, const char* db_path); int attachment_send(const char* channel_id, const char* src_file_path, const char* db_path,
const uint8_t reply_to[32], uint64_t request_id);
#ifdef __cplusplus #ifdef __cplusplus
} }

15
tools/chatgui-android/libutun_lite/photo_sender.c

@ -14,14 +14,14 @@
#include <libgen.h> #include <libgen.h>
int photo_send(const char* channel_id, const char* src_file_path, const char* db_path, int photo_send(const char* channel_id, const char* src_file_path, const char* db_path,
int width, int height) { int width, int height, const uint8_t reply_to[32], uint64_t request_id) {
if (!channel_id || !src_file_path || !db_path) { if (!channel_id || !src_file_path || !db_path) {
DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "photo_send: invalid args"); DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "photo_send: invalid args");
return -1; return -1;
} }
struct UASYNC* ua = instance_lite_get_uasync(); struct UASYNC* ua = instance_lite_get_uasync();
if (!ua) { DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "photo_send: no uasync"); return -1; } if (!uasync_is_running(ua)) { DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "photo_send: core stopped"); return -1; }
struct stat st; memset(&st, 0, sizeof(st)); struct stat st; memset(&st, 0, sizeof(st));
if (stat(src_file_path, &st) != 0 || st.st_size <= 0) { if (stat(src_file_path, &st) != 0 || st.st_size <= 0) {
@ -64,6 +64,7 @@ int photo_send(const char* channel_id, const char* src_file_path, const char* db
tmp[off++] = media_dir[i]; tmp[off++] = media_dir[i];
if (media_dir[i] == '/' && off > 1) { tmp[off] = '\0'; mkdir(tmp, 0755); } if (media_dir[i] == '/' && off > 1) { tmp[off] = '\0'; mkdir(tmp, 0755); }
} }
tmp[off] = '\0';
mkdir(tmp, 0755); mkdir(tmp, 0755);
} }
@ -72,9 +73,14 @@ int photo_send(const char* channel_id, const char* src_file_path, const char* db
size_t datalen = strlen(original_basename); size_t datalen = strlen(original_basename);
struct chat_msg_submit* req = u_calloc(1, sizeof(struct chat_msg_submit) + datalen + 1); struct chat_msg_submit* req = u_calloc(1, sizeof(struct chat_msg_submit) + datalen + 1);
if (!req) return -1; struct posted_task* post = u_calloc(1, sizeof(*post));
if (!req || !post) {
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "photo_send: allocation failed"); u_free(req); u_free(post); return -1;
}
req->inst = instance_lite_get_instance(); req->inst = instance_lite_get_instance();
memcpy(req->reply_to, reply_to, sizeof(req->reply_to));
req->request_id = request_id;
snprintf(req->channel_id, sizeof(req->channel_id), "%s", channel_id); snprintf(req->channel_id, sizeof(req->channel_id), "%s", channel_id);
snprintf(req->content_type, sizeof(req->content_type), "%s", content_type); snprintf(req->content_type, sizeof(req->content_type), "%s", content_type);
snprintf(req->media_src, sizeof(req->media_src), "%s", src_file_path); snprintf(req->media_src, sizeof(req->media_src), "%s", src_file_path);
@ -92,6 +98,7 @@ int photo_send(const char* channel_id, const char* src_file_path, const char* db
channel_id, content_type, src_file_path, media_file, original_basename, channel_id, content_type, src_file_path, media_file, original_basename,
(long long)st.st_size, width, height); (long long)st.st_size, width, height);
uasync_post(ua, chat_core_submit_trampoline, req); post->callback = chat_core_submit_trampoline; post->arg = req;
uasync_post_reserved(ua, post);
return 0; return 0;
} }

3
tools/chatgui-android/libutun_lite/photo_sender.h

@ -3,13 +3,14 @@
* 0 = запрос поставлен в uasync, -1 = отказ. src_file_path должен существовать до завершения задачи. */ * 0 = запрос поставлен в uasync, -1 = отказ. src_file_path должен существовать до завершения задачи. */
#ifndef PHOTO_SENDER_H #ifndef PHOTO_SENDER_H
#define PHOTO_SENDER_H #define PHOTO_SENDER_H
#include <stdint.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
int photo_send(const char* channel_id, const char* src_file_path, const char* db_path, int photo_send(const char* channel_id, const char* src_file_path, const char* db_path,
int width, int height); int width, int height, const uint8_t reply_to[32], uint64_t request_id);
#ifdef __cplusplus #ifdef __cplusplus
} }

Loading…
Cancel
Save