diff --git a/src/core/feedsmodelstandardfeed.cpp b/src/core/feedsmodelstandardfeed.cpp index 78009d575..623297e7a 100755 --- a/src/core/feedsmodelstandardfeed.cpp +++ b/src/core/feedsmodelstandardfeed.cpp @@ -330,13 +330,15 @@ void FeedsModelStandardFeed::updateMessages(const QList &messages) { // Prepare queries. QSqlQuery query_select(database); QSqlQuery query_insert(database); - QSqlQuery query_update(database); // Used to check if give feed contains with message with given - // title and url. + // title, url and date_created. + // 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;"); + "WHERE feed = :feed AND title = :title AND url = :url AND author = :author;"); // Used to insert new messages. query_insert.setForwardOnly(true); @@ -344,16 +346,6 @@ void FeedsModelStandardFeed::updateMessages(const QList &messages) { "(feed, title, url, author, date_created, contents) " "VALUES (:feed, :title, :url, :author, :date_created, :contents);"); - // Used to update existing messages of given feed. - // NOTE: Messages are updated if its creation date - // is changed. - query_update.setForwardOnly(true); - query_update.prepare("UPDATE Messages " - "SET title = :title, url = :url, author = :author, " - "date_created = :date_created, contents = :contents, " - "is_read = 0, is_important = 0, is_deleted = 0 " - "WHERE id = :id"); - if (!database.transaction()) { database.rollback(); @@ -365,21 +357,36 @@ void FeedsModelStandardFeed::updateMessages(const QList &messages) { query_select.bindValue(":feed", feed_id); query_select.bindValue(":title", message.m_title); query_select.bindValue(":url", message.m_url); + query_select.bindValue(":author", message.m_author); query_select.exec(); - if (query_select.next()) { - // Message with this title & url probably exists in current feed. - message_id = query_select.value(0).toInt(); - message_creation_date = query_select.value(2).value(); - } - else { - message_id = -1; + QList datetime_stamps; + + while (query_select.next()) { + datetime_stamps << query_select.value(2).value(); } query_select.finish(); - if (message_id == -1) { - // Message is not fetched in this feed yet. Add it. + // TODO: potreba opravit nacitani URL + // pro http://forum.tea-earth.net/feed.php + // a taky vyresit problem v situaci + // kdy nastane situace ze message_id == -1 + // tedy zprava s danym nazvem, autorem, url a casem + // neexistuje, ale existuje ta sama starsi s + // datem ktery se neziskalo z kanalu ale vygenerovalo + // a ja tam ted vkladam tu samou zpravu s opet novym + // vygenerovanym datem, takze se ty zpravy duplikujou a + // duplikujou + + if (datetime_stamps.size() == 0 || + (message.m_createdFromFeed && + !datetime_stamps.contains(message.m_created.toMSecsSinceEpoch()))) { + // Message is not fetched in this feed yet + // or it is. If it is, then go + // through datetime stamps of stored messages + // and check if new (not auto-generated timestamp + // is among them and add this message if it is not. query_insert.bindValue(":feed", feed_id); query_insert.bindValue(":title", message.m_title); query_insert.bindValue(":url", message.m_url); @@ -390,27 +397,6 @@ void FeedsModelStandardFeed::updateMessages(const QList &messages) { query_insert.exec(); query_insert.finish(); } - else if (message.m_createdFromFeed && - message_creation_date != 0 && - message_creation_date > message.m_created.toMSecsSinceEpoch()) { - qDebug("Message '%s' (id %d) was updated in the feed, updating too.", - qPrintable(message.m_title), - message_id); - - // Message with given title/url is already persistently - // stored in given feed. - // Creation data of the message was obtained from - // feed itself. We can update this message. - query_update.bindValue(":title", message.m_title); - query_update.bindValue(":url", message.m_url); - query_update.bindValue(":author", message.m_author); - query_update.bindValue(":date_created", message.m_created.toMSecsSinceEpoch()); - query_update.bindValue(":contents", message.m_contents); - query_update.bindValue(":id", message_id); - - query_update.exec(); - query_update.finish(); - } } if (!database.commit()) { diff --git a/src/core/messagesmodel.h b/src/core/messagesmodel.h index ab2c16992..fca38d6c6 100644 --- a/src/core/messagesmodel.h +++ b/src/core/messagesmodel.h @@ -12,6 +12,10 @@ // Represents single message. class Message { public: + Message() { + m_title = m_url = m_author = m_contents = ""; + } + QString m_title; QString m_url; QString m_author; diff --git a/src/core/parsingfactory.cpp b/src/core/parsingfactory.cpp index e968a3832..dbd6a52ae 100644 --- a/src/core/parsingfactory.cpp +++ b/src/core/parsingfactory.cpp @@ -74,6 +74,18 @@ QList ParsingFactory::parseAsATOM10(const QString &data) { new_message.m_created = current_time; } + // TODO: NESMI se vracet isNull() hodnoty + // v url a author, to děla bordel při sql dotazech + // proto tento kod, trošku zlidštit ve + // všech třech metodach + if (new_message.m_author.isNull()) { + new_message.m_author = ""; + } + + if (new_message.m_url.isNull()) { + new_message.m_url = ""; + } + messages.append(new_message); } @@ -138,6 +150,14 @@ QList ParsingFactory::parseAsRDF(const QString &data) { new_message.m_created = current_time; } + if (new_message.m_author.isNull()) { + new_message.m_author = ""; + } + + if (new_message.m_url.isNull()) { + new_message.m_url = ""; + } + messages.append(new_message); } @@ -202,6 +222,14 @@ QList ParsingFactory::parseAsRSS20(const QString &data) { new_message.m_created = current_time; } + if (new_message.m_author.isNull()) { + new_message.m_author = ""; + } + + if (new_message.m_url.isNull()) { + new_message.m_url = ""; + } + messages.append(new_message); }