diff --git a/saoriaccount.cpp b/saoriaccount.cpp index ba92539..4af74c2 100644 --- a/saoriaccount.cpp +++ b/saoriaccount.cpp @@ -118,7 +118,7 @@ connect(reply,&QNetworkReply::finished,[=](){ if (reply->error() == QNetworkReply::NoError) { QByteArray data = reply->readAll(); - emit apiData(timeline,data); + emit apiData(timeline,data,reply->rawHeader("Link")); } reply->deleteLater(); }); diff --git a/saoriaccount.h b/saoriaccount.h index 8ac86b0..b4398df 100644 --- a/saoriaccount.h +++ b/saoriaccount.h @@ -68,7 +68,7 @@ signals: void accessTokenChanged(QString); void accountInfomationChanged(); - void apiData(const QString timeline,const QByteArray data); + void apiData(const QString timeline,const QByteArray data,const QByteArray link); void posted(const QString timeline,int result); public slots: diff --git a/saoriview.cpp b/saoriview.cpp index d224bbf..ad1acd9 100644 --- a/saoriview.cpp +++ b/saoriview.cpp @@ -53,6 +53,7 @@ m_account = account; m_viewList.append(this); m_maxid = 0; + m_sinceid = 0; m_config = "/" + m_account + "/" + m_viewname; ui->actionPin->setChecked( @@ -89,7 +90,7 @@ if (ui->scrollArea->verticalScrollBar()->maximum() == p) { if (m_entries.count()) { QUrlQuery q; - q.addQueryItem("max_id",QString::number(m_entries.last()->id())); + q.addQueryItem("max_id",QString::number(m_maxid)); saoriaccount->getTimelineData(view,q); } } @@ -141,12 +142,8 @@ { auto saoriaccount = SaoriApplication::saori()->findAccount(m_account); if (saoriaccount == nullptr) return; - if (m_entries.count() == 0) m_maxid = 0; - else { - m_maxid = m_entries.first()->id(); - } QUrlQuery query; - query.addQueryItem("since_id",QString::number(m_maxid)); + query.addQueryItem("since_id",QString::number(m_sinceid)); saoriaccount->getTimelineData(m_viewname,query); } @@ -430,7 +427,26 @@ else QWidget::closeEvent(event); } -void SaoriView::recived(const QString timeline,const QByteArray data) +void SaoriView::getIdsFromHeader(const QByteArray header) +{ + QString l(header); + int n1 = l.indexOf("&max_id=") + 8; + int n2 = l.indexOf('>',n1); + qlonglong maxid = l.mid(n1,n2 - n1).toLongLong(); + n1 = l.indexOf("&since_id=") + 10; + n2 = l.indexOf('>',n1); + qlonglong sinceid = l.mid(n1,n2 - n1).toLongLong(); + if (maxid) { + if (m_maxid == 0) m_maxid = maxid; + m_maxid = m_maxid > maxid ? maxid : m_maxid; + } + if (sinceid) { + if (m_sinceid == 0) m_sinceid = sinceid; + m_sinceid = m_sinceid < sinceid ? sinceid : m_sinceid; + } +} + +void SaoriView::recived(const QString timeline, const QByteArray data, const QByteArray link) { if ((timeline.left(9) == "accounts:") && (m_viewname.left(9) == "accounts:")) { QStringList t = timeline.split(':'); @@ -443,6 +459,8 @@ } } if (timeline != m_viewname) return; + qlonglong s = m_sinceid; + getIdsFromHeader(link); QJsonArray json = QJsonDocument::fromJson(data).array(); for (auto j:json) { int i = 0; @@ -475,9 +493,7 @@ } // NOTE:ここまでを上ifに含めると取得済みエントリを再描画しなくなる。 } - if (m_entries.count()) { - if (m_entries.first()->id() > m_maxid) reload(); - } + if (s != m_sinceid) reload(); viewEntriesAdjustment(); } diff --git a/saoriview.h b/saoriview.h index dbd8f58..0c1bcde 100644 --- a/saoriview.h +++ b/saoriview.h @@ -53,6 +53,7 @@ QString m_config; QList m_entries; qlonglong m_maxid; + qlonglong m_sinceid; int m_timecount; static QList m_viewList; @@ -76,9 +77,10 @@ void savePinnedGeometry(); virtual void closeEvent(QCloseEvent *event); + void getIdsFromHeader(const QByteArray header); public slots: - void recived(const QString timeline,const QByteArray data); + void recived(const QString timeline,const QByteArray data,const QByteArray link); void linkClicked(const QUrl &url); protected slots: