2020-09-03 09:24:49 -04:00
|
|
|
/*!
|
2020-08-03 13:27:42 -04:00
|
|
|
* Copyright (C) 2020 by Savoir-faire Linux
|
|
|
|
* 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"
|
2020-10-14 15:41:03 -04:00
|
|
|
#include "api/chatview.h"
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
|
|
|
|
2021-03-30 15:15:36 -04:00
|
|
|
class AppSettingsManager;
|
|
|
|
|
2020-09-03 09:24:49 -04:00
|
|
|
class MessagesAdapter final : public QmlAdapterBase
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2020-10-14 15:41:03 -04:00
|
|
|
Q_PROPERTY(QVariantMap chatviewTranslatedStrings MEMBER chatviewTranslatedStrings_ CONSTANT)
|
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
public:
|
2021-03-30 15:15:36 -04:00
|
|
|
explicit MessagesAdapter(AppSettingsManager* settingsManager,
|
|
|
|
LRCInstance* instance,
|
|
|
|
QObject* parent = nullptr);
|
2020-09-03 09:24:49 -04:00
|
|
|
~MessagesAdapter() = default;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void safeInit() override;
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-02-26 09:42:33 +01:00
|
|
|
Q_INVOKABLE void setupChatView(const QString& convUid);
|
2020-08-03 13:27:42 -04:00
|
|
|
Q_INVOKABLE void connectConversationModel();
|
2021-06-22 14:31:42 -04:00
|
|
|
Q_INVOKABLE void sendConversationRequest();
|
2020-12-15 13:49:19 -05:00
|
|
|
Q_INVOKABLE void removeConversation(const QString& accountId,
|
2021-02-26 09:42:33 +01:00
|
|
|
const QString& convUid,
|
2020-12-15 13:49:19 -05:00
|
|
|
bool banContact = false);
|
2021-02-26 09:42:33 +01:00
|
|
|
Q_INVOKABLE void clearConversationHistory(const QString& accountId, const QString& convUid);
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-03-11 13:30:45 -05:00
|
|
|
// JS Q_INVOKABLE.
|
2020-09-10 17:40:51 -04:00
|
|
|
Q_INVOKABLE void acceptInvitation(const QString& convUid = "");
|
|
|
|
Q_INVOKABLE void refuseInvitation(const QString& convUid = "");
|
|
|
|
Q_INVOKABLE void blockConversation(const QString& convUid = "");
|
|
|
|
Q_INVOKABLE void setNewMessagesContent(const QString& path);
|
2020-11-05 14:41:25 -05:00
|
|
|
Q_INVOKABLE void setDisplayLinks();
|
2020-09-10 17:40:51 -04:00
|
|
|
Q_INVOKABLE void sendMessage(const QString& message);
|
|
|
|
Q_INVOKABLE void sendImage(const QString& message);
|
|
|
|
Q_INVOKABLE void sendFile(const QString& message);
|
2021-05-12 16:55:28 -04:00
|
|
|
Q_INVOKABLE void retryInteraction(const QString& interactionId);
|
|
|
|
Q_INVOKABLE void deleteInteraction(const QString& interactionId);
|
2020-09-10 17:40:51 -04:00
|
|
|
Q_INVOKABLE void openUrl(const QString& url);
|
|
|
|
Q_INVOKABLE void openFile(const QString& arg);
|
|
|
|
Q_INVOKABLE void acceptFile(const QString& arg);
|
|
|
|
Q_INVOKABLE void refuseFile(const QString& arg);
|
2020-08-03 13:27:42 -04:00
|
|
|
Q_INVOKABLE void pasteKeyDetected();
|
|
|
|
Q_INVOKABLE void onComposing(bool isComposing);
|
2020-12-23 18:48:06 +01:00
|
|
|
Q_INVOKABLE void loadMessages(int n);
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-03-11 13:30:45 -05:00
|
|
|
// Manually update draft when hiding message web view (Back to welcome page).
|
2020-08-03 13:27:42 -04:00
|
|
|
Q_INVOKABLE void updateDraft();
|
|
|
|
|
2021-03-11 13:30:45 -05:00
|
|
|
// Run corrsponding js functions, c++ to qml.
|
2020-08-03 13:27:42 -04:00
|
|
|
void setMessagesVisibility(bool visible);
|
|
|
|
void requestSendMessageContent();
|
2021-05-14 17:01:58 -04:00
|
|
|
void setInvitation(bool show,
|
|
|
|
const QString& contactUri = {},
|
|
|
|
const QString& contactId = {},
|
|
|
|
bool isSwarm = false,
|
|
|
|
bool needsSyncing = false);
|
2021-05-17 10:06:57 -04:00
|
|
|
void setIsSwarm(bool isSwarm);
|
2021-06-22 14:31:42 -04:00
|
|
|
void clearChatView();
|
2020-12-23 18:48:06 +01:00
|
|
|
void printHistory(ConversationModel& conversationModel, MessagesList interactions);
|
|
|
|
void updateHistory(ConversationModel& conversationModel,
|
|
|
|
MessagesList interactions,
|
|
|
|
bool allLoaded);
|
2020-09-10 17:40:51 -04:00
|
|
|
void setSenderImage(const QString& sender, const QString& senderImage);
|
|
|
|
void printNewInteraction(lrc::api::ConversationModel& conversationModel,
|
2021-05-12 16:55:28 -04:00
|
|
|
const QString& msgId,
|
2020-09-10 17:40:51 -04:00
|
|
|
const lrc::api::interaction::Info& interaction);
|
|
|
|
void updateInteraction(lrc::api::ConversationModel& conversationModel,
|
2021-05-12 16:55:28 -04:00
|
|
|
const QString& msgId,
|
2020-09-10 17:40:51 -04:00
|
|
|
const lrc::api::interaction::Info& interaction);
|
|
|
|
void setMessagesImageContent(const QString& path, bool isBased64 = false);
|
|
|
|
void setMessagesFileContent(const QString& path);
|
2021-05-12 16:55:28 -04:00
|
|
|
void removeInteraction(const QString& interactionId);
|
2020-09-10 17:40:51 -04:00
|
|
|
void setSendMessageContent(const QString& content);
|
2021-01-18 15:44:36 +01:00
|
|
|
void contactIsComposing(const QString& convUid, const QString& contactUri, bool isComposing);
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-03-29 16:51:53 -04:00
|
|
|
Q_SIGNALS:
|
2020-09-08 12:59:34 -04:00
|
|
|
void contactBanned();
|
2021-05-20 16:56:33 -04:00
|
|
|
void newInteraction(int type);
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-03-29 16:51:53 -04:00
|
|
|
public Q_SLOTS:
|
2020-09-10 17:40:51 -04:00
|
|
|
void slotSendMessageContentSaved(const QString& content);
|
|
|
|
void slotUpdateDraft(const QString& content);
|
2020-08-03 13:27:42 -04:00
|
|
|
void slotMessagesCleared();
|
|
|
|
void slotMessagesLoaded();
|
|
|
|
|
|
|
|
private:
|
2020-09-10 17:40:51 -04:00
|
|
|
void setConversationProfileData(const lrc::api::conversation::Info& convInfo);
|
|
|
|
void newInteraction(const QString& accountId,
|
|
|
|
const QString& convUid,
|
2021-05-12 16:55:28 -04:00
|
|
|
const QString& interactionId,
|
2020-09-10 17:40:51 -04:00
|
|
|
const interaction::Info& interaction);
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
QString LastConvUid_;
|
2020-09-24 13:50:04 +02:00
|
|
|
QString currentConvUid_;
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-10-14 15:41:03 -04:00
|
|
|
const QVariantMap chatviewTranslatedStrings_ {lrc::api::chatview::getTranslatedStrings()};
|
|
|
|
|
2021-03-11 13:30:45 -05:00
|
|
|
// Interaction connections.
|
2020-08-03 13:27:42 -04:00
|
|
|
QMetaObject::Connection newInteractionConnection_;
|
|
|
|
QMetaObject::Connection interactionStatusUpdatedConnection_;
|
|
|
|
QMetaObject::Connection interactionRemovedConnection_;
|
2021-05-12 16:55:28 -04:00
|
|
|
QMetaObject::Connection newMessagesAvailableConnection_;
|
2021-05-17 14:45:32 -04:00
|
|
|
QMetaObject::Connection conversationUpdatedConnection_;
|
2021-03-30 15:15:36 -04:00
|
|
|
|
|
|
|
AppSettingsManager* settingsManager_;
|
2020-08-18 17:21:28 +02:00
|
|
|
};
|