android: carry channel reply references through file and photo sends
This commit is contained in:
1 parent
4463f8870a
commit
721160fbd9
4 files changed
+28
-10
No files matched your search
@@ -12,14 +12,15 @@
|
||||
#include <unistd.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) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "attachment_send: invalid args");
|
||||
return -1;
|
||||
}
|
||||
|
||||
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 */
|
||||
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];
|
||||
if (media_dir[i] == '/' && off > 1) { tmp[off] = '\0'; mkdir(tmp, 0755); }
|
||||
}
|
||||
tmp[off] = '\0';
|
||||
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|..." */
|
||||
size_t datalen = strlen(original_basename);
|
||||
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();
|
||||
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->content_type, sizeof(req->content_type), "application/octet-stream");
|
||||
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",
|
||||
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;
|
||||
}
|
||||
@@ -3,12 +3,14 @@
|
||||
* 0 = запрос поставлен в uasync, -1 = отказ подготовки. Исходный файл нужен до завершения media-задачи. */
|
||||
#ifndef ATTACHMENT_SENDER_H
|
||||
#define ATTACHMENT_SENDER_H
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#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
|
||||
}
|
||||
|
||||
@@ -14,14 +14,14 @@
|
||||
#include <libgen.h>
|
||||
|
||||
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) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "photo_send: invalid args");
|
||||
return -1;
|
||||
}
|
||||
|
||||
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));
|
||||
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];
|
||||
if (media_dir[i] == '/' && off > 1) { tmp[off] = '\0'; mkdir(tmp, 0755); }
|
||||
}
|
||||
tmp[off] = '\0';
|
||||
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);
|
||||
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();
|
||||
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->content_type, sizeof(req->content_type), "%s", content_type);
|
||||
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,
|
||||
(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;
|
||||
}
|
||||
@@ -3,13 +3,14 @@
|
||||
* 0 = запрос поставлен в uasync, -1 = отказ. src_file_path должен существовать до завершения задачи. */
|
||||
#ifndef PHOTO_SENDER_H
|
||||
#define PHOTO_SENDER_H
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user