|
|
|
|
@ -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()); |
|
|
|
|
|