File indexing completed on 2024-05-12 05:04:13
0001 // SPDX-FileCopyrightText: 2022 Carl Schwan <carlschwan@kde.org> 0002 // SPDX-License-Identifier: LGPL-2.0-or-later 0003 0004 #pragma once 0005 0006 #include "abstractaccount.h" 0007 #include "abstracttimelinemodel.h" 0008 0009 class Identity; 0010 class Post; 0011 0012 struct Conversation { 0013 QList<std::shared_ptr<Identity>> accounts; 0014 Post *lastPost; 0015 bool unread; 0016 QString id; 0017 }; 0018 0019 /// Model used for direct messages (called Conversations in the application) 0020 /// \see AbstractTimelineModel 0021 class ConversationModel : public AbstractTimelineModel 0022 { 0023 Q_OBJECT 0024 QML_ELEMENT 0025 0026 public: 0027 /// Extra roles specifically for this model 0028 enum ExtraRole { 0029 UnreadRole = AbstractTimelineModel::ExtraRole + 1, ///< Number of unread messages 0030 ConversationAuthorsRole, ///< Human-readable list of accounts for this conversation 0031 ConversationIdRole, ///< Id for this conversation 0032 }; 0033 Q_ENUM(ExtraRole) 0034 0035 explicit ConversationModel(QObject *parent = nullptr); 0036 ~ConversationModel() override; 0037 0038 int rowCount(const QModelIndex &parent) const override; 0039 QVariant data(const QModelIndex &index, int role) const override; 0040 QHash<int, QByteArray> roleNames() const override; 0041 0042 /// Mark the conversation of \p id as read 0043 Q_INVOKABLE void markAsRead(const QString &id); 0044 0045 private: 0046 void fetchConversation(AbstractAccount *account); 0047 QList<Conversation> m_conversations; 0048 };