New async msg changes now work when marking whole feed/recycle bin read/unread. ONLY owncloud so far.

This commit is contained in:
martinrotter 2017-04-21 13:41:51 +02:00
parent 09630f1e81
commit 013a2ff0e6
4 changed files with 28 additions and 37 deletions

View File

@ -89,15 +89,8 @@ bool OwnCloudFeed::removeItself() {
}
bool OwnCloudFeed::markAsReadUnread(RootItem::ReadStatus status) {
QStringList ids = getParentServiceRoot()->customIDSOfMessagesForItem(this);
QNetworkReply::NetworkError response = serviceRoot()->network()->markMessagesRead(status, ids);
if (response != QNetworkReply::NoError) {
return false;
}
else {
return getParentServiceRoot()->markFeedsReadUnread(QList<Feed*>() << this, status);
}
serviceRoot()->addMessageStatesToCache(getParentServiceRoot()->customIDSOfMessagesForItem(this), status);
return getParentServiceRoot()->markFeedsReadUnread(QList<Feed*>() << this, status);
}
bool OwnCloudFeed::cleanMessages(bool clear_only_read) {

View File

@ -34,13 +34,6 @@ OwnCloudServiceRoot *OwnCloudRecycleBin::serviceRoot() {
}
bool OwnCloudRecycleBin::markAsReadUnread(RootItem::ReadStatus status) {
QStringList ids = getParentServiceRoot()->customIDSOfMessagesForItem(this);
QNetworkReply::NetworkError response = serviceRoot()->network()->markMessagesRead(status, ids);
if (response != QNetworkReply::NoError) {
return false;
}
else {
return RecycleBin::markAsReadUnread(status);
}
serviceRoot()->addMessageStatesToCache(getParentServiceRoot()->customIDSOfMessagesForItem(this), status);
return RecycleBin::markAsReadUnread(status);
}

View File

@ -113,6 +113,27 @@ OwnCloudNetworkFactory *OwnCloudServiceRoot::network() const {
return m_network;
}
void OwnCloudServiceRoot::addMessageStatesToCache(const QStringList &ids_of_messages, RootItem::ReadStatus read) {
m_cacheSaveMutex->lock();
QStringList &list_act = m_cachedStatesRead[read];
QStringList &list_other = m_cachedStatesRead[read == RootItem::Read ? RootItem::Unread : RootItem::Read];
// Store changes, they will be sent to server later.
list_act.append(ids_of_messages);
QSet<QString> set_act = list_act.toSet();
QSet<QString> set_other = list_other.toSet();
// Now, we want to remove all IDS from list_other, which are contained in list.
set_other -= set_act;
list_act.clear(); list_act.append(set_act.toList());
list_other.clear(); list_other.append(set_other.toList());
m_cacheSaveMutex->unlock();
}
void OwnCloudServiceRoot::saveAllCachedData() {
if (m_cachedStatesRead.isEmpty() && m_cachedStatesImportant.isEmpty()) {
// No cached changes.
@ -148,25 +169,7 @@ bool OwnCloudServiceRoot::onBeforeSetMessagesRead(RootItem *selected_item, const
RootItem::ReadStatus read) {
Q_UNUSED(selected_item)
m_cacheSaveMutex->lock();
QStringList &list_act = m_cachedStatesRead[read];
QStringList &list_other = m_cachedStatesRead[read == RootItem::Read ? RootItem::Unread : RootItem::Read];
// Store changes, they will be sent to server later.
list_act.append(customIDsOfMessages(messages));
QSet<QString> set_act = list_act.toSet();
QSet<QString> set_other = list_other.toSet();
// Now, we want to remove all IDS from list_other, which are contained in list.
set_other -= set_act;
list_act.clear(); list_act.append(set_act.toList());
list_other.clear(); list_other.append(set_other.toList());
m_cacheSaveMutex->unlock();
addMessageStatesToCache(customIDsOfMessages(messages), read);
return true;
}

View File

@ -48,6 +48,8 @@ class OwnCloudServiceRoot : public ServiceRoot {
OwnCloudNetworkFactory *network() const;
void addMessageStatesToCache(const QStringList &ids_of_messages, ReadStatus read);
bool onBeforeSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, ReadStatus read);
bool onBeforeSwitchMessageImportance(RootItem *selected_item, const QList<ImportanceChange> &changes);