Some changes to remove duplicates.

This commit is contained in:
Martin Rotter 2016-01-21 08:26:18 +01:00
parent 581a57b64d
commit b593d03c94
4 changed files with 30 additions and 10 deletions

View File

@ -2,11 +2,12 @@
—————
Fixed:
▪ Fixed some problems, that "Add category to selected account" was enabled when it shouldn't be.
▪ ♥ Auto-updating of feeds fixed (again?!). ♥
Changed:
▪ Tweaked "remove duplicates" policy.
▪ TT-RSS plugin can now restore messages from local recycle bin.
3.0.2

View File

@ -88,7 +88,7 @@
<item row="0" column="1">
<widget class="QStackedWidget" name="m_stackedSettings">
<property name="currentIndex">
<number>3</number>
<number>6</number>
</property>
<widget class="QWidget" name="m_pageGeneral">
<layout class="QFormLayout" name="formLayout_5">
@ -417,8 +417,8 @@ Authors of this application are NOT responsible for lost data.</string>
<rect>
<x>0</x>
<y>0</y>
<width>782</width>
<height>451</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
@ -463,7 +463,7 @@ Authors of this application are NOT responsible for lost data.</string>
<enum>QTabWidget::North</enum>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="m_tabIconSkin">
<attribute name="title">
@ -1492,7 +1492,7 @@ Authors of this application are NOT responsible for lost data.</string>
<string>When new message arrives from feed and duplicate exists, then its content is updated and new message is dropped.</string>
</property>
<property name="text">
<string>Remove duplicate messages</string>
<string>Remove duplicate messages (standard account only)</string>
</property>
</widget>
</item>

View File

@ -214,6 +214,7 @@ void FeedMessageViewer::updateFeedButtonsAvailability() {
form_main->m_ui->m_actionServiceDelete->setEnabled(service_selected);
form_main->m_ui->m_actionServiceEdit->setEnabled(service_selected);
form_main->m_ui->m_actionAddFeedIntoSelectedAccount->setEnabled(anything_selected);
form_main->m_ui->m_actionAddCategoryIntoSelectedAccount->setEnabled(anything_selected);
form_main->m_ui->m_menuAddItem->setEnabled(!critical_action_running);
form_main->m_ui->m_menuAccounts->setEnabled(!critical_action_running);

View File

@ -29,6 +29,7 @@
#include "gui/dialogs/formmain.h"
#include "gui/feedmessageviewer.h"
#include "gui/feedsview.h"
#include "services/abstract/recyclebin.h"
#include "services/standard/standardserviceroot.h"
#include "services/standard/gui/formstandardfeeddetails.h"
@ -616,6 +617,7 @@ bool StandardFeed::editItself(StandardFeed *new_feed_data) {
int StandardFeed::updateMessages(const QList<Message> &messages) {
int feed_id = id();
int updated_messages = 0;
bool anything_duplicated = false;
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
bool remove_duplicates = qApp->settings()->value(GROUP(Messages), SETTING(Messages::RemoveDuplicates)).toBool();
int account_id = serviceRoot()->accountId();
@ -629,7 +631,7 @@ int StandardFeed::updateMessages(const QList<Message> &messages) {
// WARNING: One feed CANNOT contain two (or more) messages with same AUTHOR AND TITLE AND URL AND DATE_CREATED.
query_select.setForwardOnly(true);
query_select.prepare("SELECT id, feed, date_created FROM Messages "
"WHERE feed = :feed AND title = :title AND url = :url AND author = :author AND account_id = :account_id;");
"WHERE feed = :feed AND url = :url AND author = :author AND account_id = :account_id;");
// Used to insert new messages.
query_insert.setForwardOnly(true);
@ -639,7 +641,9 @@ int StandardFeed::updateMessages(const QList<Message> &messages) {
if (remove_duplicates) {
query_update.setForwardOnly(true);
query_update.prepare(QSL("UPDATE Messages SET contents = :contents, enclosures = :enclosures WHERE id = :id;"));
query_update.prepare("UPDATE Messages SET is_read = 0, is_deleted = 0, is_pdeleted = 0, "
"contents = :contents, enclosures = :enclosures, date_created = :date_created "
"WHERE id = :id;");
}
if (!database.transaction()) {
@ -663,7 +667,6 @@ int StandardFeed::updateMessages(const QList<Message> &messages) {
}
query_select.bindValue(QSL(":feed"), feed_id);
query_select.bindValue(QSL(":title"), message.m_title);
query_select.bindValue(QSL(":url"), message.m_url);
query_select.bindValue(QSL(":author"), message.m_author);
query_select.bindValue(QSL(":account_id"), account_id);
@ -703,9 +706,15 @@ int StandardFeed::updateMessages(const QList<Message> &messages) {
// messages and there is exactly ONE existing duplicate.
query_update.bindValue(QSL(":id"), ids.at(0));
query_update.bindValue(QSL(":contents"), message.m_contents);
query_update.bindValue(QSL(":date_created"), message.m_created.toMSecsSinceEpoch());
query_update.bindValue(QSL(":enclosures"), Enclosures::encodeEnclosuresToString(message.m_enclosures));
query_update.exec();
query_update.finish();
QString sss = query_update.lastError().text();
anything_duplicated = true;
qDebug("Updating contents of duplicate message '%s'.", qPrintable(message.m_title));
}
else {
@ -738,8 +747,17 @@ int StandardFeed::updateMessages(const QList<Message> &messages) {
qDebug("Transaction commit for message downloader failed.");
}
else {
QList<RootItem*> items_to_update;
updateCounts(true);
serviceRoot()->itemChanged(QList<RootItem*>() << this);
items_to_update.append(this);
if (anything_duplicated) {
serviceRoot()->recycleBin()->updateCounts(true);
items_to_update.append(serviceRoot()->recycleBin());
}
serviceRoot()->itemChanged(items_to_update);
}
return updated_messages;