Keep ordinary channel drafts until their correlated save result
This commit is contained in:
1 parent
6511946a17
commit
b39cd735cd
2 files changed
+50
-41
No files matched your search
@@ -38,6 +38,8 @@ extern "C" {
|
||||
#include "mem.h"
|
||||
}
|
||||
|
||||
quint64 InputBar::s_submissionSequence = 0;
|
||||
|
||||
static bool isImageFile(const QString& suffix) {
|
||||
QString s = suffix.toLower();
|
||||
return s == "jpg" || s == "jpeg" || s == "png" || s == "gif" ||
|
||||
@@ -255,7 +257,7 @@ void InputBar::setReply(const QByteArray& messageId, const QString& author, cons
|
||||
if (m_dmMode || messageId.size() != 32 || m_channelIdForRecord.isEmpty()) {
|
||||
GUI_ERROR("reply: invalid composer target/key bytes=%d", int(messageId.size())); return;
|
||||
}
|
||||
++m_replyGeneration; m_replyTo = messageId; m_replyFailed = false;
|
||||
++m_replyGeneration; m_replyTo = messageId; m_submissionFailed = false;
|
||||
m_replyLabel->setText(author.simplified() + "\n" + preview.simplified());
|
||||
m_replyPreview->show(); m_input->setFocus();
|
||||
GUI_DEBUG("reply: selected ch=%s id=%s generation=%llu", qPrintable(m_channelIdForRecord),
|
||||
@@ -265,21 +267,22 @@ void InputBar::setReply(const QByteArray& messageId, const QString& author, cons
|
||||
void InputBar::clearReply() {
|
||||
if (!m_replyTo.isEmpty()) GUI_DEBUG("reply: cleared ch=%s generation=%llu", qPrintable(m_channelIdForRecord),
|
||||
(unsigned long long)m_replyGeneration);
|
||||
++m_replyGeneration; m_replyTo.clear(); m_replyFailed = false; m_replyPreview->hide();
|
||||
++m_replyGeneration; m_replyTo.clear(); m_submissionFailed = false; m_replyPreview->hide();
|
||||
}
|
||||
|
||||
bool InputBar::replySending() const {
|
||||
for (const auto& pending : m_pendingReplies) if (pending.generation == m_replyGeneration) return true;
|
||||
bool InputBar::submissionPending() const {
|
||||
for (const auto& pending : m_pendingSubmissions)
|
||||
if (pending.generation == m_replyGeneration && pending.target == m_channelIdForRecord) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Каждая часть отправки (текст/вложение) имеет собственное подтверждение и снимок черновика. */
|
||||
quint64 InputBar::beginReplySend(const QByteArray& reply, quint64 generation, const QString& target,
|
||||
/* Канальный текст и каждая часть ответа имеют собственное подтверждение и снимок черновика. */
|
||||
quint64 InputBar::beginSubmission(const QByteArray& reply, quint64 generation, const QString& target,
|
||||
const QString& text, const QString& source) {
|
||||
if (reply.isEmpty()) return 0;
|
||||
const quint64 request = ++m_submissionSequence;
|
||||
m_pendingReplies.insert(request, {generation, target, text, source, m_input->document()->revision(), m_attachmentRevision});
|
||||
GUI_DEBUG("reply: submit ch=%s id=%s request=%llu", qPrintable(target), reply.toHex().constData(), (unsigned long long)request);
|
||||
if (reply.isEmpty() && (m_dmMode || text.isEmpty())) return 0;
|
||||
const quint64 request = ++s_submissionSequence;
|
||||
m_pendingSubmissions.insert(request, {generation, target, text, source, m_input->document()->revision(), m_attachmentRevision});
|
||||
GUI_DEBUG("send: pending ch=%s reply=%s request=%llu", qPrintable(target), reply.toHex().constData(), (unsigned long long)request);
|
||||
return request;
|
||||
}
|
||||
|
||||
@@ -293,24 +296,24 @@ void InputBar::submissionResult(quint64 request, bool success) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!request || !m_pendingReplies.contains(request)) return;
|
||||
const auto pending = m_pendingReplies.take(request);
|
||||
GUI_DEBUG("reply: result ch=%s request=%llu success=%d", qPrintable(pending.target), (unsigned long long)request, success);
|
||||
if (!request || !m_pendingSubmissions.contains(request)) return;
|
||||
const auto pending = m_pendingSubmissions.take(request);
|
||||
GUI_DEBUG("send: result ch=%s request=%llu success=%d", qPrintable(pending.target), (unsigned long long)request, success);
|
||||
if (pending.generation != m_replyGeneration || pending.target != m_channelIdForRecord) return;
|
||||
if (!success) {
|
||||
m_replyFailed = true;
|
||||
GUI_ERROR("reply: submission failed ch=%s request=%llu", qPrintable(pending.target), (unsigned long long)request);
|
||||
emit attachmentRejected(QCoreApplication::translate("ChatGui", "Could not send reply. Please try again."));
|
||||
m_submissionFailed = true;
|
||||
GUI_ERROR("send: submission failed ch=%s request=%llu", qPrintable(pending.target), (unsigned long long)request);
|
||||
emit attachmentRejected(QCoreApplication::translate("ChatGui", "Could not send message. Please try again."));
|
||||
return;
|
||||
}
|
||||
if (!pending.text.isEmpty() && pending.textRevision == m_input->document()->revision()) m_input->clear();
|
||||
if (!pending.source.isEmpty() && pending.attachmentRevision == m_attachmentRevision) clearPendingAttachment();
|
||||
if (!replySending() && !m_replyFailed && m_input->toPlainText().isEmpty() && m_pendingAttachSrc.isEmpty()) clearReply();
|
||||
if (!submissionPending() && !m_submissionFailed && m_input->toPlainText().isEmpty() && m_pendingAttachSrc.isEmpty()) clearReply();
|
||||
}
|
||||
|
||||
/* Черновик и выбранный ответ восстанавливаются после сохранения/отмены. Вложения остаются в composer. */
|
||||
void InputBar::editMessage(const QByteArray& id, quint64 version, const QString& text) {
|
||||
if (m_dmMode || id.size() != 32 || !version || m_editRequest || replySending() || m_pttActive) {
|
||||
if (m_dmMode || id.size() != 32 || !version || m_editRequest || submissionPending() || m_pttActive) {
|
||||
GUI_WARN("edit: composer busy/invalid target=%s", qPrintable(m_channelIdForRecord)); return;
|
||||
}
|
||||
if (!m_editId.isEmpty()) cancelEdit();
|
||||
@@ -441,17 +444,19 @@ void InputBar::adjustInputHeight() {
|
||||
}
|
||||
|
||||
void InputBar::onSendClicked() {
|
||||
if (!isEnabled()) { GUI_WARN("send: composer unavailable target=%s", qPrintable(m_channelIdForRecord)); return; }
|
||||
if (!isEnabled() || m_channelIdForRecord.isEmpty()) {
|
||||
GUI_WARN("send: composer unavailable target=%s", qPrintable(m_channelIdForRecord)); return;
|
||||
}
|
||||
if (!m_editId.isEmpty()) {
|
||||
const QString text = m_input->toPlainText();
|
||||
if (m_editRequest || text.isEmpty()) return;
|
||||
m_editRequest = ++m_submissionSequence; m_input->setReadOnly(true);
|
||||
m_editRequest = ++s_submissionSequence; m_input->setReadOnly(true);
|
||||
emit saveEdit(m_channelIdForRecord, m_editId, m_editVersion, text, m_editRequest); return;
|
||||
}
|
||||
if (replySending()) {
|
||||
GUI_WARN("reply: submission still pending ch=%s", qPrintable(m_channelIdForRecord)); return;
|
||||
if (submissionPending()) {
|
||||
GUI_WARN("send: submission still pending ch=%s", qPrintable(m_channelIdForRecord)); return;
|
||||
}
|
||||
m_replyFailed = false;
|
||||
m_submissionFailed = false;
|
||||
const QByteArray reply = m_replyTo;
|
||||
QString text = m_input->toPlainText();
|
||||
while (!text.isEmpty() && (text.back() == ' ' || text.back() == '\t'))
|
||||
@@ -461,7 +466,7 @@ void InputBar::onSendClicked() {
|
||||
if (!hasAttach && text.isEmpty()) return;
|
||||
|
||||
if (hasAttach) {
|
||||
const quint64 requestId = beginReplySend(reply, m_replyGeneration, m_channelIdForRecord, {}, m_pendingAttachSrc);
|
||||
const quint64 requestId = beginSubmission(reply, m_replyGeneration, m_channelIdForRecord, {}, m_pendingAttachSrc);
|
||||
const bool encrypted = !m_dmMode && m_encryptCheck->isChecked();
|
||||
if (encrypted) {
|
||||
auto* request = (struct attachment_send_req*)u_calloc(1, sizeof(struct attachment_send_req));
|
||||
@@ -508,9 +513,11 @@ void InputBar::onSendClicked() {
|
||||
if (reply.isEmpty()) clearPendingAttachment();
|
||||
}
|
||||
if (!text.isEmpty()) {
|
||||
const quint64 request = beginReplySend(reply, m_replyGeneration, m_channelIdForRecord, text);
|
||||
const quint64 request = beginSubmission(reply, m_replyGeneration, m_channelIdForRecord, text);
|
||||
QPointer<InputBar> alive(this);
|
||||
emit sendMessage(text, reply, request);
|
||||
if (reply.isEmpty()) m_input->clear();
|
||||
if (!alive) return;
|
||||
if (!request) m_input->clear();
|
||||
if (m_emojiPanel) m_emojiPanel->hide();
|
||||
m_input->setFocus();
|
||||
}
|
||||
@@ -570,14 +577,14 @@ void InputBar::setMediaEnabled(bool enabled) {
|
||||
void InputBar::onPttPressed() {
|
||||
if (!m_editId.isEmpty()) { GUI_WARN("voice: blocked while editing"); return; }
|
||||
if (!isEnabled() || m_channelIdForRecord.isEmpty()) { GUI_WARN("voice: composer unavailable"); return; }
|
||||
if (replySending()) { GUI_WARN("reply: recording blocked while submission pending"); return; }
|
||||
if (submissionPending()) { GUI_WARN("send: recording blocked while submission pending"); return; }
|
||||
if (!m_recorder || !m_recorder->isInitialized()) return;
|
||||
m_recorder->startRecording();
|
||||
m_pttActive = m_recorder->isRecording();
|
||||
if (!m_pttActive) { DEBUG_WARN(DEBUG_CATEGORY_MEDIA, "voice recording did not start; composer remains idle"); return; }
|
||||
m_recordTarget = m_channelIdForRecord;
|
||||
m_recordDmGeneration = m_dmGeneration;
|
||||
m_recordReply = m_replyTo; m_recordReplyGeneration = m_replyGeneration; m_replyFailed = false;
|
||||
m_recordReply = m_replyTo; m_recordReplyGeneration = m_replyGeneration; m_submissionFailed = false;
|
||||
m_pttBtn->setStyleSheet(m_pttBtn->styleSheet() +
|
||||
"QPushButton { background: #e74c3c; border-radius: 4px; }");
|
||||
}
|
||||
@@ -606,7 +613,7 @@ void InputBar::onPttReleased() {
|
||||
request->dm_generation = m_recordDmGeneration;
|
||||
if (!m_recorder->takeRecording(request)) { u_free(request); return; }
|
||||
if (m_recordReply.size() == 32) memcpy(request->reply_to, m_recordReply.constData(), 32);
|
||||
request->request_id = beginReplySend(m_recordReply, m_recordReplyGeneration, m_recordTarget);
|
||||
request->request_id = beginSubmission(m_recordReply, m_recordReplyGeneration, m_recordTarget);
|
||||
emit submitAttachment(m_recordTarget, request);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user