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"
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
|
|
|
|
2020-09-03 09:24:49 -04:00
|
|
|
class MessagesAdapter final : public QmlAdapterBase
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2020-09-10 17:40:51 -04:00
|
|
|
explicit MessagesAdapter(QObject* parent = 0);
|
2020-09-03 09:24:49 -04:00
|
|
|
~MessagesAdapter() = default;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void safeInit() override;
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-10 17:40:51 -04:00
|
|
|
Q_INVOKABLE void setupChatView(const QString& uid);
|
2020-08-03 13:27:42 -04:00
|
|
|
Q_INVOKABLE void connectConversationModel();
|
|
|
|
Q_INVOKABLE void sendContactRequest();
|
|
|
|
Q_INVOKABLE void updateConversationForAddedContact();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
Q_INVOKABLE void sendMessage(const QString& message);
|
|
|
|
Q_INVOKABLE void sendImage(const QString& message);
|
|
|
|
Q_INVOKABLE void sendFile(const QString& message);
|
|
|
|
Q_INVOKABLE void retryInteraction(const QString& arg);
|
|
|
|
Q_INVOKABLE void deleteInteraction(const QString& arg);
|
|
|
|
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);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Manually update draft when hiding message web view (Back to welcome page).
|
|
|
|
*/
|
|
|
|
Q_INVOKABLE void updateDraft();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run corrsponding js functions, c++ to qml.
|
|
|
|
*/
|
|
|
|
void setMessagesVisibility(bool visible);
|
|
|
|
void requestSendMessageContent();
|
2020-09-10 17:40:51 -04:00
|
|
|
void setInvitation(bool show, const QString& contactUri = "", const QString& contactId = "");
|
2020-08-03 13:27:42 -04:00
|
|
|
void clear();
|
2020-09-10 17:40:51 -04:00
|
|
|
void printHistory(lrc::api::ConversationModel& conversationModel,
|
2020-08-03 13:27:42 -04:00
|
|
|
const std::map<uint64_t, lrc::api::interaction::Info> interactions);
|
2020-09-10 17:40:51 -04:00
|
|
|
void setSenderImage(const QString& sender, const QString& senderImage);
|
|
|
|
void printNewInteraction(lrc::api::ConversationModel& conversationModel,
|
2020-08-03 13:27:42 -04:00
|
|
|
uint64_t msgId,
|
2020-09-10 17:40:51 -04:00
|
|
|
const lrc::api::interaction::Info& interaction);
|
|
|
|
void updateInteraction(lrc::api::ConversationModel& conversationModel,
|
2020-08-03 13:27:42 -04:00
|
|
|
uint64_t 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);
|
2020-08-03 13:27:42 -04:00
|
|
|
void removeInteraction(uint64_t interactionId);
|
2020-09-10 17:40:51 -04:00
|
|
|
void setSendMessageContent(const QString& content);
|
|
|
|
void contactIsComposing(const QString& uid, const QString& contactUri, bool isComposing);
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void needToUpdateSmartList();
|
2020-09-08 12:59:34 -04:00
|
|
|
void contactBanned();
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
public 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,
|
2020-08-03 13:27:42 -04:00
|
|
|
uint64_t interactionId,
|
2020-09-10 17:40:51 -04:00
|
|
|
const interaction::Info& interaction);
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
QString LastConvUid_;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interaction connections.
|
|
|
|
*/
|
|
|
|
QMetaObject::Connection newInteractionConnection_;
|
|
|
|
QMetaObject::Connection interactionStatusUpdatedConnection_;
|
|
|
|
QMetaObject::Connection interactionRemovedConnection_;
|
2020-08-18 17:21:28 +02:00
|
|
|
};
|