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 <QDataStream> 9 #include <QDateTime> 10 #include <QSqlRecord> 11 #include <QStringList> 12 13 class QSqlDatabase; 14 class Label; 15 16 // Represents single enclosure. 17 struct RSSGUARD_DLLSPEC Enclosure { 18 public: 19 explicit Enclosure(QString url = QString(), QString mime = QString()); 20 21 QString m_url; 22 QString m_mimeType; 23 }; 24 25 // Represents single enclosure. 26 class RSSGUARD_DLLSPEC Enclosures { 27 public: 28 static QList<Enclosure> decodeEnclosuresFromString(const QString& enclosures_data); 29 static QString encodeEnclosuresToString(const QList<Enclosure>& enclosures); 30 }; 31 32 class Feed; 33 34 // Represents single message. 35 class RSSGUARD_DLLSPEC Message { 36 public: 37 explicit Message(); 38 39 void sanitize(const Feed* feed); 40 41 // Creates Message from given record, which contains 42 // row from query SELECT * FROM Messages WHERE ....; 43 static Message fromSqlRecord(const QSqlRecord& record, bool* result = nullptr); 44 static QString generateRawAtomContents(const Message& msg); 45 46 public: 47 QString m_title; 48 QString m_url; 49 QString m_author; 50 QString m_contents; 51 QString m_rawContents; 52 53 // This should be preferably in UTC and should be converted 54 // to localtime when needed. 55 QDateTime m_created; 56 QString m_feedId; 57 int m_accountId; 58 int m_id; 59 QString m_customId; 60 QString m_customHash; 61 bool m_isRead; 62 bool m_isImportant; 63 bool m_isDeleted; 64 double m_score; 65 QList<Enclosure> m_enclosures; 66 67 // List of custom IDs of labels assigned to this message. 68 QList<Label*> m_assignedLabels; 69 70 // Is true if "created" date was obtained directly 71 // from the feed, otherwise is false 72 bool m_createdFromFeed = false; 73 }; 74 75 inline bool operator==(const Message& lhs, const Message& rhs) { 76 return lhs.m_accountId == rhs.m_accountId && 77 ((lhs.m_id > 0 && rhs.m_id > 0 && lhs.m_id == rhs.m_id) || 78 (!lhs.m_customId.isEmpty() && !rhs.m_customId.isEmpty() && lhs.m_customId == rhs.m_customId)); 79 } 80 81 inline bool operator!=(const Message& lhs, const Message& rhs) { 82 return !(lhs == rhs); 83 } 84 85 // Serialize message state. 86 // NOTE: This is used for persistent caching of message state changes. 87 RSSGUARD_DLLSPEC QDataStream& operator<<(QDataStream& out, const Message& my_obj); 88 RSSGUARD_DLLSPEC QDataStream& operator>>(QDataStream& in, Message& my_obj); 89 90 uint qHash(const Message& key, uint seed); 91 uint qHash(const Message& key); 92 93 #endif // MESSAGE_H 94