Keep channel download commands out of the shared message delegate
This commit is contained in:
1 parent
4f76b4d765
commit
a281165450
2 files changed
+6
-47
No files matched your search
@@ -24,14 +24,6 @@
|
||||
#include <QDebug>
|
||||
#include <QImageReader>
|
||||
|
||||
extern "C" {
|
||||
#include "../transport/gui_bridge.h"
|
||||
#include "chat/chat_core.h"
|
||||
#include "../../lib/u_async.h"
|
||||
#include "../../lib/mem.h"
|
||||
void chat_core_attachment_download_trampoline(void* arg);
|
||||
}
|
||||
|
||||
MessageDelegate::MessageDelegate(QObject *parent)
|
||||
: QStyledItemDelegate(parent) {}
|
||||
|
||||
@@ -96,16 +88,7 @@ bool MessageDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
|
||||
}
|
||||
if (dlState == 1) return false; /* скачивается */
|
||||
|
||||
if (chId.isEmpty() || msgId <= 0) return false;
|
||||
struct attachment_dl_req* req = (struct attachment_dl_req*)
|
||||
u_malloc(sizeof(struct attachment_dl_req));
|
||||
if (!req) return false;
|
||||
memset(req, 0, sizeof(*req));
|
||||
req->inst = gui_bridge_get_inst();
|
||||
strncpy(req->channel_id, chId.toUtf8().constData(), sizeof(req->channel_id) - 1);
|
||||
req->msg_id = msgId;
|
||||
gui_bridge_post_uasync_fn(chat_core_attachment_download_trampoline, req);
|
||||
return true;
|
||||
return m_downloadCb && m_downloadCb(index);
|
||||
}
|
||||
|
||||
if (L.isImage) {
|
||||
@@ -123,16 +106,7 @@ bool MessageDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
|
||||
}
|
||||
if (dlState == 1) return false; /* скачивается */
|
||||
|
||||
if (chId.isEmpty() || msgId <= 0) return false;
|
||||
struct attachment_dl_req* req = (struct attachment_dl_req*)
|
||||
u_malloc(sizeof(struct attachment_dl_req));
|
||||
if (!req) return false;
|
||||
memset(req, 0, sizeof(*req));
|
||||
req->inst = gui_bridge_get_inst();
|
||||
strncpy(req->channel_id, chId.toUtf8().constData(), sizeof(req->channel_id) - 1);
|
||||
req->msg_id = msgId;
|
||||
gui_bridge_post_uasync_fn(chat_core_attachment_download_trampoline, req);
|
||||
return true;
|
||||
return m_downloadCb && m_downloadCb(index);
|
||||
}
|
||||
|
||||
if (L.isFile) {
|
||||
@@ -151,16 +125,7 @@ bool MessageDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
|
||||
}
|
||||
if (dlState == 1) return false; /* downloading — no action */
|
||||
|
||||
if (chId.isEmpty() || msgId <= 0) return false;
|
||||
struct attachment_dl_req* req = (struct attachment_dl_req*)
|
||||
u_malloc(sizeof(struct attachment_dl_req));
|
||||
if (!req) return false;
|
||||
memset(req, 0, sizeof(*req));
|
||||
req->inst = gui_bridge_get_inst();
|
||||
strncpy(req->channel_id, chId.toUtf8().constData(), sizeof(req->channel_id) - 1);
|
||||
req->msg_id = msgId;
|
||||
gui_bridge_post_uasync_fn(chat_core_attachment_download_trampoline, req);
|
||||
return true;
|
||||
return m_downloadCb && m_downloadCb(index);
|
||||
}
|
||||
|
||||
if (!L.isVoice) return false;
|
||||
@@ -184,15 +149,7 @@ bool MessageDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
|
||||
/* not downloaded (or file evicted): start download (play will start on completion) */
|
||||
bool fileMissing = filePath.isEmpty() || !QFile::exists(filePath);
|
||||
if (fileMissing && dlState != 1) {
|
||||
if (chId.isEmpty() || msgId <= 0) return false;
|
||||
struct attachment_dl_req* req = (struct attachment_dl_req*)
|
||||
u_malloc(sizeof(struct attachment_dl_req));
|
||||
if (!req) return false;
|
||||
memset(req, 0, sizeof(*req));
|
||||
req->inst = gui_bridge_get_inst();
|
||||
strncpy(req->channel_id, chId.toUtf8().constData(), sizeof(req->channel_id) - 1);
|
||||
req->msg_id = msgId;
|
||||
gui_bridge_post_uasync_fn(chat_core_attachment_download_trampoline, req);
|
||||
if (!m_downloadCb || !m_downloadCb(index)) return false;
|
||||
model->setData(index, true, MsgVoiceDownloadPendingRole);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user