2021-07-06 10:20:46 -04:00
|
|
|
/*
|
2025-02-06 21:47:26 -04:00
|
|
|
* Copyright (C) 2020-2025 Savoir-faire Linux Inc.
|
2020-08-03 13:27:42 -04:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "messagesadapter.h"
|
|
|
|
|
|
2021-03-30 15:15:36 -04:00
|
|
|
#include "appsettingsmanager.h"
|
2020-09-04 14:51:39 -04:00
|
|
|
#include "qtutils.h"
|
2023-03-20 16:26:37 -04:00
|
|
|
#include "messageparser.h"
|
2023-11-16 15:27:07 -05:00
|
|
|
#include "previewengine.h"
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-06-28 09:14:31 -04:00
|
|
|
#include <api/datatransfermodel.h>
|
2024-02-15 12:05:14 -05:00
|
|
|
#include <api/contact.h>
|
2021-06-28 09:14:31 -04:00
|
|
|
|
2020-09-04 14:51:39 -04:00
|
|
|
#include <QApplication>
|
2022-05-13 10:20:46 -04:00
|
|
|
#include <QBuffer>
|
2020-09-04 14:51:39 -04:00
|
|
|
#include <QClipboard>
|
2020-08-03 13:27:42 -04:00
|
|
|
#include <QDesktopServices>
|
2022-05-13 10:20:46 -04:00
|
|
|
#include <QDir>
|
2020-08-03 13:27:42 -04:00
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QImageReader>
|
|
|
|
|
#include <QList>
|
2021-04-08 16:03:25 -04:00
|
|
|
#include <QMimeData>
|
2022-05-13 10:20:46 -04:00
|
|
|
#include <QMimeDatabase>
|
|
|
|
|
#include <QUrl>
|
2021-07-06 10:20:46 -04:00
|
|
|
#include <QtMath>
|
2022-05-13 10:20:46 -04:00
|
|
|
#include <QRegExp>
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-03-30 15:15:36 -04:00
|
|
|
MessagesAdapter::MessagesAdapter(AppSettingsManager* settingsManager,
|
2021-07-06 10:20:46 -04:00
|
|
|
PreviewEngine* previewEngine,
|
2021-03-30 15:15:36 -04:00
|
|
|
LRCInstance* instance,
|
|
|
|
|
QObject* parent)
|
2021-03-30 14:22:39 -04:00
|
|
|
: QmlAdapterBase(instance, parent)
|
2021-03-30 15:15:36 -04:00
|
|
|
, settingsManager_(settingsManager)
|
2023-03-20 16:26:37 -04:00
|
|
|
, messageParser_(new MessageParser(previewEngine, this))
|
2023-02-01 17:33:24 -05:00
|
|
|
, filteredMsgListModel_(new FilteredMsgListModel(this))
|
2023-07-06 11:31:20 -04:00
|
|
|
, mediaInteractions_(std::make_unique<MessageListModel>(nullptr))
|
2023-02-01 17:33:24 -05:00
|
|
|
, timestampTimer_(new QTimer(this))
|
2021-07-06 10:20:46 -04:00
|
|
|
{
|
2023-01-06 14:07:33 -05:00
|
|
|
setObjectName(typeid(*this).name());
|
|
|
|
|
|
|
|
|
|
set_messageListModel(QVariant::fromValue(filteredMsgListModel_));
|
|
|
|
|
|
2023-07-06 11:31:20 -04:00
|
|
|
connect(settingsManager_,
|
|
|
|
|
&AppSettingsManager::reloadHistory,
|
|
|
|
|
&lrcInstance_->accountModel(),
|
|
|
|
|
&AccountModel::reloadHistory);
|
|
|
|
|
|
2023-01-06 14:07:33 -05:00
|
|
|
connect(lrcInstance_, &LRCInstance::selectedConvUidChanged, this, [this]() {
|
2022-07-19 15:57:44 -04:00
|
|
|
set_replyToId("");
|
2022-10-11 16:24:04 -04:00
|
|
|
set_editId("");
|
2021-07-06 10:20:46 -04:00
|
|
|
const QString& convId = lrcInstance_->get_selectedConvUid();
|
|
|
|
|
const auto& conversation = lrcInstance_->getConversationFromConvUid(convId);
|
2023-02-01 17:33:24 -05:00
|
|
|
|
|
|
|
|
// Reset the source model for the proxy model.
|
|
|
|
|
filteredMsgListModel_->setSourceModel(conversation.interactions.get());
|
|
|
|
|
|
2022-08-04 13:57:07 -04:00
|
|
|
set_currentConvComposingList(conversationTypersUrlToName(conversation.typers));
|
2021-07-06 10:20:46 -04:00
|
|
|
});
|
|
|
|
|
|
2023-03-20 16:26:37 -04:00
|
|
|
connect(messageParser_, &MessageParser::messageParsed, this, &MessagesAdapter::onMessageParsed);
|
|
|
|
|
connect(messageParser_, &MessageParser::linkInfoReady, this, &MessagesAdapter::onLinkInfoReady);
|
2023-02-01 17:33:24 -05:00
|
|
|
|
|
|
|
|
connect(timestampTimer_, &QTimer::timeout, this, &MessagesAdapter::timestampUpdated);
|
|
|
|
|
timestampTimer_->start(timestampUpdateIntervalMs_);
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2023-12-20 17:16:07 -05:00
|
|
|
connect(lrcInstance_,
|
|
|
|
|
&LRCInstance::currentAccountIdChanged,
|
|
|
|
|
this,
|
|
|
|
|
&MessagesAdapter::connectConversationModel);
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2023-01-06 14:07:33 -05:00
|
|
|
connectConversationModel();
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
|
2023-02-03 11:29:37 -05:00
|
|
|
bool
|
|
|
|
|
MessagesAdapter::isDocument(const interaction::Type& type)
|
|
|
|
|
{
|
|
|
|
|
return interaction::Type::DATA_TRANSFER == type;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
void
|
2021-07-06 10:20:46 -04:00
|
|
|
MessagesAdapter::loadMoreMessages()
|
2021-06-25 14:37:55 -04:00
|
|
|
{
|
2021-07-07 13:48:41 -04:00
|
|
|
auto accountId = lrcInstance_->get_currentAccountId();
|
2021-07-06 10:20:46 -04:00
|
|
|
auto convId = lrcInstance_->get_selectedConvUid();
|
2022-12-29 13:21:14 -05:00
|
|
|
try {
|
|
|
|
|
const auto& convInfo = lrcInstance_->getConversationFromConvUid(convId, accountId);
|
2023-07-06 11:31:20 -04:00
|
|
|
if (convInfo.isSwarm())
|
|
|
|
|
lrcInstance_->getCurrentConversationModel()->loadConversationMessages(convId,
|
|
|
|
|
loadChunkSize_);
|
2022-12-29 13:21:14 -05:00
|
|
|
} catch (const std::exception& e) {
|
|
|
|
|
qWarning() << e.what();
|
2021-06-25 14:37:55 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MessagesAdapter::connectConversationModel()
|
|
|
|
|
{
|
|
|
|
|
auto currentConversationModel = lrcInstance_->getCurrentConversationModel();
|
2023-01-06 14:07:33 -05:00
|
|
|
if (currentConversationModel == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-06-25 14:37:55 -04:00
|
|
|
|
|
|
|
|
QObject::connect(currentConversationModel,
|
|
|
|
|
&ConversationModel::newInteraction,
|
|
|
|
|
this,
|
|
|
|
|
&MessagesAdapter::onNewInteraction,
|
|
|
|
|
Qt::UniqueConnection);
|
|
|
|
|
|
|
|
|
|
QObject::connect(currentConversationModel,
|
2021-07-06 10:20:46 -04:00
|
|
|
&ConversationModel::conversationMessagesLoaded,
|
2021-06-25 14:37:55 -04:00
|
|
|
this,
|
2021-07-06 10:20:46 -04:00
|
|
|
&MessagesAdapter::onConversationMessagesLoaded,
|
2021-06-25 14:37:55 -04:00
|
|
|
Qt::UniqueConnection);
|
2021-10-08 17:27:43 -04:00
|
|
|
|
|
|
|
|
QObject::connect(currentConversationModel,
|
|
|
|
|
&ConversationModel::composingStatusChanged,
|
|
|
|
|
this,
|
|
|
|
|
&MessagesAdapter::onComposingStatusChanged,
|
|
|
|
|
Qt::UniqueConnection);
|
2022-10-13 14:41:28 -04:00
|
|
|
|
|
|
|
|
QObject::connect(currentConversationModel,
|
|
|
|
|
&ConversationModel::messagesFoundProcessed,
|
|
|
|
|
this,
|
|
|
|
|
&MessagesAdapter::onMessagesFoundProcessed,
|
|
|
|
|
Qt::UniqueConnection);
|
2023-12-20 17:16:07 -05:00
|
|
|
|
|
|
|
|
mediaInteractions_.reset(new MessageListModel(&lrcInstance_->getCurrentAccountInfo(), this));
|
|
|
|
|
set_mediaMessageListModel(QVariant::fromValue(mediaInteractions_.get()));
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2021-06-22 14:31:42 -04:00
|
|
|
MessagesAdapter::sendConversationRequest()
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
2021-06-22 14:31:42 -04:00
|
|
|
lrcInstance_->makeConversationPermanent();
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2020-09-10 17:40:51 -04:00
|
|
|
MessagesAdapter::sendMessage(const QString& message)
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2021-04-08 16:53:12 -04:00
|
|
|
const auto convUid = lrcInstance_->get_selectedConvUid();
|
2022-07-19 15:57:44 -04:00
|
|
|
lrcInstance_->getCurrentConversationModel()->sendMessage(convUid, message, replyToId_);
|
2020-08-03 13:27:42 -04:00
|
|
|
} catch (...) {
|
|
|
|
|
qDebug() << "Exception during sendMessage:" << message;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-30 15:04:11 -04:00
|
|
|
void
|
|
|
|
|
MessagesAdapter::sendMessageToUid(const QString& message, const QString& convUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
lrcInstance_->getCurrentConversationModel()->sendMessage(convUid, message, replyToId_);
|
|
|
|
|
} catch (...) {
|
|
|
|
|
qDebug() << "Exception during sendMessage:" << message;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-11 16:24:04 -04:00
|
|
|
void
|
|
|
|
|
MessagesAdapter::editMessage(const QString& convId, const QString& newBody, const QString& messageId)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
auto editId = !messageId.isEmpty() ? messageId : editId_;
|
|
|
|
|
if (editId.isEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-01-04 13:53:21 -05:00
|
|
|
set_editId("");
|
2022-10-11 16:24:04 -04:00
|
|
|
lrcInstance_->getCurrentConversationModel()->editMessage(convId, newBody, editId);
|
|
|
|
|
} catch (...) {
|
|
|
|
|
qDebug() << "Exception during message edition:" << messageId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 09:50:53 -05:00
|
|
|
void
|
|
|
|
|
MessagesAdapter::removeEmojiReaction(const QString& convId,
|
|
|
|
|
const QString& emoji,
|
|
|
|
|
const QString& messageId)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
// check if this emoji has already been added by this author
|
2023-07-06 11:31:20 -04:00
|
|
|
editMessage(convId, "", messageId);
|
2022-11-23 09:50:53 -05:00
|
|
|
} catch (...) {
|
|
|
|
|
qDebug() << "Exception during removeEmojiReaction():" << messageId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MessagesAdapter::addEmojiReaction(const QString& convId,
|
|
|
|
|
const QString& emoji,
|
|
|
|
|
const QString& messageId)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
lrcInstance_->getCurrentConversationModel()->reactMessage(convId, emoji, messageId);
|
|
|
|
|
} catch (...) {
|
|
|
|
|
qDebug() << "Exception during addEmojiReaction():" << messageId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
void
|
2020-09-10 17:40:51 -04:00
|
|
|
MessagesAdapter::sendFile(const QString& message)
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
|
|
|
|
QFileInfo fi(message);
|
|
|
|
|
QString fileName = fi.fileName();
|
|
|
|
|
try {
|
2021-04-08 16:53:12 -04:00
|
|
|
auto convUid = lrcInstance_->get_selectedConvUid();
|
2023-03-03 15:56:21 -05:00
|
|
|
lrcInstance_->getCurrentConversationModel()->sendFile(convUid,
|
|
|
|
|
message,
|
|
|
|
|
fileName,
|
|
|
|
|
replyToId_);
|
2020-08-03 13:27:42 -04:00
|
|
|
} catch (...) {
|
|
|
|
|
qDebug() << "Exception during sendFile";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-30 15:04:11 -04:00
|
|
|
void
|
|
|
|
|
MessagesAdapter::sendFileToUid(const QString& message, const QString& convUid)
|
|
|
|
|
{
|
|
|
|
|
QFileInfo fi(message);
|
|
|
|
|
QString fileName = fi.fileName();
|
|
|
|
|
try {
|
|
|
|
|
lrcInstance_->getCurrentConversationModel()->sendFile(convUid,
|
|
|
|
|
message,
|
|
|
|
|
fileName,
|
|
|
|
|
replyToId_);
|
|
|
|
|
} catch (...) {
|
|
|
|
|
qDebug() << "Exception during sendFile";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-09 11:23:14 -04:00
|
|
|
void
|
|
|
|
|
MessagesAdapter::joinCall(const QString& uri,
|
|
|
|
|
const QString& deviceId,
|
|
|
|
|
const QString& confId,
|
|
|
|
|
bool isAudioOnly)
|
|
|
|
|
{
|
|
|
|
|
lrcInstance_->getCurrentConversationModel()->joinCall(lrcInstance_->get_selectedConvUid(),
|
|
|
|
|
uri,
|
|
|
|
|
deviceId,
|
|
|
|
|
confId,
|
|
|
|
|
isAudioOnly);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-28 09:14:31 -04:00
|
|
|
void
|
|
|
|
|
MessagesAdapter::copyToDownloads(const QString& interactionId, const QString& displayName)
|
|
|
|
|
{
|
|
|
|
|
auto downloadDir = lrcInstance_->accountModel().downloadDirectory;
|
2023-04-07 14:14:54 -04:00
|
|
|
if (auto accInfo = &lrcInstance_->getCurrentAccountInfo()) {
|
|
|
|
|
auto dest = accInfo->dataTransferModel->copyTo(lrcInstance_->get_currentAccountId(),
|
|
|
|
|
lrcInstance_->get_selectedConvUid(),
|
|
|
|
|
interactionId,
|
|
|
|
|
downloadDir,
|
|
|
|
|
displayName);
|
|
|
|
|
if (!dest.isEmpty()) {
|
|
|
|
|
Q_EMIT fileCopied(dest);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-28 09:14:31 -04:00
|
|
|
}
|
|
|
|
|
|
2020-08-29 13:45:07 -04:00
|
|
|
void
|
2020-09-10 17:40:51 -04:00
|
|
|
MessagesAdapter::openUrl(const QString& url)
|
2020-08-29 13:45:07 -04:00
|
|
|
{
|
|
|
|
|
if (!QDesktopServices::openUrl(url)) {
|
|
|
|
|
qDebug() << "Couldn't open url: " << url;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-25 16:18:06 -04:00
|
|
|
void
|
|
|
|
|
MessagesAdapter::openDirectory(const QString& path)
|
|
|
|
|
{
|
|
|
|
|
QString p = path;
|
|
|
|
|
QFileInfo f(p);
|
|
|
|
|
if (f.exists()) {
|
|
|
|
|
if (!f.isDir())
|
|
|
|
|
p = f.dir().absolutePath();
|
|
|
|
|
QString url;
|
2021-10-28 11:45:48 -04:00
|
|
|
if (!p.startsWith("file:/"))
|
|
|
|
|
url = "file:///" + p;
|
2021-10-25 16:18:06 -04:00
|
|
|
else
|
|
|
|
|
url = p;
|
|
|
|
|
openUrl(url);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 16:32:32 -04:00
|
|
|
void
|
|
|
|
|
MessagesAdapter::removeFile(const QString& interactionId, const QString& path)
|
|
|
|
|
{
|
|
|
|
|
auto convUid = lrcInstance_->get_selectedConvUid();
|
|
|
|
|
lrcInstance_->getCurrentConversationModel()->removeFile(convUid, interactionId, path);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
void
|
2021-05-12 16:55:28 -04:00
|
|
|
MessagesAdapter::acceptFile(const QString& interactionId)
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
2021-05-12 16:55:28 -04:00
|
|
|
auto convUid = lrcInstance_->get_selectedConvUid();
|
|
|
|
|
lrcInstance_->getCurrentConversationModel()->acceptTransfer(convUid, interactionId);
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2021-09-27 10:29:07 -04:00
|
|
|
MessagesAdapter::cancelFile(const QString& interactionId)
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
2021-05-12 16:55:28 -04:00
|
|
|
const auto convUid = lrcInstance_->get_selectedConvUid();
|
|
|
|
|
lrcInstance_->getCurrentConversationModel()->cancelTransfer(convUid, interactionId);
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2021-07-06 10:20:46 -04:00
|
|
|
MessagesAdapter::onPaste()
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
2020-09-10 17:40:51 -04:00
|
|
|
const QMimeData* mimeData = QApplication::clipboard()->mimeData();
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
|
if (mimeData->hasImage()) {
|
2021-07-06 15:16:08 -04:00
|
|
|
// Save temp data into a temp file.
|
2020-08-03 13:27:42 -04:00
|
|
|
QPixmap pixmap = qvariant_cast<QPixmap>(mimeData->imageData());
|
|
|
|
|
|
2021-07-06 15:16:08 -04:00
|
|
|
auto img_name_hash
|
|
|
|
|
= QCryptographicHash::hash(QString::number(pixmap.cacheKey()).toLocal8Bit(),
|
|
|
|
|
QCryptographicHash::Sha1);
|
2022-02-23 11:52:53 +03:00
|
|
|
QString fileName = "img_" + QString(img_name_hash.toHex()) + ".png";
|
|
|
|
|
QString path = QDir::temp().filePath(fileName);
|
2021-07-06 15:16:08 -04:00
|
|
|
|
|
|
|
|
if (!pixmap.save(path, "PNG")) {
|
2024-08-30 15:04:11 -04:00
|
|
|
qDebug().noquote() << "Errors during QPixmap save" << "\n";
|
2021-07-06 15:16:08 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Q_EMIT newFilePasted(path);
|
2020-08-03 13:27:42 -04:00
|
|
|
} else if (mimeData->hasUrls()) {
|
|
|
|
|
QList<QUrl> urlList = mimeData->urls();
|
2021-07-06 15:16:08 -04:00
|
|
|
|
|
|
|
|
// Extract the local paths of the files.
|
2020-08-03 13:27:42 -04:00
|
|
|
for (int i = 0; i < urlList.size(); ++i) {
|
2021-07-06 15:16:08 -04:00
|
|
|
// Trim file:// or file:/// from url.
|
2023-05-16 14:02:14 -04:00
|
|
|
const static QRegularExpression fileSchemeRe("^file:\\/{2,3}");
|
|
|
|
|
QString filePath = urlList.at(i).toString().remove(fileSchemeRe);
|
2021-07-06 15:16:08 -04:00
|
|
|
Q_EMIT newFilePasted(filePath);
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
} else {
|
2021-01-04 15:39:10 -05:00
|
|
|
// Treat as text content, make chatview.js handle in order to
|
|
|
|
|
// avoid string escape problems
|
2021-07-06 15:16:08 -04:00
|
|
|
Q_EMIT newTextPasted();
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-27 10:29:07 -04:00
|
|
|
QVariantMap
|
|
|
|
|
MessagesAdapter::getTransferStats(const QString& msgId, int status)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(status)
|
|
|
|
|
auto convModel = lrcInstance_->getCurrentConversationModel();
|
|
|
|
|
lrc::api::datatransfer::Info info = {};
|
|
|
|
|
convModel->getTransferInfo(lrcInstance_->get_selectedConvUid(), msgId, info);
|
|
|
|
|
return {{"totalSize", qint64(info.totalSize)}, {"progress", qint64(info.progress)}};
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-19 15:57:44 -04:00
|
|
|
QVariant
|
|
|
|
|
MessagesAdapter::dataForInteraction(const QString& interactionId, int role) const
|
|
|
|
|
{
|
2023-02-01 17:33:24 -05:00
|
|
|
if (auto* model = getMsgListSourceModel()) {
|
2023-12-20 17:16:07 -05:00
|
|
|
return model->data(interactionId, role);
|
2022-07-19 15:57:44 -04:00
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
void
|
2021-07-06 15:16:08 -04:00
|
|
|
MessagesAdapter::userIsComposing(bool isComposing)
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
2024-02-22 14:04:45 -05:00
|
|
|
if (lrcInstance_->get_selectedConvUid().isEmpty())
|
2020-11-05 14:41:25 -05:00
|
|
|
return;
|
2021-04-08 16:53:12 -04:00
|
|
|
lrcInstance_->getCurrentConversationModel()->setIsComposing(lrcInstance_->get_selectedConvUid(),
|
2021-03-11 13:30:45 -05:00
|
|
|
isComposing);
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2021-07-06 10:20:46 -04:00
|
|
|
MessagesAdapter::onNewInteraction(const QString& convUid,
|
|
|
|
|
const QString& interactionId,
|
|
|
|
|
const interaction::Info& interaction)
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(interactionId);
|
|
|
|
|
try {
|
2021-04-08 16:53:12 -04:00
|
|
|
if (convUid.isEmpty() || convUid != lrcInstance_->get_selectedConvUid()) {
|
2020-08-03 13:27:42 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2021-07-06 10:20:46 -04:00
|
|
|
auto accountId = lrcInstance_->get_currentAccountId();
|
2021-03-11 13:30:45 -05:00
|
|
|
auto& accountInfo = lrcInstance_->getAccountInfo(accountId);
|
2020-09-14 13:04:57 -04:00
|
|
|
auto& convModel = accountInfo.conversationModel;
|
2020-08-03 13:27:42 -04:00
|
|
|
convModel->clearUnreadInteractions(convUid);
|
2022-07-19 15:57:44 -04:00
|
|
|
Q_EMIT newInteraction(interactionId, static_cast<int>(interaction.type));
|
2020-08-03 13:27:42 -04:00
|
|
|
} catch (...) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-20 16:26:37 -04:00
|
|
|
void
|
|
|
|
|
MessagesAdapter::onMessageParsed(const QString& messageId, const QString& parsed)
|
|
|
|
|
{
|
2023-07-17 11:01:02 -04:00
|
|
|
if (messageId.isEmpty()) {
|
|
|
|
|
Q_EMIT messageParsed(messageId, parsed);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-03-20 16:26:37 -04:00
|
|
|
const QString& convId = lrcInstance_->get_selectedConvUid();
|
|
|
|
|
const QString& accId = lrcInstance_->get_currentAccountId();
|
|
|
|
|
auto& conversation = lrcInstance_->getConversationFromConvUid(convId, accId);
|
|
|
|
|
conversation.interactions->setParsedMessage(messageId, parsed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MessagesAdapter::onLinkInfoReady(const QString& messageId, const QVariantMap& info)
|
|
|
|
|
{
|
|
|
|
|
const QString& convId = lrcInstance_->get_selectedConvUid();
|
|
|
|
|
const QString& accId = lrcInstance_->get_currentAccountId();
|
|
|
|
|
auto& conversation = lrcInstance_->getConversationFromConvUid(convId, accId);
|
|
|
|
|
conversation.interactions->addHyperlinkInfo(messageId, info);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
void
|
2021-06-25 14:33:56 -04:00
|
|
|
MessagesAdapter::acceptInvitation(const QString& convId)
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
2021-06-25 14:33:56 -04:00
|
|
|
auto conversationId = convId.isEmpty() ? lrcInstance_->get_selectedConvUid() : convId;
|
|
|
|
|
auto* convModel = lrcInstance_->getCurrentConversationModel();
|
|
|
|
|
convModel->acceptConversationRequest(conversationId);
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2020-09-10 17:40:51 -04:00
|
|
|
MessagesAdapter::refuseInvitation(const QString& convUid)
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
2021-04-08 16:53:12 -04:00
|
|
|
const auto currentConvUid = convUid.isEmpty() ? lrcInstance_->get_selectedConvUid() : convUid;
|
2021-03-11 13:30:45 -05:00
|
|
|
lrcInstance_->getCurrentConversationModel()->removeConversation(currentConvUid, false);
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2020-09-10 17:40:51 -04:00
|
|
|
MessagesAdapter::blockConversation(const QString& convUid)
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
2021-04-08 16:53:12 -04:00
|
|
|
const auto currentConvUid = convUid.isEmpty() ? lrcInstance_->get_selectedConvUid() : convUid;
|
2021-03-11 13:30:45 -05:00
|
|
|
lrcInstance_->getCurrentConversationModel()->removeConversation(currentConvUid, true);
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
2020-12-15 13:49:19 -05:00
|
|
|
|
2021-08-26 14:57:24 -04:00
|
|
|
void
|
|
|
|
|
MessagesAdapter::unbanContact(int index)
|
|
|
|
|
{
|
|
|
|
|
auto& accountInfo = lrcInstance_->getCurrentAccountInfo();
|
|
|
|
|
auto bannedContactList = accountInfo.contactModel->getBannedContacts();
|
|
|
|
|
auto it = bannedContactList.begin();
|
|
|
|
|
std::advance(it, index);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
auto contactInfo = accountInfo.contactModel->getContact(*it);
|
|
|
|
|
accountInfo.contactModel->addContact(contactInfo);
|
|
|
|
|
} catch (const std::out_of_range& e) {
|
|
|
|
|
qDebug() << e.what();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 11:52:55 -04:00
|
|
|
void
|
|
|
|
|
MessagesAdapter::unbanConversation(const QString& convUid)
|
|
|
|
|
{
|
|
|
|
|
auto& accInfo = lrcInstance_->getCurrentAccountInfo();
|
|
|
|
|
try {
|
|
|
|
|
const auto contactUri = accInfo.conversationModel->peersForConversation(convUid).at(0);
|
|
|
|
|
auto contactInfo = accInfo.contactModel->getContact(contactUri);
|
|
|
|
|
accInfo.contactModel->addContact(contactInfo);
|
|
|
|
|
} catch (const std::out_of_range& e) {
|
|
|
|
|
qDebug() << e.what();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-15 13:49:19 -05:00
|
|
|
void
|
2021-02-26 09:42:33 +01:00
|
|
|
MessagesAdapter::clearConversationHistory(const QString& accountId, const QString& convUid)
|
2020-12-15 13:49:19 -05:00
|
|
|
{
|
2021-02-26 09:42:33 +01:00
|
|
|
lrcInstance_->getAccountInfo(accountId).conversationModel->clearHistory(convUid);
|
2020-12-15 13:49:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2021-08-06 18:03:15 -04:00
|
|
|
MessagesAdapter::removeConversation(const QString& convUid)
|
2020-12-15 13:49:19 -05:00
|
|
|
{
|
2021-08-06 18:03:15 -04:00
|
|
|
auto& accInfo = lrcInstance_->getCurrentAccountInfo();
|
|
|
|
|
accInfo.conversationModel->removeConversation(convUid);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-17 15:52:30 -05:00
|
|
|
void
|
|
|
|
|
MessagesAdapter::removeConversationMember(const QString& convUid, const QString& memberUri)
|
|
|
|
|
{
|
|
|
|
|
auto& accInfo = lrcInstance_->getCurrentAccountInfo();
|
|
|
|
|
accInfo.conversationModel->removeConversationMember(convUid, memberUri);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-05 16:08:44 -05:00
|
|
|
void
|
|
|
|
|
MessagesAdapter::addConversationMember(const QString& convUid, const QString& memberUri)
|
|
|
|
|
{
|
|
|
|
|
auto& accInfo = lrcInstance_->getCurrentAccountInfo();
|
|
|
|
|
accInfo.conversationModel->addConversationMember(convUid, memberUri);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-06 18:03:15 -04:00
|
|
|
void
|
|
|
|
|
MessagesAdapter::removeContact(const QString& convUid, bool banContact)
|
|
|
|
|
{
|
|
|
|
|
auto& accInfo = lrcInstance_->getCurrentAccountInfo();
|
2021-02-26 09:42:33 +01:00
|
|
|
|
2021-08-06 18:03:15 -04:00
|
|
|
// remove the uri from the default moderators list
|
|
|
|
|
// TODO: seems like this should be done in libringclient
|
|
|
|
|
QStringList list = lrcInstance_->accountModel().getDefaultModerators(accInfo.id);
|
|
|
|
|
const auto contactUri = accInfo.conversationModel->peersForConversation(convUid).at(0);
|
|
|
|
|
if (!contactUri.isEmpty() && list.contains(contactUri)) {
|
|
|
|
|
lrcInstance_->accountModel().setDefaultModerator(accInfo.id, contactUri, false);
|
2021-02-26 09:42:33 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-06 18:03:15 -04:00
|
|
|
// actually remove the contact
|
|
|
|
|
accInfo.contactModel->removeContact(contactUri, banContact);
|
2020-12-15 13:49:19 -05:00
|
|
|
}
|
2020-12-23 18:48:06 +01:00
|
|
|
|
2021-07-06 10:20:46 -04:00
|
|
|
void
|
2023-02-13 16:49:04 -05:00
|
|
|
MessagesAdapter::onConversationMessagesLoaded(uint32_t loadingRequestId, const QString& convId)
|
2021-07-06 10:20:46 -04:00
|
|
|
{
|
|
|
|
|
if (convId != lrcInstance_->get_selectedConvUid())
|
2020-12-23 18:48:06 +01:00
|
|
|
return;
|
2023-02-13 16:49:04 -05:00
|
|
|
Q_EMIT moreMessagesLoaded(loadingRequestId);
|
2021-07-06 10:20:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2023-03-20 16:26:37 -04:00
|
|
|
MessagesAdapter::parseMessage(const QString& msgId,
|
|
|
|
|
const QString& msg,
|
|
|
|
|
bool showPreview,
|
|
|
|
|
const QColor& linkColor,
|
|
|
|
|
const QColor& backgroundColor)
|
2021-07-06 10:20:46 -04:00
|
|
|
{
|
2023-03-20 16:26:37 -04:00
|
|
|
messageParser_->parseMessage(msgId, msg, showPreview, linkColor, backgroundColor);
|
2021-07-06 10:20:46 -04:00
|
|
|
}
|
|
|
|
|
|
2021-10-08 17:27:43 -04:00
|
|
|
void
|
|
|
|
|
MessagesAdapter::onComposingStatusChanged(const QString& convId,
|
|
|
|
|
const QString& contactUri,
|
|
|
|
|
bool isComposing)
|
|
|
|
|
{
|
2021-11-09 14:52:31 -05:00
|
|
|
Q_UNUSED(contactUri)
|
2021-10-08 17:27:43 -04:00
|
|
|
if (lrcInstance_->get_selectedConvUid() == convId) {
|
2021-11-09 14:52:31 -05:00
|
|
|
const QString& accId = lrcInstance_->get_currentAccountId();
|
|
|
|
|
auto& conversation = lrcInstance_->getConversationFromConvUid(convId, accId);
|
|
|
|
|
set_currentConvComposingList(conversationTypersUrlToName(conversation.typers));
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-08 17:27:43 -04:00
|
|
|
|
2022-10-13 14:41:28 -04:00
|
|
|
void
|
|
|
|
|
MessagesAdapter::onMessagesFoundProcessed(const QString& accountId,
|
2023-02-03 11:29:37 -05:00
|
|
|
const QMap<QString, interaction::Info>& messageInformation)
|
2022-10-13 14:41:28 -04:00
|
|
|
{
|
|
|
|
|
if (lrcInstance_->get_currentAccountId() != accountId) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-02-03 11:29:37 -05:00
|
|
|
|
|
|
|
|
bool isSearchInProgress = messageInformation.size();
|
2022-10-13 14:41:28 -04:00
|
|
|
if (isSearchInProgress) {
|
2023-02-03 11:29:37 -05:00
|
|
|
for (auto it = messageInformation.begin(); it != messageInformation.end(); it++) {
|
2023-12-20 17:16:07 -05:00
|
|
|
mediaInteractions_->append(it.key(), it.value());
|
2022-10-13 14:41:28 -04:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
set_mediaMessageListModel(QVariant::fromValue(mediaInteractions_.get()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-09 14:52:31 -05:00
|
|
|
QList<QString>
|
|
|
|
|
MessagesAdapter::conversationTypersUrlToName(const QSet<QString>& typersSet)
|
|
|
|
|
{
|
|
|
|
|
QList<QString> nameList;
|
|
|
|
|
for (const auto& id : typersSet) {
|
|
|
|
|
auto name = lrcInstance_->getCurrentContactModel()->bestNameForContact(id);
|
|
|
|
|
nameList.append(name);
|
2021-10-08 17:27:43 -04:00
|
|
|
}
|
2021-11-09 14:52:31 -05:00
|
|
|
|
|
|
|
|
return nameList;
|
2021-10-08 17:27:43 -04:00
|
|
|
}
|
|
|
|
|
|
2021-11-01 17:39:23 -04:00
|
|
|
QVariantMap
|
2022-05-13 10:20:46 -04:00
|
|
|
MessagesAdapter::isLocalImage(const QString& mimename)
|
|
|
|
|
{
|
|
|
|
|
if (mimename.startsWith("image/")) {
|
|
|
|
|
QString fileFormat = mimename;
|
|
|
|
|
fileFormat.replace("image/", "");
|
|
|
|
|
QImageReader reader;
|
|
|
|
|
QList<QByteArray> supportedFormats = reader.supportedImageFormats();
|
|
|
|
|
auto iterator = std::find_if(supportedFormats.begin(),
|
2022-07-19 15:57:44 -04:00
|
|
|
supportedFormats.end(),
|
|
|
|
|
[fileFormat](QByteArray format) {
|
|
|
|
|
return format == fileFormat;
|
|
|
|
|
});
|
2022-11-21 09:26:55 -05:00
|
|
|
if (iterator != supportedFormats.end() && *iterator == "gif") {
|
2022-11-18 17:17:34 -05:00
|
|
|
return {{"isAnimatedImage", true}};
|
|
|
|
|
}
|
2022-05-13 10:20:46 -04:00
|
|
|
return {{"isImage", iterator != supportedFormats.end()}};
|
2021-11-01 17:39:23 -04:00
|
|
|
}
|
|
|
|
|
return {{"isImage", false}};
|
2021-09-27 10:29:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap
|
|
|
|
|
MessagesAdapter::getMediaInfo(const QString& msg)
|
|
|
|
|
{
|
|
|
|
|
auto filePath = QFileInfo(msg).absoluteFilePath();
|
|
|
|
|
static const QString html
|
|
|
|
|
= "<body style='margin:0;padding:0;'>"
|
|
|
|
|
"<%1 style='width:100%;height:%2;outline:none;background-color:#f1f3f4;"
|
|
|
|
|
"object-fit:cover;' "
|
2023-05-25 15:46:31 -04:00
|
|
|
"controls controlsList='nodownload noplaybackrate' src='file://%3' type='%4'/></body>";
|
2022-05-13 10:20:46 -04:00
|
|
|
QMimeDatabase db;
|
|
|
|
|
QMimeType mime = db.mimeTypeForFile(filePath);
|
|
|
|
|
QVariantMap fileInfo = isLocalImage(mime.name());
|
2021-11-01 17:39:23 -04:00
|
|
|
if (fileInfo["isImage"].toBool() || fileInfo["isAnimatedImage"].toBool()) {
|
|
|
|
|
return fileInfo;
|
2021-09-27 10:29:07 -04:00
|
|
|
}
|
2022-05-13 10:20:46 -04:00
|
|
|
static const QRegExp vPattern("(video/)(avi|mov|webm|webp|rmvb)$", Qt::CaseInsensitive);
|
2023-01-30 14:43:15 -05:00
|
|
|
vPattern.indexIn(mime.name());
|
2023-05-16 14:02:14 -04:00
|
|
|
auto captured = vPattern.capturedTexts();
|
|
|
|
|
QString type = captured.size() == 3 ? captured[1] : "";
|
2021-09-27 10:29:07 -04:00
|
|
|
if (!type.isEmpty()) {
|
|
|
|
|
return {
|
|
|
|
|
{"isVideo", true},
|
2023-04-04 12:03:51 -04:00
|
|
|
{"isAudio", false},
|
2022-05-13 10:20:46 -04:00
|
|
|
{"html", html.arg("video", "100%", filePath, mime.name())},
|
2021-09-27 10:29:07 -04:00
|
|
|
};
|
|
|
|
|
} else {
|
2022-05-13 10:20:46 -04:00
|
|
|
static const QRegExp aPattern("(audio/)(ogg|flac|wav|mpeg|mp3)$", Qt::CaseInsensitive);
|
2023-01-30 14:43:15 -05:00
|
|
|
aPattern.indexIn(mime.name());
|
2023-05-16 14:02:14 -04:00
|
|
|
captured = aPattern.capturedTexts();
|
|
|
|
|
type = captured.size() == 3 ? captured[1] : "";
|
2021-09-27 10:29:07 -04:00
|
|
|
if (!type.isEmpty()) {
|
|
|
|
|
return {
|
|
|
|
|
{"isVideo", false},
|
2023-04-04 12:03:51 -04:00
|
|
|
{"isAudio", true},
|
2022-05-13 10:20:46 -04:00
|
|
|
{"html", html.arg("audio", "54px", filePath, mime.name())},
|
2021-09-27 10:29:07 -04:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {};
|
2021-07-06 10:20:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
2021-09-27 10:29:07 -04:00
|
|
|
MessagesAdapter::isRemoteImage(const QString& msg)
|
2021-07-06 10:20:46 -04:00
|
|
|
{
|
2021-09-27 10:29:07 -04:00
|
|
|
// TODO: test if all these open in the AnimatedImage component
|
2023-05-16 14:02:14 -04:00
|
|
|
const static QRegularExpression
|
|
|
|
|
imageRe("[^\\s]+(.*?)\\.(jpg|jpeg|png|gif|apng|webp|avif|flif)$",
|
|
|
|
|
QRegularExpression::CaseInsensitiveOption);
|
|
|
|
|
QRegularExpressionMatch match = imageRe.match(msg);
|
2021-07-06 10:20:46 -04:00
|
|
|
return match.hasMatch();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
|
MessagesAdapter::getFormattedTime(const quint64 timestamp)
|
|
|
|
|
{
|
2023-02-02 14:52:58 -05:00
|
|
|
const auto currentTime = QDateTime::currentDateTime();
|
|
|
|
|
const auto seconds = currentTime.toSecsSinceEpoch() - timestamp;
|
2022-09-12 09:36:50 -04:00
|
|
|
auto interval = qFloor(seconds / 60);
|
|
|
|
|
|
|
|
|
|
if (interval > 1) {
|
2023-02-14 14:01:40 -03:00
|
|
|
auto curLang = settingsManager_->getLanguage();
|
|
|
|
|
auto curLocal = QLocale(curLang);
|
2022-09-12 09:36:50 -04:00
|
|
|
auto curTime = QDateTime::fromSecsSinceEpoch(timestamp).time();
|
|
|
|
|
QString timeLocale;
|
2023-12-01 15:16:58 -05:00
|
|
|
timeLocale = curLocal.toString(curTime, curLocal.ShortFormat).toLower();
|
2022-09-12 09:36:50 -04:00
|
|
|
return timeLocale;
|
|
|
|
|
}
|
2024-11-02 15:05:24 -04:00
|
|
|
return QObject::tr("Just now");
|
2020-12-23 18:48:06 +01:00
|
|
|
}
|
2022-09-12 09:36:50 -04:00
|
|
|
|
2023-02-02 14:52:58 -05:00
|
|
|
QString
|
|
|
|
|
MessagesAdapter::getBestFormattedDate(const quint64 timestamp)
|
|
|
|
|
{
|
|
|
|
|
auto currentDate = QDate::currentDate();
|
|
|
|
|
auto timestampDate = QDateTime::fromSecsSinceEpoch(timestamp).date();
|
|
|
|
|
if (timestampDate == currentDate)
|
|
|
|
|
return getFormattedTime(timestamp);
|
|
|
|
|
return getFormattedDay(timestamp);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-12 09:36:50 -04:00
|
|
|
QString
|
|
|
|
|
MessagesAdapter::getFormattedDay(const quint64 timestamp)
|
|
|
|
|
{
|
2023-02-02 14:52:58 -05:00
|
|
|
auto currentDate = QDate::currentDate();
|
|
|
|
|
auto timestampDate = QDateTime::fromSecsSinceEpoch(timestamp).date();
|
|
|
|
|
if (timestampDate == currentDate)
|
2022-09-12 09:36:50 -04:00
|
|
|
return QObject::tr("Today");
|
2023-02-02 14:52:58 -05:00
|
|
|
if (timestampDate.daysTo(currentDate) == 1)
|
2022-09-12 09:36:50 -04:00
|
|
|
return QObject::tr("Yesterday");
|
|
|
|
|
|
2023-02-14 14:01:40 -03:00
|
|
|
auto curLang = settingsManager_->getLanguage();
|
|
|
|
|
auto curLocal = QLocale(curLang);
|
2022-09-12 09:36:50 -04:00
|
|
|
auto curDate = QDateTime::fromSecsSinceEpoch(timestamp).date();
|
|
|
|
|
QString dateLocale;
|
2023-02-14 14:01:40 -03:00
|
|
|
dateLocale = curLocal.toString(curDate, curLocal.ShortFormat);
|
2022-09-12 09:36:50 -04:00
|
|
|
|
|
|
|
|
return dateLocale;
|
|
|
|
|
}
|
2022-10-13 14:41:28 -04:00
|
|
|
|
|
|
|
|
void
|
2023-04-24 16:43:58 -04:00
|
|
|
MessagesAdapter::startSearch(const QString& text, bool isMedia)
|
2022-10-13 14:41:28 -04:00
|
|
|
{
|
2023-07-06 11:31:20 -04:00
|
|
|
auto accountId = lrcInstance_->get_currentAccountId();
|
|
|
|
|
mediaInteractions_.reset(new MessageListModel(&lrcInstance_->getCurrentAccountInfo(), this));
|
2023-02-03 11:29:37 -05:00
|
|
|
set_mediaMessageListModel(QVariant::fromValue(mediaInteractions_.get()));
|
|
|
|
|
|
|
|
|
|
if (text.isEmpty() && !isMedia)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-10-13 14:41:28 -04:00
|
|
|
auto convId = lrcInstance_->get_selectedConvUid();
|
|
|
|
|
|
|
|
|
|
try {
|
2023-02-03 11:29:37 -05:00
|
|
|
lrcInstance_->getCurrentConversationModel()->getConvMediasInfos(accountId,
|
|
|
|
|
convId,
|
|
|
|
|
text,
|
|
|
|
|
isMedia);
|
2022-10-13 14:41:28 -04:00
|
|
|
} catch (...) {
|
2023-02-03 11:29:37 -05:00
|
|
|
qDebug() << "Exception during startSearch()";
|
2022-10-13 14:41:28 -04:00
|
|
|
}
|
|
|
|
|
}
|
2023-02-01 17:33:24 -05:00
|
|
|
|
|
|
|
|
MessageListModel*
|
|
|
|
|
MessagesAdapter::getMsgListSourceModel() const
|
|
|
|
|
{
|
|
|
|
|
// We are certain that filteredMsgListModel_'s source model is a MessageListModel,
|
|
|
|
|
// However it may be a nullptr if not yet set.
|
|
|
|
|
return static_cast<MessageListModel*>(filteredMsgListModel_->sourceModel());
|
|
|
|
|
}
|