File indexing completed on 2023-12-03 08:31:20
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 "account/abstractaccount.h" 0007 #include "timeline/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 0025 public: 0026 /// Extra roles specifically for this model 0027 enum ExtraRole { 0028 UnreadRole = AbstractTimelineModel::ExtraRole + 1, ///< Number of unread messages 0029 ConversationAuthorsRole, ///< Human-readable list of accounts for this conversation 0030 ConversationIdRole, ///< Id for this conversation 0031 }; 0032 Q_ENUM(ExtraRole) 0033 0034 explicit ConversationModel(QObject *parent = nullptr); 0035 ~ConversationModel() override; 0036 0037 int rowCount(const QModelIndex &parent) const override; 0038 QVariant data(const QModelIndex &index, int role) const override; 0039 QHash<int, QByteArray> roleNames() const override; 0040 0041 /// Mark the conversation of \p id as read 0042 Q_INVOKABLE void markAsRead(const QString &id); 0043 0044 private: 0045 void fetchConversation(AbstractAccount *account); 0046 QList<Conversation> m_conversations; 0047 };