Use one owned channel submission path and preserve the emitting context

This commit is contained in:
evgeny committed 2026-10-28 00:58:59 +01:00
1 parent 195b9c5afb
commit 45485f4fbc
2 files changed
+12 -10

No files matched your search

+10 -6
View File
@@ -457,6 +457,9 @@ void InputBar::onSendClicked() {
GUI_WARN("send: submission still pending ch=%s", qPrintable(m_channelIdForRecord)); return;
}
m_submissionFailed = false;
QPointer<InputBar> alive(this);
const quint64 context = m_attachmentContext;
const QString target = m_channelIdForRecord;
const QByteArray reply = m_replyTo;
QString text = m_input->toPlainText();
while (!text.isEmpty() && (text.back() == ' ' || text.back() == '\t'))
@@ -466,6 +469,7 @@ void InputBar::onSendClicked() {
if (!hasAttach && text.isEmpty()) return;
if (hasAttach) {
const QString source = m_pendingAttachSrc, destination = m_pendingAttachDest, name = m_pendingAttachName;
const quint64 requestId = beginSubmission(reply, m_replyGeneration, m_channelIdForRecord, {}, m_pendingAttachSrc);
const bool encrypted = !m_dmMode && m_encryptCheck->isChecked();
if (encrypted) {
@@ -487,10 +491,10 @@ void InputBar::onSendClicked() {
snprintf(request->info.name, sizeof(request->info.name), "%s", name.constData());
if (reply.size() == 32) memcpy(request->reply_to, reply.constData(), 32);
request->request_id = requestId;
emit submitAttachment(m_channelIdForRecord, request);
emit submitAttachment(target, request);
} else if (m_pendingAttachAsImage) {
GUI_INFO("send: image=%s name=%s", qPrintable(m_pendingAttachSrc), qPrintable(m_pendingAttachName));
emit sendImageAttachment(m_channelIdForRecord, m_pendingAttachSrc, m_pendingAttachDest, m_pendingAttachName, reply, requestId);
emit sendImageAttachment(target, source, destination, name, reply, requestId);
} else if (m_pendingAttachAsVideo) {
GUI_INFO("send: video=%s name=%s", qPrintable(m_pendingAttachSrc), qPrintable(m_pendingAttachName));
auto* request = (struct attachment_send_req*)u_calloc(1, sizeof(struct attachment_send_req));
@@ -505,18 +509,18 @@ void InputBar::onSendClicked() {
request->request_id = requestId;
snprintf(request->source, sizeof(request->source), "%s", source.constData());
snprintf(request->info.name, sizeof(request->info.name), "%s", name.constData());
emit submitAttachment(m_channelIdForRecord, request);
emit submitAttachment(target, request);
} else {
GUI_INFO("send: file=%s name=%s", qPrintable(m_pendingAttachSrc), qPrintable(m_pendingAttachName));
emit sendFileAttachment(m_channelIdForRecord, m_pendingAttachSrc, m_pendingAttachDest, m_pendingAttachName, reply, requestId);
emit sendFileAttachment(target, source, destination, name, reply, requestId);
}
if (!alive || context != m_attachmentContext) return;
if (reply.isEmpty()) clearPendingAttachment();
}
if (!text.isEmpty()) {
const quint64 request = beginSubmission(reply, m_replyGeneration, m_channelIdForRecord, text);
QPointer<InputBar> alive(this);
emit sendMessage(text, reply, request);
if (!alive) return;
if (!alive || context != m_attachmentContext) return;
if (!request) m_input->clear();
if (m_emojiPanel) m_emojiPanel->hide();
m_input->setFocus();
+2 -4
View File
@@ -796,7 +796,6 @@ MessageList::MessageList(DbManager* db, AudioRecorder* recorder, QWidget *parent
memset(req, 0, sizeof(*req));
if (reply.size() == 32) memcpy(req->reply_to, reply.constData(), 32);
req->request_id = request;
req->inst = gui_bridge_get_inst();
snprintf(req->channel_id, sizeof(req->channel_id), "%s",
target.toUtf8().constData());
snprintf(req->content_type, sizeof(req->content_type), "application/octet-stream");
@@ -807,7 +806,7 @@ MessageList::MessageList(DbManager* db, AudioRecorder* recorder, QWidget *parent
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);
if (gui_bridge_submit_message(req) < 0) { u_free(req); m_inputBar->submissionResult(request, false); }
});
connect(m_inputBar, &InputBar::sendImageAttachment, this, [this](const QString& target, const QString& mediaSrc, const QString& mediaDest,
@@ -841,7 +840,6 @@ MessageList::MessageList(DbManager* db, AudioRecorder* recorder, QWidget *parent
memset(req, 0, sizeof(*req));
if (reply.size() == 32) memcpy(req->reply_to, reply.constData(), 32);
req->request_id = request;
req->inst = gui_bridge_get_inst();
snprintf(req->channel_id, sizeof(req->channel_id), "%s",
target.toUtf8().constData());
snprintf(req->content_type, sizeof(req->content_type), "%s", ct.toUtf8().constData());
@@ -855,7 +853,7 @@ MessageList::MessageList(DbManager* db, AudioRecorder* recorder, QWidget *parent
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);
if (gui_bridge_submit_message(req) < 0) { u_free(req); m_inputBar->submissionResult(request, false); }
});
connect(AnimTimer::instance(), &AnimTimer::ticked, this, [this]() {