File indexing completed on 2024-04-21 04:56:56
0001 /** 0002 * SPDX-FileCopyrightText: 2018 Aleix Pol Gonzalez <aleixpol@kde.org> 0003 * SPDX-FileCopyrightText: 2018 Simon Redman <simon@ergotech.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #ifndef CONVERSATIONMODEL_H 0009 #define CONVERSATIONMODEL_H 0010 0011 #include <QSet> 0012 #include <QStandardItemModel> 0013 0014 #include "interfaces/conversationmessage.h" 0015 #include "interfaces/dbusinterfaces.h" 0016 #include "thumbnailsprovider.h" 0017 0018 #define INVALID_THREAD_ID -1 0019 0020 class ConversationModel : public QStandardItemModel 0021 { 0022 Q_OBJECT 0023 Q_PROPERTY(qint64 threadId READ threadId WRITE setThreadId) 0024 Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged) 0025 Q_PROPERTY(QList<ConversationAddress> addressList READ addressList WRITE setAddressList) 0026 0027 public: 0028 ConversationModel(QObject *parent = nullptr); 0029 ~ConversationModel() override; 0030 0031 enum Roles { 0032 FromMeRole = Qt::UserRole, 0033 SenderRole, // The sender of the message. Undefined if this is an outgoing message 0034 DateRole, 0035 AvatarRole, // URI to the avatar of the sender of the message. Undefined if outgoing. 0036 AttachmentsRole, // The list of attachments. Undefined if there is no attachment in a message 0037 }; 0038 0039 Q_ENUM(Roles) 0040 0041 qint64 threadId() const; 0042 void setThreadId(const qint64 &threadId); 0043 0044 QString deviceId() const 0045 { 0046 return m_deviceId; 0047 } 0048 void setDeviceId(const QString & /*deviceId*/); 0049 0050 QList<ConversationAddress> addressList() const 0051 { 0052 return m_addressList; 0053 } 0054 void setAddressList(const QList<ConversationAddress> &addressList); 0055 0056 Q_INVOKABLE bool sendReplyToConversation(const QString &textMessage, QList<QUrl> attachmentUrls); 0057 Q_INVOKABLE bool startNewConversation(const QString &textMessage, const QList<ConversationAddress> &addressList, QList<QUrl> attachmentUrls); 0058 Q_INVOKABLE void requestMoreMessages(const quint32 &howMany = 10); 0059 0060 Q_INVOKABLE QString getCharCountInfo(const QString &message) const; 0061 0062 Q_INVOKABLE void requestAttachmentPath(const qint64 &partID, const QString &UniqueIdentifier); 0063 0064 Q_SIGNALS: 0065 void loadingFinished(); 0066 void filePathReceived(QString filePath, QString fileName); 0067 void deviceIdChanged(const QString &value); 0068 0069 private Q_SLOTS: 0070 void handleConversationUpdate(const QDBusVariant &message); 0071 void handleConversationLoaded(qint64 threadID); 0072 void handleConversationCreated(const QDBusVariant &message); 0073 0074 private: 0075 void createRowFromMessage(const ConversationMessage &message, int pos); 0076 0077 DeviceConversationsDbusInterface *m_conversationsInterface; 0078 ThumbnailsProvider *m_thumbnailsProvider; 0079 QString m_deviceId; 0080 qint64 m_threadId = INVALID_THREAD_ID; 0081 QList<ConversationAddress> m_addressList; 0082 QSet<qint32> knownMessageIDs; // Set of known Message uIDs 0083 }; 0084 0085 #endif // CONVERSATIONMODEL_H