Fixed batch msg importance switching.
This commit is contained in:
parent
8517f2b027
commit
b67158eeef
@ -337,7 +337,9 @@ bool MessagesModel::switchBatchMessageImportance(const QModelIndexList &messages
|
||||
const Message msg = messageAt(message.row());
|
||||
RootItem::Importance message_importance = messageImportance((message.row()));
|
||||
|
||||
message_states.append(QPair<Message,RootItem::Importance>(msg, message_importance));
|
||||
message_states.append(QPair<Message,RootItem::Importance>(msg, message_importance == RootItem::Important ?
|
||||
RootItem::NotImportant :
|
||||
RootItem::Important));
|
||||
message_ids.append(QString::number(msg.m_id));
|
||||
}
|
||||
|
||||
|
@ -297,6 +297,104 @@ void ServiceRoot::requestItemRemoval(RootItem *item) {
|
||||
emit itemRemovalRequested(item);
|
||||
}
|
||||
|
||||
QStringList ServiceRoot::customIDSOfMessagesForItem(RootItem *item) {
|
||||
if (item->getParentServiceRoot() != this) {
|
||||
// Not item from this account.
|
||||
return QStringList();
|
||||
}
|
||||
else {
|
||||
QStringList list;
|
||||
|
||||
switch (item->kind()) {
|
||||
case RootItemKind::Category: {
|
||||
foreach (RootItem *child, item->childItems()) {
|
||||
list.append(customIDSOfMessagesForItem(child));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
case RootItemKind::ServiceRoot: {
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
QSqlQuery query(database);
|
||||
|
||||
query.prepare(QSL("SELECT custom_id FROM Messages WHERE is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;"));
|
||||
query.bindValue(QSL(":account_id"), accountId());
|
||||
query.exec();
|
||||
|
||||
while (query.next()) {
|
||||
list.append(query.value(0).toString());
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case RootItemKind::Bin: {
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
QSqlQuery query(database);
|
||||
|
||||
query.prepare(QSL("SELECT custom_id FROM Messages WHERE is_deleted = 1 AND is_pdeleted = 0 AND account_id = :account_id;"));
|
||||
query.bindValue(QSL(":account_id"), accountId());
|
||||
query.exec();
|
||||
|
||||
while (query.next()) {
|
||||
list.append(query.value(0).toString());
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case RootItemKind::Feed: {
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
QSqlQuery query(database);
|
||||
|
||||
query.prepare(QSL("SELECT custom_id FROM Messages WHERE is_deleted = 0 AND is_pdeleted = 0 AND feed = :feed AND account_id = :account_id;"));
|
||||
query.bindValue(QSL(":account_id"), accountId());
|
||||
query.bindValue(QSL(":feed"), item->customId());
|
||||
query.exec();
|
||||
|
||||
while (query.next()) {
|
||||
list.append(query.value(0).toString());
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
bool ServiceRoot::markFeedsReadUnread(QList<Feed*> items, RootItem::ReadStatus read) {
|
||||
QSqlDatabase db_handle = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
QSqlQuery query_read_msg(db_handle);
|
||||
query_read_msg.setForwardOnly(true);
|
||||
query_read_msg.prepare(QString("UPDATE Messages SET is_read = :read "
|
||||
"WHERE feed IN (%1) AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;").arg(textualFeedIds(items).join(QSL(", "))));
|
||||
|
||||
query_read_msg.bindValue(QSL(":read"), read == RootItem::Read ? 1 : 0);
|
||||
query_read_msg.bindValue(QSL(":account_id"), accountId());
|
||||
|
||||
if (query_read_msg.exec()) {
|
||||
QList<RootItem*> itemss;
|
||||
|
||||
foreach (Feed *feed, items) {
|
||||
feed->updateCounts(false);
|
||||
itemss.append(feed);
|
||||
}
|
||||
|
||||
itemChanged(itemss);
|
||||
requestReloadMessageList(read == RootItem::Read);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QStringList ServiceRoot::textualFeedIds(const QList<Feed*> &feeds) const {
|
||||
QStringList stringy_ids;
|
||||
stringy_ids.reserve(feeds.size());
|
||||
|
@ -150,6 +150,8 @@ class ServiceRoot : public RootItem {
|
||||
virtual bool onAfterMessagesRestoredFromBin(RootItem *selected_item, const QList<Message> &messages);
|
||||
|
||||
void completelyRemoveAllData();
|
||||
QStringList customIDSOfMessagesForItem(RootItem *item);
|
||||
bool markFeedsReadUnread(QList<Feed*> items, ReadStatus read);
|
||||
|
||||
// Obvious methods to wrap signals.
|
||||
void itemChanged(const QList<RootItem*> &items);
|
||||
@ -178,7 +180,6 @@ class ServiceRoot : public RootItem {
|
||||
void removeLeftOverMessages();
|
||||
|
||||
QStringList textualFeedIds(const QList<Feed*> &feeds) const;
|
||||
|
||||
QStringList customIDsOfMessages(const QList<ImportanceChange> &changes);
|
||||
QStringList customIDsOfMessages(const QList<Message> &messages);
|
||||
|
||||
|
@ -37,6 +37,22 @@ OwnCloudFeed::OwnCloudFeed(const QSqlRecord &record) : Feed(NULL) {
|
||||
OwnCloudFeed::~OwnCloudFeed() {
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
bool OwnCloudFeed::cleanMessages(bool clear_only_read) {
|
||||
return getParentServiceRoot()->cleanFeeds(QList<Feed*>() << this, clear_only_read);
|
||||
}
|
||||
|
||||
OwnCloudServiceRoot *OwnCloudFeed::serviceRoot() const {
|
||||
return qobject_cast<OwnCloudServiceRoot*>(getParentServiceRoot());
|
||||
}
|
||||
|
@ -31,6 +31,9 @@ class OwnCloudFeed : public Feed {
|
||||
explicit OwnCloudFeed(const QSqlRecord &record);
|
||||
virtual ~OwnCloudFeed();
|
||||
|
||||
bool markAsReadUnread(ReadStatus status);
|
||||
bool cleanMessages(bool clear_only_read);
|
||||
|
||||
OwnCloudServiceRoot *serviceRoot() const;
|
||||
int messageForeignKeyId() const;
|
||||
|
||||
|
@ -128,7 +128,7 @@ bool TtRssFeed::deleteViaGui() {
|
||||
}
|
||||
|
||||
bool TtRssFeed::markAsReadUnread(RootItem::ReadStatus status) {
|
||||
QStringList ids = serviceRoot()->customIDSOfMessagesForItem(this);
|
||||
QStringList ids = getParentServiceRoot()->customIDSOfMessagesForItem(this);
|
||||
TtRssUpdateArticleResponse response = serviceRoot()->network()->updateArticles(ids, UpdateArticle::Unread,
|
||||
status == RootItem::Unread ?
|
||||
UpdateArticle::SetToTrue :
|
||||
@ -138,12 +138,12 @@ bool TtRssFeed::markAsReadUnread(RootItem::ReadStatus status) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return serviceRoot()->markFeedsReadUnread(QList<Feed*>() << this, status);
|
||||
return getParentServiceRoot()->markFeedsReadUnread(QList<Feed*>() << this, status);
|
||||
}
|
||||
}
|
||||
|
||||
bool TtRssFeed::cleanMessages(bool clear_only_read) {
|
||||
return serviceRoot()->cleanFeeds(QList<Feed*>() << this, clear_only_read);
|
||||
return getParentServiceRoot()->cleanFeeds(QList<Feed*>() << this, clear_only_read);
|
||||
}
|
||||
|
||||
bool TtRssFeed::editItself(TtRssFeed *new_feed_data) {
|
||||
|
@ -205,7 +205,7 @@ bool TtRssServiceRoot::onBeforeSwitchMessageImportance(RootItem *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 greate.
|
||||
// Tiny Tiny RSS API allows it, which is great.
|
||||
TtRssUpdateArticleResponse response = m_network->updateArticles(customIDsOfMessages(changes),
|
||||
UpdateArticle::Starred,
|
||||
UpdateArticle::Togggle);
|
||||
@ -222,103 +222,6 @@ TtRssNetworkFactory *TtRssServiceRoot::network() const {
|
||||
return m_network;
|
||||
}
|
||||
|
||||
QStringList TtRssServiceRoot::customIDSOfMessagesForItem(RootItem *item) {
|
||||
if (item->getParentServiceRoot() != this) {
|
||||
// Not item from this account.
|
||||
return QStringList();
|
||||
}
|
||||
else {
|
||||
QStringList list;
|
||||
|
||||
switch (item->kind()) {
|
||||
case RootItemKind::Category: {
|
||||
foreach (RootItem *child, item->childItems()) {
|
||||
list.append(customIDSOfMessagesForItem(child));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
case RootItemKind::ServiceRoot: {
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
QSqlQuery query(database);
|
||||
|
||||
query.prepare(QSL("SELECT custom_id FROM Messages WHERE is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;"));
|
||||
query.bindValue(QSL(":account_id"), accountId());
|
||||
query.exec();
|
||||
|
||||
while (query.next()) {
|
||||
list.append(query.value(0).toString());
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case RootItemKind::Bin: {
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
QSqlQuery query(database);
|
||||
|
||||
query.prepare(QSL("SELECT custom_id FROM Messages WHERE is_deleted = 1 AND is_pdeleted = 0 AND account_id = :account_id;"));
|
||||
query.bindValue(QSL(":account_id"), accountId());
|
||||
query.exec();
|
||||
|
||||
while (query.next()) {
|
||||
list.append(query.value(0).toString());
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case RootItemKind::Feed: {
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
QSqlQuery query(database);
|
||||
|
||||
query.prepare(QSL("SELECT custom_id FROM Messages WHERE is_deleted = 0 AND is_pdeleted = 0 AND feed = :feed AND account_id = :account_id;"));
|
||||
query.bindValue(QSL(":account_id"), accountId());
|
||||
query.bindValue(QSL(":feed"), qobject_cast<TtRssFeed*>(item)->customId());
|
||||
query.exec();
|
||||
|
||||
while (query.next()) {
|
||||
list.append(query.value(0).toString());
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
bool TtRssServiceRoot::markFeedsReadUnread(QList<Feed*> items, RootItem::ReadStatus read) {
|
||||
QSqlDatabase db_handle = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
QSqlQuery query_read_msg(db_handle);
|
||||
query_read_msg.setForwardOnly(true);
|
||||
query_read_msg.prepare(QString("UPDATE Messages SET is_read = :read "
|
||||
"WHERE feed IN (%1) AND is_deleted = 0 AND is_pdeleted = 0;").arg(textualFeedIds(items).join(QSL(", "))));
|
||||
|
||||
query_read_msg.bindValue(QSL(":read"), read == RootItem::Read ? 1 : 0);
|
||||
|
||||
if (query_read_msg.exec()) {
|
||||
QList<RootItem*> itemss;
|
||||
|
||||
foreach (Feed *feed, items) {
|
||||
feed->updateCounts(false);
|
||||
itemss.append(feed);
|
||||
}
|
||||
|
||||
itemChanged(itemss);
|
||||
requestReloadMessageList(read == RootItem::Read);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void TtRssServiceRoot::saveAccountDataToDatabase() {
|
||||
if (accountId() != NO_PARENT_CATEGORY) {
|
||||
// We are overwritting previously saved data.
|
||||
|
@ -55,10 +55,6 @@ class TtRssServiceRoot : public ServiceRoot {
|
||||
// Access to network.
|
||||
TtRssNetworkFactory *network() const;
|
||||
|
||||
// Returns list of custom IDS of all DB messages in given item.
|
||||
QStringList customIDSOfMessagesForItem(RootItem *item);
|
||||
|
||||
bool markFeedsReadUnread(QList<Feed*> items, ReadStatus read);
|
||||
void saveAccountDataToDatabase();
|
||||
void updateTitle();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user