Marking TT-RSS read/unread works - only for whole acc now.
This commit is contained in:
parent
4e289fc1f0
commit
e23f517c05
9 changed files with 75 additions and 32 deletions
|
@ -560,7 +560,7 @@ set(APP_HEADERS
|
||||||
|
|
||||||
# TT-RSS service headers.
|
# TT-RSS service headers.
|
||||||
src/services/tt-rss/ttrssserviceroot.h
|
src/services/tt-rss/ttrssserviceroot.h
|
||||||
src/services/tt-rss/ttrssrecyclebin.h
|
src/services/tt-rss/ttrssrecyclebin.h;
|
||||||
src/services/tt-rss/ttrssfeed.h
|
src/services/tt-rss/ttrssfeed.h
|
||||||
src/services/tt-rss/ttrsscategory.h
|
src/services/tt-rss/ttrsscategory.h
|
||||||
src/services/tt-rss/gui/formeditaccount.h
|
src/services/tt-rss/gui/formeditaccount.h
|
||||||
|
|
|
@ -60,6 +60,38 @@ bool ServiceRoot::deleteViaGui() {
|
||||||
return data_removed;
|
return data_removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ServiceRoot::markAsReadUnread(RootItem::ReadStatus status) {
|
||||||
|
QSqlDatabase db_handle = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||||
|
|
||||||
|
if (!db_handle.transaction()) {
|
||||||
|
qWarning("Starting transaction for feeds read change.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSqlQuery query_read_msg(db_handle);
|
||||||
|
query_read_msg.setForwardOnly(true);
|
||||||
|
query_read_msg.prepare(QSL("UPDATE Messages SET is_read = :read WHERE is_pdeleted = 0 AND account_id = :account_id;"));
|
||||||
|
|
||||||
|
query_read_msg.bindValue(QSL(":account_id"), accountId());
|
||||||
|
query_read_msg.bindValue(QSL(":read"), status == RootItem::Read ? 1 : 0);
|
||||||
|
|
||||||
|
if (!query_read_msg.exec()) {
|
||||||
|
qDebug("Query execution for feeds read change failed.");
|
||||||
|
db_handle.rollback();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commit changes.
|
||||||
|
if (db_handle.commit()) {
|
||||||
|
updateCounts(false);
|
||||||
|
itemChanged(getSubTree());
|
||||||
|
requestReloadMessageList(status == RootItem::Read);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return db_handle.rollback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QList<Message> ServiceRoot::undeletedMessages() const {
|
QList<Message> ServiceRoot::undeletedMessages() const {
|
||||||
QList<Message> messages;
|
QList<Message> messages;
|
||||||
int account_id = accountId();
|
int account_id = accountId();
|
||||||
|
|
|
@ -50,6 +50,8 @@ class ServiceRoot : public RootItem {
|
||||||
|
|
||||||
bool deleteViaGui();
|
bool deleteViaGui();
|
||||||
|
|
||||||
|
bool markAsReadUnread(ReadStatus status);
|
||||||
|
|
||||||
// Returns list of specific actions for "Add new item" main window menu.
|
// Returns list of specific actions for "Add new item" main window menu.
|
||||||
// So typical list of returned actions could look like:
|
// So typical list of returned actions could look like:
|
||||||
// a) Add new feed
|
// a) Add new feed
|
||||||
|
|
|
@ -118,35 +118,7 @@ bool StandardServiceRoot::deleteViaGui() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StandardServiceRoot::markAsReadUnread(RootItem::ReadStatus status) {
|
bool StandardServiceRoot::markAsReadUnread(RootItem::ReadStatus status) {
|
||||||
QSqlDatabase db_handle = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
return ServiceRoot::markAsReadUnread(status);
|
||||||
|
|
||||||
if (!db_handle.transaction()) {
|
|
||||||
qWarning("Starting transaction for feeds read change.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
QSqlQuery query_read_msg(db_handle);
|
|
||||||
query_read_msg.setForwardOnly(true);
|
|
||||||
query_read_msg.prepare(QSL("UPDATE Messages SET is_read = :read WHERE is_pdeleted = 0 AND account_id = :account_id;"));
|
|
||||||
|
|
||||||
query_read_msg.bindValue(QSL(":account_id"), accountId());
|
|
||||||
query_read_msg.bindValue(QSL(":read"), status == RootItem::Read ? 1 : 0);
|
|
||||||
|
|
||||||
if (!query_read_msg.exec()) {
|
|
||||||
qDebug("Query execution for feeds read change failed.");
|
|
||||||
db_handle.rollback();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Commit changes.
|
|
||||||
if (db_handle.commit()) {
|
|
||||||
updateCounts(false);
|
|
||||||
itemChanged(getSubTree());
|
|
||||||
requestReloadMessageList(status == RootItem::Read);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return db_handle.rollback();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant StandardServiceRoot::data(int column, int role) const {
|
QVariant StandardServiceRoot::data(int column, int role) const {
|
||||||
|
|
|
@ -31,8 +31,6 @@ class TtRssCategory : public Category {
|
||||||
explicit TtRssCategory(const QSqlRecord &record);
|
explicit TtRssCategory(const QSqlRecord &record);
|
||||||
virtual ~TtRssCategory();
|
virtual ~TtRssCategory();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int customId() const;
|
int customId() const;
|
||||||
void setCustomId(int custom_id);
|
void setCustomId(int custom_id);
|
||||||
|
|
||||||
|
|
|
@ -144,6 +144,24 @@ QList<Message> TtRssFeed::undeletedMessages() const {
|
||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TtRssFeed::markAsReadUnread(RootItem::ReadStatus status) {
|
||||||
|
QNetworkReply::NetworkError error;
|
||||||
|
QStringList ids = serviceRoot()->customIDSOfMessagesForItem(this);
|
||||||
|
TtRssUpdateArticleResponse response = serviceRoot()->network()->updateArticles(ids, UpdateArticle::Unread,
|
||||||
|
status == RootItem::Unread ?
|
||||||
|
UpdateArticle::SetToTrue :
|
||||||
|
UpdateArticle::SetToFalse,
|
||||||
|
error);
|
||||||
|
|
||||||
|
if (error != QNetworkReply::NoError || response.updateStatus() != STATUS_OK) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// TODO: todo
|
||||||
|
//return Feed::markAsReadUnread(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int TtRssFeed::customId() const {
|
int TtRssFeed::customId() const {
|
||||||
return m_customId;
|
return m_customId;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,8 @@ class TtRssFeed : public Feed {
|
||||||
int update();
|
int update();
|
||||||
QList<Message> undeletedMessages() const;
|
QList<Message> undeletedMessages() const;
|
||||||
|
|
||||||
|
bool markAsReadUnread(ReadStatus status);
|
||||||
|
|
||||||
int customId() const;
|
int customId() const;
|
||||||
void setCustomId(int custom_id);
|
void setCustomId(int custom_id);
|
||||||
|
|
||||||
|
|
|
@ -86,6 +86,23 @@ bool TtRssServiceRoot::deleteViaGui() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TtRssServiceRoot::markAsReadUnread(RootItem::ReadStatus status) {
|
||||||
|
QNetworkReply::NetworkError error;
|
||||||
|
QStringList ids = customIDSOfMessagesForItem(this);
|
||||||
|
TtRssUpdateArticleResponse response = m_network->updateArticles(ids, UpdateArticle::Unread,
|
||||||
|
status == RootItem::Unread ?
|
||||||
|
UpdateArticle::SetToTrue :
|
||||||
|
UpdateArticle::SetToFalse,
|
||||||
|
error);
|
||||||
|
|
||||||
|
if (error != QNetworkReply::NoError || response.updateStatus() != STATUS_OK) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return ServiceRoot::markAsReadUnread(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool TtRssServiceRoot::canBeEdited() {
|
bool TtRssServiceRoot::canBeEdited() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,8 @@ class TtRssServiceRoot : public ServiceRoot {
|
||||||
bool editViaGui();
|
bool editViaGui();
|
||||||
bool deleteViaGui();
|
bool deleteViaGui();
|
||||||
|
|
||||||
|
bool markAsReadUnread(ReadStatus status);
|
||||||
|
|
||||||
QVariant data(int column, int role) const;
|
QVariant data(int column, int role) const;
|
||||||
|
|
||||||
QList<QAction*> addItemMenu();
|
QList<QAction*> addItemMenu();
|
||||||
|
|
Loading…
Add table
Reference in a new issue