Experimental tt-rss starred msg changes, fixed crash. -

This commit is contained in:
martinrotter 2017-04-28 09:14:17 +02:00
parent d0b19b7361
commit 7f16ae5265
5 changed files with 48 additions and 27 deletions
resources/text
src

@ -10,6 +10,9 @@ Changed:
▪ Folder which holds SQL scripts got renamed to "sql".
▪ Tweaked some conditions for determining newly "updated" messages in ATOM format. (issue #103)
Fixed:
▪ Crash in TT-RSS plugin on application exit, when TT-RSS user needed to be logged out.
3.4.0
—————

@ -61,10 +61,6 @@ FeedsModel::FeedsModel(QObject *parent) : QAbstractItemModel(parent) {
FeedsModel::~FeedsModel() {
qDebug("Destroying FeedsModel instance.");
foreach (ServiceRoot *account, serviceRoots()) {
account->stop();
}
// Delete all model items.
delete m_rootItem;
}
@ -539,6 +535,12 @@ void FeedsModel::loadActivatedServiceAccounts() {
}
}
void FeedsModel::stopServiceAccounts() {
foreach (ServiceRoot *account, serviceRoots()) {
account->stop();
}
}
QList<Feed*> FeedsModel::feedsForIndex(const QModelIndex &index) const {
return itemForIndex(index)->getSubTreeFeeds();
}

@ -109,6 +109,8 @@ class FeedsModel : public QAbstractItemModel {
// Loads feed/categories from the database.
void loadActivatedServiceAccounts();
void stopServiceAccounts();
// Reloads counts of all feeds/categories/whatever in the model.
void reloadCountsOfWholeModel();

@ -311,6 +311,8 @@ void FeedReader::quit() {
if (qApp->settings()->value(GROUP(Messages), SETTING(Messages::ClearReadOnExit)).toBool()) {
m_feedsModel->markItemCleared(m_feedsModel->rootItem(), true);
}
m_feedsModel->stopServiceAccounts();
}
MessagesProxyModel *FeedReader::messagesProxyModel() const {

@ -157,19 +157,6 @@ RecycleBin *TtRssServiceRoot::recycleBin() const {
}
void TtRssServiceRoot::saveAllCachedData() {
/*TtRssUpdateArticleResponse response = m_network->updateArticles(customIDsOfMessages(messages),
UpdateArticle::Unread,
read == RootItem::Unread ?
UpdateArticle::SetToTrue :
UpdateArticle::SetToFalse);
if (m_network->lastError() == QNetworkReply::NoError && response.updateStatus() == STATUS_OK) {
return true;
}
else {
return false;
}*/
QPair<QMap<RootItem::ReadStatus, QStringList>, QMap<RootItem::Importance, QList<Message>>> msgCache = takeMessageCache();
QMapIterator<RootItem::ReadStatus, QStringList> i(msgCache.first);
@ -185,6 +172,22 @@ void TtRssServiceRoot::saveAllCachedData() {
key == RootItem::Unread ? UpdateArticle::SetToTrue : UpdateArticle::SetToFalse);
}
}
QMapIterator<RootItem::Importance, QList<Message>> j(msgCache.second);
// Save the actual data important/not important.
while (j.hasNext()) {
j.next();
auto key = j.key();
QList<Message> messages = j.value();
if (!messages.isEmpty()) {
QStringList ids = customIDsOfMessages(messages);
network()->updateArticles(ids,
UpdateArticle::Starred,
key == RootItem::Important ? UpdateArticle::SetToTrue : UpdateArticle::SetToFalse);
}
}
}
QList<QAction*> TtRssServiceRoot::serviceMenu() {
@ -208,19 +211,28 @@ bool TtRssServiceRoot::onBeforeSetMessagesRead(RootItem *selected_item, const QL
bool TtRssServiceRoot::onBeforeSwitchMessageImportance(RootItem *selected_item, const QList<ImportanceChange> &changes) {
Q_UNUSED(selected_item)
// NOTE: We just toggle it here, because we know, that there is only
// toggling of starred status supported by RSS Guard right now and
// Tiny Tiny RSS API allows it, which is great.
TtRssUpdateArticleResponse response = m_network->updateArticles(customIDsOfMessages(changes),
UpdateArticle::Starred,
UpdateArticle::Togggle);
// Now, we need to separate the changes because of ownCloud API limitations.
QList<Message> mark_starred_msgs;
QList<Message> mark_unstarred_msgs;
if (m_network->lastError() == QNetworkReply::NoError && response.updateStatus() == STATUS_OK) {
return true;
foreach (const ImportanceChange &pair, changes) {
if (pair.second == RootItem::Important) {
mark_starred_msgs.append(pair.first);
}
else {
mark_unstarred_msgs.append(pair.first);
}
}
else {
return false;
if (!mark_starred_msgs.isEmpty()) {
addMessageStatesToCache(mark_starred_msgs, RootItem::Important);
}
if (!mark_unstarred_msgs.isEmpty()) {
addMessageStatesToCache(mark_unstarred_msgs, RootItem::NotImportant);
}
return true;
}
TtRssNetworkFactory *TtRssServiceRoot::network() const {