This commit is contained in:
Martin Rotter 2021-03-03 14:50:31 +01:00
parent 081d25eca1
commit db156ce4a7
13 changed files with 63 additions and 29 deletions

View file

@ -61,6 +61,7 @@ CREATE TABLE Messages (
date_created INTEGER NOT NULL CHECK (date_created >= 0), date_created INTEGER NOT NULL CHECK (date_created >= 0),
contents TEXT, contents TEXT,
enclosures TEXT, enclosures TEXT,
score REAL NOT NULL DEFAULT 0.0 CHECK (score >= 0.0 AND score <= 100.0),
account_id INTEGER NOT NULL, account_id INTEGER NOT NULL,
custom_id TEXT, custom_id TEXT,
custom_hash TEXT, custom_hash TEXT,

View file

@ -66,6 +66,7 @@ Message::Message() {
m_title = m_url = m_author = m_contents = m_feedId = m_customId = m_customHash = ""; m_title = m_url = m_author = m_contents = m_feedId = m_customId = m_customHash = "";
m_enclosures = QList<Enclosure>(); m_enclosures = QList<Enclosure>();
m_accountId = m_id = 0; m_accountId = m_id = 0;
m_score = 0.0;
m_isRead = m_isImportant = m_isDeleted = false; m_isRead = m_isImportant = m_isDeleted = false;
m_assignedLabels = QList<Label*>(); m_assignedLabels = QList<Label*>();
} }
@ -106,6 +107,7 @@ Message Message::fromSqlRecord(const QSqlRecord& record, bool* result) {
message.m_created = TextFactory::parseDateTime(record.value(MSG_DB_DCREATED_INDEX).value<qint64>()); message.m_created = TextFactory::parseDateTime(record.value(MSG_DB_DCREATED_INDEX).value<qint64>());
message.m_contents = record.value(MSG_DB_CONTENTS_INDEX).toString(); message.m_contents = record.value(MSG_DB_CONTENTS_INDEX).toString();
message.m_enclosures = Enclosures::decodeEnclosuresFromString(record.value(MSG_DB_ENCLOSURES_INDEX).toString()); message.m_enclosures = Enclosures::decodeEnclosuresFromString(record.value(MSG_DB_ENCLOSURES_INDEX).toString());
message.m_score = record.value(MSG_DB_SCORE_INDEX).toDouble();
message.m_accountId = record.value(MSG_DB_ACCOUNT_ID_INDEX).toInt(); message.m_accountId = record.value(MSG_DB_ACCOUNT_ID_INDEX).toInt();
message.m_customId = record.value(MSG_DB_CUSTOM_ID_INDEX).toString(); message.m_customId = record.value(MSG_DB_CUSTOM_ID_INDEX).toString();
message.m_customHash = record.value(MSG_DB_CUSTOM_HASH_INDEX).toString(); message.m_customHash = record.value(MSG_DB_CUSTOM_HASH_INDEX).toString();
@ -125,31 +127,34 @@ QDataStream& operator<<(QDataStream& out, const Message& my_obj) {
<< my_obj.m_id << my_obj.m_id
<< my_obj.m_isImportant << my_obj.m_isImportant
<< my_obj.m_isRead << my_obj.m_isRead
<< my_obj.m_isDeleted; << my_obj.m_isDeleted
<< my_obj.m_score;
return out; return out;
} }
QDataStream& operator>>(QDataStream& in, Message& my_obj) { QDataStream& operator>>(QDataStream& in, Message& my_obj) {
int accountId; int account_id;
QString customHash; QString custom_hash;
QString customId; QString custom_id;
QString feedId; QString feed_id;
int id; int id;
bool isImportant; bool is_important;
bool isRead; bool is_read;
bool isDeleted; bool is_deleted;
double score;
in >> accountId >> customHash >> customId >> feedId >> id >> isImportant >> isRead >> isDeleted; in >> account_id >> custom_hash >> custom_id >> feed_id >> id >> is_important >> is_read >> is_deleted >> score;
my_obj.m_accountId = accountId; my_obj.m_accountId = account_id;
my_obj.m_customHash = customHash; my_obj.m_customHash = custom_hash;
my_obj.m_customId = customId; my_obj.m_customId = custom_id;
my_obj.m_feedId = feedId; my_obj.m_feedId = feed_id;
my_obj.m_id = id; my_obj.m_id = id;
my_obj.m_isImportant = isImportant; my_obj.m_isImportant = is_important;
my_obj.m_isRead = isRead; my_obj.m_isRead = is_read;
my_obj.m_isDeleted = isDeleted; my_obj.m_isDeleted = is_deleted;
my_obj.m_score = score;
return in; return in;
} }

View file

@ -54,6 +54,7 @@ class RSSGUARD_DLLSPEC Message {
bool m_isRead; bool m_isRead;
bool m_isImportant; bool m_isImportant;
bool m_isDeleted; bool m_isDeleted;
double m_score;
QList<Enclosure> m_enclosures; QList<Enclosure> m_enclosures;
// List of custom IDs of labels assigned to this message. // List of custom IDs of labels assigned to this message.

View file

@ -183,6 +183,14 @@ void MessageObject::setIsDeleted(bool is_deleted) {
m_message->m_isDeleted = is_deleted; m_message->m_isDeleted = is_deleted;
} }
double MessageObject::score() const {
return m_message->m_score;
}
void MessageObject::setScore(double score) {
m_message->m_score = score;
}
QString MessageObject::feedCustomId() const { QString MessageObject::feedCustomId() const {
if (m_feedCustomId.isEmpty() || m_feedCustomId == QString::number(NO_PARENT_CATEGORY)) { if (m_feedCustomId.isEmpty() || m_feedCustomId == QString::number(NO_PARENT_CATEGORY)) {
return m_message->m_feedId; return m_message->m_feedId;

View file

@ -19,6 +19,7 @@ class MessageObject : public QObject {
Q_PROPERTY(QString author READ author WRITE setAuthor) Q_PROPERTY(QString author READ author WRITE setAuthor)
Q_PROPERTY(QString contents READ contents WRITE setContents) Q_PROPERTY(QString contents READ contents WRITE setContents)
Q_PROPERTY(QDateTime created READ created WRITE setCreated) Q_PROPERTY(QDateTime created READ created WRITE setCreated)
Q_PROPERTY(double score READ score WRITE setScore)
Q_PROPERTY(bool isRead READ isRead WRITE setIsRead) Q_PROPERTY(bool isRead READ isRead WRITE setIsRead)
Q_PROPERTY(bool isImportant READ isImportant WRITE setIsImportant) Q_PROPERTY(bool isImportant READ isImportant WRITE setIsImportant)
Q_PROPERTY(bool isDeleted READ isDeleted WRITE setIsDeleted) Q_PROPERTY(bool isDeleted READ isDeleted WRITE setIsDeleted)
@ -112,6 +113,9 @@ class MessageObject : public QObject {
bool isDeleted() const; bool isDeleted() const;
void setIsDeleted(bool is_deleted); void setIsDeleted(bool is_deleted);
double score() const;
void setScore(double score);
private: private:
QSqlDatabase* m_db; QSqlDatabase* m_db;
QString m_feedCustomId; QString m_feedCustomId;

View file

@ -197,6 +197,8 @@ void MessagesModel::setupHeaderData() {
/*: Tooltip for attachments of message.*/ tr("Attachments") << /*: Tooltip for attachments of message.*/ tr("Attachments") <<
/*: Tooltip for score of message.*/ tr("Score") <<
/*: Tooltip for account ID of message.*/ tr("Account ID") << /*: Tooltip for account ID of message.*/ tr("Account ID") <<
/*: Tooltip for custom ID of message.*/ tr("Custom ID") << /*: Tooltip for custom ID of message.*/ tr("Custom ID") <<

View file

@ -23,6 +23,7 @@ MessagesModelSqlLayer::MessagesModelSqlLayer()
m_fieldNames[MSG_DB_DCREATED_INDEX] = "Messages.date_created"; m_fieldNames[MSG_DB_DCREATED_INDEX] = "Messages.date_created";
m_fieldNames[MSG_DB_CONTENTS_INDEX] = "Messages.contents"; m_fieldNames[MSG_DB_CONTENTS_INDEX] = "Messages.contents";
m_fieldNames[MSG_DB_ENCLOSURES_INDEX] = "Messages.enclosures"; m_fieldNames[MSG_DB_ENCLOSURES_INDEX] = "Messages.enclosures";
m_fieldNames[MSG_DB_SCORE_INDEX] = "Messages.score";
m_fieldNames[MSG_DB_ACCOUNT_ID_INDEX] = "Messages.account_id"; m_fieldNames[MSG_DB_ACCOUNT_ID_INDEX] = "Messages.account_id";
m_fieldNames[MSG_DB_CUSTOM_ID_INDEX] = "Messages.custom_id"; m_fieldNames[MSG_DB_CUSTOM_ID_INDEX] = "Messages.custom_id";
m_fieldNames[MSG_DB_CUSTOM_HASH_INDEX] = "Messages.custom_hash"; m_fieldNames[MSG_DB_CUSTOM_HASH_INDEX] = "Messages.custom_hash";
@ -42,6 +43,7 @@ MessagesModelSqlLayer::MessagesModelSqlLayer()
m_orderByNames[MSG_DB_DCREATED_INDEX] = "Messages.date_created"; m_orderByNames[MSG_DB_DCREATED_INDEX] = "Messages.date_created";
m_orderByNames[MSG_DB_CONTENTS_INDEX] = "Messages.contents"; m_orderByNames[MSG_DB_CONTENTS_INDEX] = "Messages.contents";
m_orderByNames[MSG_DB_ENCLOSURES_INDEX] = "Messages.enclosures"; m_orderByNames[MSG_DB_ENCLOSURES_INDEX] = "Messages.enclosures";
m_orderByNames[MSG_DB_SCORE_INDEX] = "Messages.score";
m_orderByNames[MSG_DB_ACCOUNT_ID_INDEX] = "Messages.account_id"; m_orderByNames[MSG_DB_ACCOUNT_ID_INDEX] = "Messages.account_id";
m_orderByNames[MSG_DB_CUSTOM_ID_INDEX] = "Messages.custom_id"; m_orderByNames[MSG_DB_CUSTOM_ID_INDEX] = "Messages.custom_id";
m_orderByNames[MSG_DB_CUSTOM_HASH_INDEX] = "Messages.custom_hash"; m_orderByNames[MSG_DB_CUSTOM_HASH_INDEX] = "Messages.custom_hash";
@ -49,7 +51,8 @@ MessagesModelSqlLayer::MessagesModelSqlLayer()
m_orderByNames[MSG_DB_HAS_ENCLOSURES] = "has_enclosures"; m_orderByNames[MSG_DB_HAS_ENCLOSURES] = "has_enclosures";
m_numericColumns << MSG_DB_ID_INDEX << MSG_DB_READ_INDEX << MSG_DB_DELETED_INDEX << MSG_DB_PDELETED_INDEX m_numericColumns << MSG_DB_ID_INDEX << MSG_DB_READ_INDEX << MSG_DB_DELETED_INDEX << MSG_DB_PDELETED_INDEX
<< MSG_DB_IMPORTANT_INDEX << MSG_DB_ACCOUNT_ID_INDEX << MSG_DB_DCREATED_INDEX; << MSG_DB_IMPORTANT_INDEX << MSG_DB_ACCOUNT_ID_INDEX << MSG_DB_DCREATED_INDEX
<< MSG_DB_SCORE_INDEX;
} }
void MessagesModelSqlLayer::addSortState(int column, Qt::SortOrder order) { void MessagesModelSqlLayer::addSortState(int column, Qt::SortOrder order) {

View file

@ -186,11 +186,12 @@
#define MSG_DB_DCREATED_INDEX 9 #define MSG_DB_DCREATED_INDEX 9
#define MSG_DB_CONTENTS_INDEX 10 #define MSG_DB_CONTENTS_INDEX 10
#define MSG_DB_ENCLOSURES_INDEX 11 #define MSG_DB_ENCLOSURES_INDEX 11
#define MSG_DB_ACCOUNT_ID_INDEX 12 #define MSG_DB_SCORE_INDEX 12
#define MSG_DB_CUSTOM_ID_INDEX 13 #define MSG_DB_ACCOUNT_ID_INDEX 13
#define MSG_DB_CUSTOM_HASH_INDEX 14 #define MSG_DB_CUSTOM_ID_INDEX 14
#define MSG_DB_FEED_TITLE_INDEX 15 #define MSG_DB_CUSTOM_HASH_INDEX 15
#define MSG_DB_HAS_ENCLOSURES 16 #define MSG_DB_FEED_TITLE_INDEX 16
#define MSG_DB_HAS_ENCLOSURES 17
// Indexes of columns as they are DEFINED IN THE TABLE for CATEGORIES. // Indexes of columns as they are DEFINED IN THE TABLE for CATEGORIES.
#define CAT_DB_ID_INDEX 0 #define CAT_DB_ID_INDEX 0

View file

@ -629,6 +629,7 @@ void MessagesView::adjustColumns() {
hideColumn(MSG_DB_CONTENTS_INDEX); hideColumn(MSG_DB_CONTENTS_INDEX);
hideColumn(MSG_DB_PDELETED_INDEX); hideColumn(MSG_DB_PDELETED_INDEX);
hideColumn(MSG_DB_ENCLOSURES_INDEX); hideColumn(MSG_DB_ENCLOSURES_INDEX);
hideColumn(MSG_DB_SCORE_INDEX);
hideColumn(MSG_DB_ACCOUNT_ID_INDEX); hideColumn(MSG_DB_ACCOUNT_ID_INDEX);
hideColumn(MSG_DB_CUSTOM_ID_INDEX); hideColumn(MSG_DB_CUSTOM_ID_INDEX);
hideColumn(MSG_DB_CUSTOM_HASH_INDEX); hideColumn(MSG_DB_CUSTOM_HASH_INDEX);

View file

@ -910,13 +910,13 @@ int DatabaseQueries::updateMessages(QSqlDatabase db,
// Used to insert new messages. // Used to insert new messages.
query_insert.setForwardOnly(true); query_insert.setForwardOnly(true);
query_insert.prepare("INSERT INTO Messages " query_insert.prepare("INSERT INTO Messages "
"(feed, title, is_read, is_important, is_deleted, url, author, date_created, contents, enclosures, custom_id, custom_hash, account_id) " "(feed, title, is_read, is_important, is_deleted, url, author, score, date_created, contents, enclosures, custom_id, custom_hash, account_id) "
"VALUES (:feed, :title, :is_read, :is_important, :is_deleted, :url, :author, :date_created, :contents, :enclosures, :custom_id, :custom_hash, :account_id);"); "VALUES (:feed, :title, :is_read, :is_important, :is_deleted, :url, :author, :score, :date_created, :contents, :enclosures, :custom_id, :custom_hash, :account_id);");
// Used to update existing messages. // Used to update existing messages.
query_update.setForwardOnly(true); query_update.setForwardOnly(true);
query_update.prepare("UPDATE Messages " query_update.prepare("UPDATE Messages "
"SET title = :title, is_read = :is_read, is_important = :is_important, is_deleted = :is_deleted, url = :url, author = :author, date_created = :date_created, contents = :contents, enclosures = :enclosures, feed = :feed " "SET title = :title, is_read = :is_read, is_important = :is_important, is_deleted = :is_deleted, url = :url, author = :author, score = :score, date_created = :date_created, contents = :contents, enclosures = :enclosures, feed = :feed "
"WHERE id = :id;"); "WHERE id = :id;");
if (use_transactions && !query_begin_transaction.exec(qApp->database()->obtainBeginTransactionSql())) { if (use_transactions && !query_begin_transaction.exec(qApp->database()->obtainBeginTransactionSql())) {
@ -1091,6 +1091,7 @@ int DatabaseQueries::updateMessages(QSqlDatabase db,
query_update.bindValue(QSL(":contents"), unnulifyString(message.m_contents)); query_update.bindValue(QSL(":contents"), unnulifyString(message.m_contents));
query_update.bindValue(QSL(":enclosures"), Enclosures::encodeEnclosuresToString(message.m_enclosures)); query_update.bindValue(QSL(":enclosures"), Enclosures::encodeEnclosuresToString(message.m_enclosures));
query_update.bindValue(QSL(":feed"), unnulifyString(feed_id_existing_message)); query_update.bindValue(QSL(":feed"), unnulifyString(feed_id_existing_message));
query_update.bindValue(QSL(":score"), message.m_score);
query_update.bindValue(QSL(":id"), id_existing_message); query_update.bindValue(QSL(":id"), id_existing_message);
*any_message_changed = true; *any_message_changed = true;
@ -1129,6 +1130,7 @@ int DatabaseQueries::updateMessages(QSqlDatabase db,
query_insert.bindValue(QSL(":enclosures"), Enclosures::encodeEnclosuresToString(message.m_enclosures)); query_insert.bindValue(QSL(":enclosures"), Enclosures::encodeEnclosuresToString(message.m_enclosures));
query_insert.bindValue(QSL(":custom_id"), unnulifyString(message.m_customId)); query_insert.bindValue(QSL(":custom_id"), unnulifyString(message.m_customId));
query_insert.bindValue(QSL(":custom_hash"), unnulifyString(message.m_customHash)); query_insert.bindValue(QSL(":custom_hash"), unnulifyString(message.m_customHash));
query_insert.bindValue(QSL(":score"), message.m_score);
query_insert.bindValue(QSL(":account_id"), account_id); query_insert.bindValue(QSL(":account_id"), account_id);
if (query_insert.exec() && query_insert.numRowsAffected() == 1) { if (query_insert.exec() && query_insert.numRowsAffected() == 1) {
@ -1673,6 +1675,10 @@ void DatabaseQueries::createOverwriteFeed(const QSqlDatabase& db, Feed* feed, in
} }
else { else {
feed->setId(q.lastInsertId().toInt()); feed->setId(q.lastInsertId().toInt());
if (feed->customId().isEmpty()) {
feed->setCustomId(QString::number(feed->id()));
}
} }
} }
@ -1691,7 +1697,7 @@ void DatabaseQueries::createOverwriteFeed(const QSqlDatabase& db, Feed* feed, in
q.bindValue(QSL(":update_type"), int(feed->autoUpdateType())); q.bindValue(QSL(":update_type"), int(feed->autoUpdateType()));
q.bindValue(QSL(":update_interval"), feed->autoUpdateInitialInterval()); q.bindValue(QSL(":update_interval"), feed->autoUpdateInitialInterval());
q.bindValue(QSL(":account_id"), account_id); q.bindValue(QSL(":account_id"), account_id);
q.bindValue(QSL(":custom_id"), feed->customId().isEmpty() ? QString::number(feed->id()) : feed->customId()); q.bindValue(QSL(":custom_id"), feed->customId());
q.bindValue(QSL(":id"), feed->id()); q.bindValue(QSL(":id"), feed->id());
auto custom_data = feed->customDatabaseData(); auto custom_data = feed->customDatabaseData();

View file

@ -22,6 +22,7 @@ RootItem::RootItem(const RootItem& other) : RootItem(nullptr) {
setId(other.id()); setId(other.id());
setCustomId(other.customId()); setCustomId(other.customId());
setIcon(other.icon()); setIcon(other.icon());
setKeepOnTop(other.keepOnTop());
// NOTE: We do not need to clone childs, because that would mean that // NOTE: We do not need to clone childs, because that would mean that
// either source or target item tree would get corrupted. // either source or target item tree would get corrupted.

View file

@ -83,8 +83,6 @@ QList<Message> GmailServiceRoot::obtainNewMessages(const QList<Feed*>& feeds, bo
if (error == Feed::Status::NetworkError || error == Feed::Status::AuthError || error == Feed::Status::ParsingError) { if (error == Feed::Status::NetworkError || error == Feed::Status::AuthError || error == Feed::Status::ParsingError) {
*error_during_obtaining = true; *error_during_obtaining = true;
} }
return messages;
} }
return messages; return messages;

View file

@ -352,6 +352,9 @@ bool StandardServiceRoot::mergeImportExportModel(FeedsImportExportModel* model,
target_root_node->getParentServiceRoot()->accountId(), target_root_node->getParentServiceRoot()->accountId(),
target_parent->id()); target_parent->id());
requestItemReassignment(new_category, target_parent); requestItemReassignment(new_category, target_parent);
original_parents.push(new_category);
new_parents.push(source_category);
} }
catch (ApplicationException& ex) { catch (ApplicationException& ex) {
// Add category failed, but this can mean that the same category (with same title) // Add category failed, but this can mean that the same category (with same title)