2021-07-06 10:20:46 -04:00
|
|
|
/*
|
2023-02-06 01:47:15 -05:00
|
|
|
* Copyright (C) 2020-2023 Savoir-faire Linux Inc.
|
2020-08-03 13:27:42 -04:00
|
|
|
* Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "lrcinstance.h"
|
|
|
|
#include "qmladapterbase.h"
|
2021-07-06 10:20:46 -04:00
|
|
|
#include "previewengine.h"
|
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
2023-02-01 17:33:24 -05:00
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
|
2023-03-20 16:26:37 -04:00
|
|
|
class AppSettingsManager;
|
|
|
|
class MessageParser;
|
|
|
|
|
2023-02-01 17:33:24 -05:00
|
|
|
class FilteredMsgListModel final : public QSortFilterProxyModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit FilteredMsgListModel(QObject* parent = nullptr)
|
|
|
|
: QSortFilterProxyModel(parent)
|
|
|
|
{
|
|
|
|
sort(0, Qt::AscendingOrder);
|
|
|
|
}
|
|
|
|
bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override
|
|
|
|
{
|
|
|
|
auto index = sourceModel()->index(sourceRow, 0, sourceParent);
|
|
|
|
auto type = static_cast<interaction::Type>(
|
|
|
|
sourceModel()->data(index, MessageList::Role::Type).toInt());
|
2023-02-03 15:54:28 -05:00
|
|
|
return interaction::isDisplayedInChatview(type);
|
2023-02-01 17:33:24 -05:00
|
|
|
};
|
|
|
|
bool lessThan(const QModelIndex& left, const QModelIndex& right) const override
|
|
|
|
{
|
|
|
|
return left.row() > right.row();
|
|
|
|
};
|
|
|
|
};
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-03 09:24:49 -04:00
|
|
|
class MessagesAdapter final : public QmlAdapterBase
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2021-07-06 10:20:46 -04:00
|
|
|
QML_RO_PROPERTY(QVariant, messageListModel)
|
2022-07-19 15:57:44 -04:00
|
|
|
QML_PROPERTY(QString, replyToId)
|
2022-10-11 16:24:04 -04:00
|
|
|
QML_PROPERTY(QString, editId)
|
2021-10-08 17:27:43 -04:00
|
|
|
QML_RO_PROPERTY(QList<QString>, currentConvComposingList)
|
2022-10-13 14:41:28 -04:00
|
|
|
QML_PROPERTY(QVariant, mediaMessageListModel)
|
2023-02-03 11:29:37 -05:00
|
|
|
QML_PROPERTY(QString, searchbarPrompt)
|
2020-10-14 15:41:03 -04:00
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
public:
|
2021-03-30 15:15:36 -04:00
|
|
|
explicit 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 = nullptr);
|
2020-09-03 09:24:49 -04:00
|
|
|
~MessagesAdapter() = default;
|
|
|
|
|
2021-07-06 10:20:46 -04:00
|
|
|
Q_SIGNALS:
|
2022-07-19 15:57:44 -04:00
|
|
|
void newInteraction(const QString& id, int type);
|
2023-02-03 11:29:37 -05:00
|
|
|
void newMessageBarPlaceholderText(QString& placeholderText);
|
2021-07-06 10:20:46 -04:00
|
|
|
void newFilePasted(QString filePath);
|
|
|
|
void newTextPasted();
|
2023-02-13 16:49:04 -05:00
|
|
|
void moreMessagesLoaded(qint32 loadingRequestId);
|
2023-02-01 17:33:24 -05:00
|
|
|
void timestampUpdated();
|
2023-04-07 14:14:54 -04:00
|
|
|
void fileCopied(const QString& dest);
|
2023-07-06 14:48:03 -04:00
|
|
|
void messageParsed(const QString& msgId, const QString& msg);
|
2021-07-06 10:20:46 -04:00
|
|
|
|
2020-09-03 09:24:49 -04:00
|
|
|
protected:
|
2023-02-03 11:29:37 -05:00
|
|
|
Q_INVOKABLE bool isDocument(const interaction::Type& type);
|
2021-07-06 10:20:46 -04:00
|
|
|
Q_INVOKABLE void loadMoreMessages();
|
2020-08-03 13:27:42 -04:00
|
|
|
Q_INVOKABLE void connectConversationModel();
|
2021-06-22 14:31:42 -04:00
|
|
|
Q_INVOKABLE void sendConversationRequest();
|
2021-08-06 18:03:15 -04:00
|
|
|
Q_INVOKABLE void removeConversation(const QString& convUid);
|
2023-01-05 16:08:44 -05:00
|
|
|
Q_INVOKABLE void addConversationMember(const QString& convUid, const QString& participantUri);
|
2021-12-17 15:52:30 -05:00
|
|
|
Q_INVOKABLE void removeConversationMember(const QString& convUid, const QString& participantUri);
|
2021-08-06 18:03:15 -04:00
|
|
|
Q_INVOKABLE void removeContact(const QString& convUid, bool banContact = false);
|
2021-02-26 09:42:33 +01:00
|
|
|
Q_INVOKABLE void clearConversationHistory(const QString& accountId, const QString& convUid);
|
2021-06-25 14:37:55 -04:00
|
|
|
Q_INVOKABLE void acceptInvitation(const QString& convId = {});
|
2020-09-10 17:40:51 -04:00
|
|
|
Q_INVOKABLE void refuseInvitation(const QString& convUid = "");
|
|
|
|
Q_INVOKABLE void blockConversation(const QString& convUid = "");
|
2021-08-26 14:57:24 -04:00
|
|
|
Q_INVOKABLE void unbanContact(int index);
|
2022-07-04 11:52:55 -04:00
|
|
|
Q_INVOKABLE void unbanConversation(const QString& convUid);
|
2020-09-10 17:40:51 -04:00
|
|
|
Q_INVOKABLE void sendMessage(const QString& message);
|
2022-10-11 16:24:04 -04:00
|
|
|
Q_INVOKABLE void editMessage(const QString& convId,
|
|
|
|
const QString& newBody,
|
|
|
|
const QString& messageId = "");
|
2022-11-23 09:50:53 -05:00
|
|
|
Q_INVOKABLE void addEmojiReaction(const QString& convId,
|
|
|
|
const QString& emoji,
|
|
|
|
const QString& messageId = "");
|
|
|
|
Q_INVOKABLE void removeEmojiReaction(const QString& convId,
|
|
|
|
const QString& emoji,
|
|
|
|
const QString& messageId);
|
2020-09-10 17:40:51 -04:00
|
|
|
Q_INVOKABLE void sendFile(const QString& message);
|
|
|
|
Q_INVOKABLE void acceptFile(const QString& arg);
|
2021-09-27 10:29:07 -04:00
|
|
|
Q_INVOKABLE void cancelFile(const QString& arg);
|
2021-07-06 10:20:46 -04:00
|
|
|
Q_INVOKABLE void openUrl(const QString& url);
|
2021-10-25 16:18:06 -04:00
|
|
|
Q_INVOKABLE void openDirectory(const QString& arg);
|
2023-08-03 16:32:32 -04:00
|
|
|
Q_INVOKABLE void removeFile(const QString& interactionId, const QString& path);
|
2022-06-09 11:23:14 -04:00
|
|
|
Q_INVOKABLE void joinCall(const QString& uri,
|
|
|
|
const QString& deviceId,
|
|
|
|
const QString& confId,
|
|
|
|
bool isAudioOnly = false);
|
2021-06-28 09:14:31 -04:00
|
|
|
Q_INVOKABLE void copyToDownloads(const QString& interactionId, const QString& displayName);
|
2021-07-06 10:20:46 -04:00
|
|
|
Q_INVOKABLE void userIsComposing(bool isComposing);
|
2022-05-13 10:20:46 -04:00
|
|
|
Q_INVOKABLE QVariantMap isLocalImage(const QString& mimeName);
|
2021-09-27 10:29:07 -04:00
|
|
|
Q_INVOKABLE QVariantMap getMediaInfo(const QString& msg);
|
|
|
|
Q_INVOKABLE bool isRemoteImage(const QString& msg);
|
2022-09-12 09:36:50 -04:00
|
|
|
Q_INVOKABLE QString getFormattedDay(const quint64 timestamp);
|
2021-07-06 10:20:46 -04:00
|
|
|
Q_INVOKABLE QString getFormattedTime(const quint64 timestamp);
|
2023-02-02 14:52:58 -05:00
|
|
|
Q_INVOKABLE QString getBestFormattedDate(const quint64 timestamp);
|
2023-03-20 16:26:37 -04:00
|
|
|
Q_INVOKABLE void parseMessage(const QString& msgId,
|
|
|
|
const QString& msg,
|
|
|
|
bool previewLinks,
|
|
|
|
const QColor& linkColor = QColor(0x06, 0x45, 0xad),
|
|
|
|
const QColor& backgroundColor = QColor(0x0, 0x0, 0x0));
|
2021-07-06 10:20:46 -04:00
|
|
|
Q_INVOKABLE void onPaste();
|
2022-07-19 15:57:44 -04:00
|
|
|
Q_INVOKABLE int getIndexOfMessage(const QString& messageId) const;
|
2021-09-27 10:29:07 -04:00
|
|
|
Q_INVOKABLE QString getStatusString(int status);
|
|
|
|
Q_INVOKABLE QVariantMap getTransferStats(const QString& messageId, int);
|
2022-07-19 15:57:44 -04:00
|
|
|
Q_INVOKABLE QVariant dataForInteraction(const QString& interactionId,
|
|
|
|
int role = Qt::DisplayRole) const;
|
2023-04-24 16:43:58 -04:00
|
|
|
Q_INVOKABLE void startSearch(const QString& text, bool isMedia);
|
2023-06-14 11:21:36 -04:00
|
|
|
Q_INVOKABLE int getMessageIndexFromId(const QString& id);
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-03-11 13:30:45 -05:00
|
|
|
// Run corrsponding js functions, c++ to qml.
|
2020-09-10 17:40:51 -04:00
|
|
|
void setMessagesImageContent(const QString& path, bool isBased64 = false);
|
|
|
|
void setMessagesFileContent(const QString& path);
|
|
|
|
void setSendMessageContent(const QString& content);
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2023-02-01 17:33:24 -05:00
|
|
|
inline MessageListModel* getMsgListSourceModel() const;
|
|
|
|
|
2021-06-25 14:37:55 -04:00
|
|
|
private Q_SLOTS:
|
|
|
|
void onNewInteraction(const QString& convUid,
|
|
|
|
const QString& interactionId,
|
|
|
|
const interaction::Info& interaction);
|
2023-03-20 16:26:37 -04:00
|
|
|
void onMessageParsed(const QString& messageId, const QString& parsed);
|
|
|
|
void onLinkInfoReady(const QString& messageIndex, const QVariantMap& info);
|
2021-07-06 10:20:46 -04:00
|
|
|
void onConversationMessagesLoaded(uint32_t requestId, const QString& convId);
|
2021-10-08 17:27:43 -04:00
|
|
|
void onComposingStatusChanged(const QString& convId,
|
|
|
|
const QString& contactUri,
|
|
|
|
bool isComposing);
|
2022-10-13 14:41:28 -04:00
|
|
|
void onMessagesFoundProcessed(const QString& accountId,
|
2023-02-03 11:29:37 -05:00
|
|
|
const QMap<QString, interaction::Info>& messageInformation);
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
private:
|
2021-11-09 14:52:31 -05:00
|
|
|
QList<QString> conversationTypersUrlToName(const QSet<QString>& typersSet);
|
|
|
|
|
2021-03-30 15:15:36 -04:00
|
|
|
AppSettingsManager* settingsManager_;
|
2023-03-20 16:26:37 -04:00
|
|
|
MessageParser* messageParser_;
|
|
|
|
|
2023-02-01 17:33:24 -05:00
|
|
|
FilteredMsgListModel* filteredMsgListModel_;
|
2021-07-06 10:20:46 -04:00
|
|
|
|
|
|
|
static constexpr const int loadChunkSize_ {20};
|
2022-10-13 14:41:28 -04:00
|
|
|
|
|
|
|
std::unique_ptr<MessageListModel> mediaInteractions_;
|
2023-02-01 17:33:24 -05:00
|
|
|
|
|
|
|
QTimer* timestampTimer_ {nullptr};
|
|
|
|
static constexpr const int timestampUpdateIntervalMs_ {1000};
|
2020-08-18 17:21:28 +02:00
|
|
|
};
|