Debian Codegraph @

src/librssguard/core/messageobject.h

raw symbols SCIP
1 // For license of this file, see <project-root-folder>/LICENSE.md.
2
3 #ifndef MESSAGEOBJECT_H
4 #define MESSAGEOBJECT_H
5
6 #include "services/abstract/label.h"
7
8 #include <QObject>
9
10 class MessageObject : public QObject {
11 Q_OBJECT
12
13 Q_PROPERTY(QList<MessageCategory> categories READ categories)
14 Q_PROPERTY(QList<Label*> assignedLabels READ assignedLabels)
15 Q_PROPERTY(QList<Label*> availableLabels READ availableLabels)
16 Q_PROPERTY(QString feedCustomId READ feedCustomId)
17 Q_PROPERTY(int accountId READ accountId)
18 Q_PROPERTY(int id READ id)
19 Q_PROPERTY(bool hasEnclosures READ hasEnclosures)
20 Q_PROPERTY(QString customId READ customId WRITE setCustomId)
21 Q_PROPERTY(QString title READ title WRITE setTitle)
22 Q_PROPERTY(QString url READ url WRITE setUrl)
23 Q_PROPERTY(QString author READ author WRITE setAuthor)
24 Q_PROPERTY(QString contents READ contents WRITE setContents)
25 Q_PROPERTY(QString rawContents READ rawContents WRITE setRawContents)
26 Q_PROPERTY(QDateTime created READ created WRITE setCreated)
27 Q_PROPERTY(bool createdIsMadeup READ createdIsMadeup WRITE setCreatedIsMadeup)
28 Q_PROPERTY(double score READ score WRITE setScore)
29 Q_PROPERTY(bool isRead READ isRead WRITE setIsRead)
30 Q_PROPERTY(bool isImportant READ isImportant WRITE setIsImportant)
31 Q_PROPERTY(bool isDeleted READ isDeleted WRITE setIsDeleted)
32 Q_PROPERTY(bool runningFilterWhenFetching READ runningFilterWhenFetching)
33
34 public:
35 enum class FilteringAction {
36 // Message is normally accepted and stored in DB or updated.
37 Accept = 1,
38
39 // Message is ignored and will not be stored in DB but is not purged if it already exists.
40 Ignore = 2,
41
42 // Message is purged from DB if it already exists.
43 Purge = 4
44 };
45
46 Q_ENUM(FilteringAction)
47
48 enum class DuplicateCheck {
49 // Message with same title in DB.
50 SameTitle = 1,
51
52 // Message with same URL in DB.
53 SameUrl = 2,
54
55 // Message with same author in DB.
56 SameAuthor = 4,
57
58 // Messages with same creation date in DB.
59 SameDateCreated = 8,
60
61 // Compare with all messages from the account not only with messages from same feed.
62 // Note that this value must be used via bitwise OR with other values,
63 // for example 2 | 4 | 16.
64 AllFeedsSameAccount = 16,
65
66 // Messages with same custom ID as provided by feed/service.
67 SameCustomId = 32
68 };
69
70 Q_ENUM(DuplicateCheck)
71
72 explicit MessageObject(QSqlDatabase* db,
73 Feed* feed,
74 ServiceRoot* account,
75 bool is_new_message,
76 QObject* parent = nullptr);
77
78 void setMessage(Message* message);
79
80 // Check if message is duplicate with another messages in DB.
81 Q_INVOKABLE bool isAlreadyInDatabase(MessageObject::DuplicateCheck attribute_check) const;
82 Q_INVOKABLE bool isDuplicate(MessageObject::DuplicateCheck attribute_check) const;
83 Q_INVOKABLE bool isDuplicateWithAttribute(MessageObject::DuplicateCheck attribute_check) const;
84
85 // Adds given label to list of assigned labels to this message.
86 // Returns true if label was assigned now or if the message already has it assigned.
87 Q_INVOKABLE bool assignLabel(const QString& label_custom_id) const;
88
89 // Removes given label from list of assigned labels of this message.
90 // Returns true if label was now removed or if it is not assigned to the message at all.
91 Q_INVOKABLE bool deassignLabel(const QString& label_custom_id) const;
92
93 // Returns label custom ID given label title.
94 Q_INVOKABLE QString findLabelId(const QString& label_title) const;
95
96 // Returns label custom ID given label title or creates
97 // the label if it does not exist.
98 Q_INVOKABLE QString createLabelId(const QString& title, const QString& hex_color = {});
99
100 // Add multimedia attachment to the message.
101 Q_INVOKABLE void addEnclosure(const QString& url, const QString& mime_type) const;
102
103 // Returns list of assigned and available messages.
104 QList<Label*> assignedLabels() const;
105 QList<Label*> availableLabels() const;
106
107 QList<MessageCategory> categories() const;
108
109 bool runningFilterWhenFetching() const;
110 bool hasEnclosures() const;
111
112 // Generic Message's properties bindings.
113 QString feedCustomId() const;
114
115 int accountId() const;
116
117 QString customId() const;
118 void setCustomId(const QString& custom_id);
119
120 int id() const;
121
122 QString title() const;
123 void setTitle(const QString& title);
124
125 QString url() const;
126 void setUrl(const QString& url);
127
128 QString author() const;
129 void setAuthor(const QString& author);
130
131 QString contents() const;
132 void setContents(const QString& contents);
133
134 QString rawContents() const;
135 void setRawContents(const QString& raw_contents);
136
137 QDateTime created() const;
138 void setCreated(const QDateTime& created);
139
140 bool createdIsMadeup() const;
141 void setCreatedIsMadeup(bool madeup);
142
143 bool isRead() const;
144 void setIsRead(bool is_read);
145
146 bool isImportant() const;
147 void setIsImportant(bool is_important);
148
149 bool isDeleted() const;
150 void setIsDeleted(bool is_deleted);
151
152 double score() const;
153 void setScore(double score);
154
155 private:
156 QSqlDatabase* m_db;
157
158 Feed* m_feed;
159 ServiceRoot* m_account;
160
161 QString m_feedCustomId;
162 int m_accountId;
163 Message* m_message;
164 QList<Label*> m_availableLabels;
165 bool m_runningAfterFetching;
166 };
167
168 #endif // MESSAGEOBJECT_H