Debian Codegraph @

src/librssguard/core/message.h

raw symbols SCIP
1 // For license of this file, see <project-root-folder>/LICENSE.md.
2
3 #ifndef MESSAGE_H
4 #define MESSAGE_H
5
6 // #include "definitions/definitions.h"
7
8 #include "services/abstract/feedrtlbehavior.h"
9
10 #include <QDataStream>
11 #include <QDateTime>
12 #include <QSqlRecord>
13 #include <QStringList>
14
15 class QSqlDatabase;
16 class Label;
17
18 // Represents single enclosure.
19 struct RSSGUARD_DLLSPEC Enclosure {
20 public:
21 explicit Enclosure(QString url = QString(), QString mime = QString());
22
23 QString m_url;
24 QString m_mimeType;
25 };
26
27 // Represents single enclosure.
28 class RSSGUARD_DLLSPEC Enclosures {
29 public:
30 static QList<Enclosure> decodeEnclosuresFromString(const QString& enclosures_data);
31 static QJsonArray encodeEnclosuresToJson(const QList<Enclosure>& enclosures);
32 static QString encodeEnclosuresToString(const QList<Enclosure>& enclosures);
33 };
34
35 class Feed;
36
37 // Represents RSS, JSON or ATOM category (or tag, label - depending on terminology of each entry.
38 class RSSGUARD_DLLSPEC MessageCategory : public QObject {
39 Q_OBJECT
40
41 Q_PROPERTY(QString title READ title)
42
43 public:
44 explicit MessageCategory(const QString& title);
45 MessageCategory(const MessageCategory& other);
46
47 QString title() const;
48
49 MessageCategory& operator=(const MessageCategory& other);
50
51 private:
52 QString m_title;
53 };
54
55 // Represents single message.
56 class RSSGUARD_DLLSPEC Message {
57 public:
58 explicit Message();
59
60 void sanitize(const Feed* feed, bool fix_future_datetimes);
61
62 QJsonObject toJson() const;
63
64 // Creates Message from given record, which contains
65 // row from query SELECT * FROM Messages WHERE ....;
66 static Message fromSqlRecord(const QSqlRecord& record, bool* result = nullptr);
67 static QString generateRawAtomContents(const Message& msg);
68
69 public:
70 QString m_title;
71 QString m_url;
72 QString m_author;
73 QString m_contents;
74 QString m_rawContents;
75
76 // This should be preferably in UTC and should be converted
77 // to localtime when needed.
78 QDateTime m_created;
79 QString m_feedId;
80 QString m_feedTitle;
81 int m_accountId;
82 int m_id;
83 QString m_customId;
84 QString m_customHash;
85 bool m_isRead;
86 bool m_isImportant;
87 bool m_isDeleted;
88 double m_score;
89 RtlBehavior m_rtlBehavior;
90 QList<Enclosure> m_enclosures;
91
92 // List of assigned labels.
93 // This field is only field when fetching entries of a feed.
94 QList<MessageCategory> m_categories;
95
96 // List of custom IDs of labels assigned to this message.
97 QList<Label*> m_assignedLabels;
98
99 QList<Label*> m_assignedLabelsByFilter;
100 QList<Label*> m_deassignedLabelsByFilter;
101
102 QStringList m_assignedLabelsIds;
103
104 // Is true if "created" date was obtained directly
105 // from the feed, otherwise is false
106 bool m_createdFromFeed = false;
107
108 // Notice if the article was actually inserted/updated into DB when feed was fetched.
109 bool m_insertedUpdated = false;
110 };
111
112 inline bool operator==(const Message& lhs, const Message& rhs) {
113 return lhs.m_accountId == rhs.m_accountId &&
114 ((lhs.m_id > 0 && rhs.m_id > 0 && lhs.m_id == rhs.m_id) ||
115 (!lhs.m_customId.isEmpty() && !rhs.m_customId.isEmpty() && lhs.m_customId == rhs.m_customId));
116 }
117
118 inline bool operator!=(const Message& lhs, const Message& rhs) {
119 return !(lhs == rhs);
120 }
121
122 // Serialize message state.
123 // NOTE: This is used for persistent caching of message state changes.
124 RSSGUARD_DLLSPEC QDataStream& operator<<(QDataStream& out, const Message& my_obj);
125 RSSGUARD_DLLSPEC QDataStream& operator>>(QDataStream& in, Message& my_obj);
126
127 uint qHash(const Message& key, uint seed);
128 uint qHash(const Message& key);
129
130 #endif // MESSAGE_H