blob: 6b520d2bd6727aaa38b75a9bf12782d7c780be82 [file] [log] [blame]
Sébastien Blin1f915762020-08-03 13:27:42 -04001/*
2 * Copyright (C) 2020 by Savoir-faire Linux
3 * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21#include "lrcinstance.h"
22#include "qmladapterbase.h"
23
24#include <QObject>
25#include <QString>
26
27class MessagesAdapter : public QmlAdapterBase
28{
29 Q_OBJECT
30
31public:
32 explicit MessagesAdapter(QObject *parent = 0);
33 ~MessagesAdapter();
34
35 Q_INVOKABLE void setupChatView(const QString &uid);
36 Q_INVOKABLE void connectConversationModel();
37 Q_INVOKABLE void sendContactRequest();
ababi0b686642020-08-18 17:21:28 +020038 Q_INVOKABLE void accountChangedSetUp(const QString &accountId);
Sébastien Blin1f915762020-08-03 13:27:42 -040039 Q_INVOKABLE void updateConversationForAddedContact();
40
41 /*
42 * JS Q_INVOKABLE.
43 */
44 Q_INVOKABLE void acceptInvitation();
45 Q_INVOKABLE void refuseInvitation();
46 Q_INVOKABLE void blockConversation();
47 Q_INVOKABLE void setNewMessagesContent(const QString &path);
48 Q_INVOKABLE void sendMessage(const QString &message);
49 Q_INVOKABLE void sendImage(const QString &message);
50 Q_INVOKABLE void sendFile(const QString &message);
51 Q_INVOKABLE void retryInteraction(const QString &arg);
52 Q_INVOKABLE void deleteInteraction(const QString &arg);
53 Q_INVOKABLE void openFile(const QString &arg);
54 Q_INVOKABLE void acceptFile(const QString &arg);
55 Q_INVOKABLE void refuseFile(const QString &arg);
56 Q_INVOKABLE void pasteKeyDetected();
57 Q_INVOKABLE void onComposing(bool isComposing);
58
59 /*
60 * Manually update draft when hiding message web view (Back to welcome page).
61 */
62 Q_INVOKABLE void updateDraft();
63
64 /*
65 * Run corrsponding js functions, c++ to qml.
66 */
67 void setMessagesVisibility(bool visible);
68 void requestSendMessageContent();
69 void setInvitation(bool show, const QString &contactUri = "", const QString &contactId = "");
70 void clear();
71 void printHistory(lrc::api::ConversationModel &conversationModel,
72 const std::map<uint64_t, lrc::api::interaction::Info> interactions);
73 void setSenderImage(const QString &sender, const QString &senderImage);
74 void printNewInteraction(lrc::api::ConversationModel &conversationModel,
75 uint64_t msgId,
76 const lrc::api::interaction::Info &interaction);
77 void updateInteraction(lrc::api::ConversationModel &conversationModel,
78 uint64_t msgId,
79 const lrc::api::interaction::Info &interaction);
80 void setMessagesImageContent(const QString &path, bool isBased64 = false);
81 void setMessagesFileContent(const QString &path);
82 void removeInteraction(uint64_t interactionId);
83 void setSendMessageContent(const QString &content);
84 void contactIsComposing(const QString &uid, const QString &contactUri, bool isComposing);
85
86signals:
87 void needToUpdateSmartList();
88
89public slots:
90 void slotSendMessageContentSaved(const QString &content);
91 void slotUpdateDraft(const QString &content);
92 void slotMessagesCleared();
93 void slotMessagesLoaded();
Sébastien Blin1f915762020-08-03 13:27:42 -040094
95private:
96 void initQmlObject() override final;
97 void setConversationProfileData(const lrc::api::conversation::Info &convInfo);
98 void newInteraction(const QString &accountId,
99 const QString &convUid,
100 uint64_t interactionId,
101 const interaction::Info &interaction);
102
103 QString LastConvUid_;
104
105 /*
106 * Interaction connections.
107 */
108 QMetaObject::Connection newInteractionConnection_;
109 QMetaObject::Connection interactionStatusUpdatedConnection_;
110 QMetaObject::Connection interactionRemovedConnection_;
ababi0b686642020-08-18 17:21:28 +0200111};