Browse Source

Dispatch Qt attachments using the target captured by the composer

master
evgeny 3 days ago
parent
commit
4f76b4d765
  1. 1
      src/media_async/attachment_send.c
  2. 74
      tools/chatgui/src/messagelist.cpp

1
src/media_async/attachment_send.c

@ -57,6 +57,7 @@ done:
/* Один выбор транспорта после общей подготовки; групповой индекс и PM crypto не смешиваются. */
static void attachment_publish(struct attachment_send_req* req, int error) {
attachment_release_pcm(req); /* Submit мог завершиться ошибкой до запуска work. */
if (error || req->error || attachment_validate(&req->info)) {
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "attachment: preparation failed target=%s error=%d worker=%d", req->target, error, req->error);
if (remove(req->output) && errno != ENOENT) DEBUG_WARN(DEBUG_CATEGORY_MEDIA, "attachment: output cleanup failed path=%s", req->output);

74
tools/chatgui/src/messagelist.cpp

@ -2,6 +2,7 @@
#include "chatview.h"
#include "messagedelegate.h"
#include "inputbar.h"
#include "media_async/attachment_send.h"
#include "emojipanel.h"
#include "emoji.h"
#include "animtimer.h"
@ -476,44 +477,28 @@ MessageList::MessageList(DbManager* db, AudioRecorder* recorder, QWidget *parent
gui_bridge_post_uasync_fn(chat_core_submit_trampoline, req);
});
connect(m_inputBar, &InputBar::sendVoiceMessage, this, [this](const QString& mediaSrc, const QString& mediaDest,
int durationMs, const QString& wfStr) {
if (m_currentChannelId.isEmpty()) return;
QByteArray textData = wfStr.toUtf8();
auto ts = QDateTime::currentMSecsSinceEpoch();
struct chat_msg_submit* req = (struct chat_msg_submit*)
u_malloc(sizeof(struct chat_msg_submit) + textData.size());
memset(req, 0, sizeof(*req));
req->inst = gui_bridge_get_inst();
snprintf(req->channel_id, sizeof(req->channel_id), "%s",
m_currentChannelId.toUtf8().constData());
snprintf(req->content_type, sizeof(req->content_type), "audio/opus");
snprintf(req->media_src, sizeof(req->media_src), "%s", mediaSrc.toUtf8().constData());
snprintf(req->media_dest, sizeof(req->media_dest), "%s", mediaDest.toUtf8().constData());
req->media_copy = 0;
req->data = (uint8_t*)(req + 1);
req->data_len = (uint32_t)textData.size();
memcpy(req->data, textData.constData(), textData.size());
req->timestamp = (uint64_t)ts;
gui_bridge_post_uasync_fn(chat_core_submit_trampoline, req);
connect(m_inputBar, &InputBar::submitAttachment, this, [this](const QString& target, struct attachment_send_req* req) {
req->inst = gui_bridge_get_inst(); req->is_dm = isDmChannel(target);
QByteArray id = (req->is_dm ? dmConvId(target) : target).toUtf8();
snprintf(req->target, sizeof(req->target), "%s", id.constData());
gui_bridge_post_uasync_fn(attachment_send_trampoline, req);
});
connect(m_inputBar, &InputBar::sendFileAttachment, this, [this](const QString& mediaSrc, const QString& mediaDest,
connect(m_inputBar, &InputBar::sendFileAttachment, this, [this](const QString& target, const QString& mediaSrc, const QString& mediaDest,
const QString& displayName) {
if (m_currentChannelId.isEmpty()) return;
if (isDmChannel(m_currentChannelId)) {
if (target.isEmpty()) return;
if (isDmChannel(target)) {
auto* req = (struct dm_file_req*)u_calloc(1, sizeof(struct dm_file_req));
if (!req) { DEBUG_ERROR(DEBUG_CATEGORY_DM, "PM file request allocation failed"); return; }
req->inst = gui_bridge_get_inst();
QByteArray conv = dmConvId(m_currentChannelId).toUtf8(), path = mediaSrc.toUtf8(), name = displayName.toUtf8();
if (path.size() >= (int)sizeof(req->path) || name.size() >= (int)sizeof(req->name)) {
QByteArray conv = dmConvId(target).toUtf8(), path = mediaSrc.toUtf8(), name = displayName.toUtf8();
if (path.size() >= (int)sizeof(req->path) || name.size() >= (int)sizeof(req->info.name)) {
DEBUG_ERROR(DEBUG_CATEGORY_DM, "PM attachment path or name is too long"); u_free(req); return;
}
snprintf(req->conv, sizeof(req->conv), "%s", conv.constData());
snprintf(req->path, sizeof(req->path), "%s", path.constData());
snprintf(req->name, sizeof(req->name), "%s", name.constData());
req->info.kind = ATTACHMENT_FILE;
snprintf(req->info.name, sizeof(req->info.name), "%s", name.constData());
gui_bridge_post_uasync_fn(dm_send_file_trampoline, req);
return;
}
@ -526,7 +511,7 @@ MessageList::MessageList(DbManager* db, AudioRecorder* recorder, QWidget *parent
memset(req, 0, sizeof(*req));
req->inst = gui_bridge_get_inst();
snprintf(req->channel_id, sizeof(req->channel_id), "%s",
m_currentChannelId.toUtf8().constData());
target.toUtf8().constData());
snprintf(req->content_type, sizeof(req->content_type), "application/octet-stream");
snprintf(req->media_src, sizeof(req->media_src), "%s", mediaSrc.toUtf8().constData());
snprintf(req->media_dest, sizeof(req->media_dest), "%s", mediaDest.toUtf8().constData());
@ -538,34 +523,9 @@ MessageList::MessageList(DbManager* db, AudioRecorder* recorder, QWidget *parent
gui_bridge_post_uasync_fn(chat_core_submit_trampoline, req);
});
connect(m_inputBar, &InputBar::sendVideoAttachment, this, [this](const QString& mediaSrc, const QString& mediaDest,
connect(m_inputBar, &InputBar::sendImageAttachment, this, [this](const QString& target, const QString& mediaSrc, const QString& mediaDest,
const QString& displayName) {
if (m_currentChannelId.isEmpty()) return;
QByteArray textData = displayName.toUtf8();
auto ts = QDateTime::currentMSecsSinceEpoch();
struct chat_msg_submit* req = (struct chat_msg_submit*)
u_malloc(sizeof(struct chat_msg_submit) + textData.size());
memset(req, 0, sizeof(*req));
req->inst = gui_bridge_get_inst();
snprintf(req->channel_id, sizeof(req->channel_id), "%s",
m_currentChannelId.toUtf8().constData());
snprintf(req->content_type, sizeof(req->content_type), "video/mp4");
snprintf(req->media_src, sizeof(req->media_src), "%s", mediaSrc.toUtf8().constData());
snprintf(req->media_dest, sizeof(req->media_dest), "%s", mediaDest.toUtf8().constData());
req->media_copy = 0;
req->media_video = 1;
req->data = (uint8_t*)(req + 1);
req->data_len = (uint32_t)textData.size();
memcpy(req->data, textData.constData(), textData.size());
req->timestamp = (uint64_t)ts;
gui_bridge_post_uasync_fn(chat_core_submit_trampoline, req);
});
connect(m_inputBar, &InputBar::sendImageAttachment, this, [this](const QString& mediaSrc, const QString& mediaDest,
const QString& displayName) {
if (m_currentChannelId.isEmpty()) return;
if (target.isEmpty()) return;
QByteArray textData = displayName.toUtf8();
auto ts = QDateTime::currentMSecsSinceEpoch();
@ -591,7 +551,7 @@ MessageList::MessageList(DbManager* db, AudioRecorder* recorder, QWidget *parent
memset(req, 0, sizeof(*req));
req->inst = gui_bridge_get_inst();
snprintf(req->channel_id, sizeof(req->channel_id), "%s",
m_currentChannelId.toUtf8().constData());
target.toUtf8().constData());
snprintf(req->content_type, sizeof(req->content_type), "%s", ct.toUtf8().constData());
snprintf(req->media_src, sizeof(req->media_src), "%s", mediaSrc.toUtf8().constData());
snprintf(req->media_dest, sizeof(req->media_dest), "%s", mediaDest.toUtf8().constData());

Loading…
Cancel
Save