-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathconversationmodel.h
54 lines (44 loc) · 1.47 KB
/
conversationmodel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-FileCopyrightText: 2022 Carl Schwan <[email protected]>
// SPDX-License-Identifier: LGPL-2.0-or-later
#pragma once
#include "account/abstractaccount.h"
#include "timeline/abstracttimelinemodel.h"
class Identity;
class Post;
struct Conversation {
QList<std::shared_ptr<Identity>> accounts;
Post *lastPost;
bool unread;
QString id;
};
/**
* @brief Model used for direct messages (called Conversations in the application)
* @see AbstractTimelineModel
*/
class ConversationModel : public AbstractTimelineModel
{
Q_OBJECT
QML_ELEMENT
public:
/**
* @brief Extra roles specifically for this model.
*/
enum ExtraRole {
UnreadRole = AbstractTimelineModel::ExtraRole + 1, /** Number of unread messages. */
ConversationAuthorsRole, /** Human-readable list of accounts for this conversation. */
ConversationIdRole, /** Id for this conversation. */
};
Q_ENUM(ExtraRole)
explicit ConversationModel(QObject *parent = nullptr);
~ConversationModel() override;
[[nodiscard]] int rowCount(const QModelIndex &parent) const override;
[[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
/**
* @brief Mark the conversation of @p id as read.
*/
Q_INVOKABLE void markAsRead(const QString &id);
private:
void fetchConversation(AbstractAccount *account);
QList<Conversation> m_conversations;
};