Only fetch entries we don't already fetched before.
authorJan Dumon <j.dumon@option.com>
Thu, 11 Mar 2010 21:16:07 +0000 (22:16 +0100)
committerJan Dumon <j.dumon@option.com>
Thu, 11 Mar 2010 21:16:07 +0000 (22:16 +0100)
src/googlereader.cpp
src/googlereader.h

index a10f783..9949977 100644 (file)
@@ -27,7 +27,6 @@ void Feed::updateSubscription(Feed *feed) {
 
 void Feed::fetch(bool cont) {
        QNetworkRequest request;
-       //QByteArray ba = "http://www.google.com/reader/atom/";
        QByteArray ba = "http://www.google.com/reader/api/0/stream/contents/";
        ba.append(QUrl::toPercentEncoding(id));
        QUrl url = QUrl::fromEncoded(ba);
@@ -35,6 +34,13 @@ void Feed::fetch(bool cont) {
        if(continuation != "" && cont)
                url.addEncodedQueryItem("c", continuation.toUtf8());
 
+       if(!cont && updated) {
+               /* Add 1 to the timestamp, otherwise we get the latest item
+                * again. Also the order has to be reversed for this to work. */
+               url.addEncodedQueryItem("ot", QByteArray::number(updated + 1));
+               url.addEncodedQueryItem("r", "o");
+       }
+
        request.setUrl(url);
        reply = reader->getManager()->get(request);
        connect(reply, SIGNAL(finished()), SLOT(fetchFinished()));
@@ -52,6 +58,7 @@ void Feed::fetchFinished() {
        QString continuation;
 
        continuation = result["continuation"].toString();
+       updated = result["updated"].toUInt();
 
        foreach(QVariant l, result["items"].toList()) {
                QVariantMap e = l.toMap();
@@ -262,6 +269,10 @@ void GoogleReader::parseUnread(QByteArray data) {
                if(f) {
                        f->unread = count;
                        f->newestitem = newestitem;
+
+                       /* Not a good idea if it doesn't happen sequentially. */
+                       /* Pre-fetch feeds with unread items */
+                       /* f->fetch(false); */
                }
        }
 
index a7d6e57..da927aa 100644 (file)
@@ -27,6 +27,7 @@ class Feed : public QObject {
                uint newestitem;
                
                QString continuation;
+               uint updated;
 
                QDateTime lastUpdated;
 
@@ -40,6 +41,7 @@ class Feed : public QObject {
                        unread = 0;
                        reader = gr;
                        special = 0;
+                       updated = 0;
                }
 
                void fetch(bool);