Only fetch entries we don't already fetched before.
[grr] / src / googlereader.cpp
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); */
                }
        }