add feed option to load article URL in message preview (#588)

* add feed option to load article URL in message preview

Some RSS feeds (such as reddit.com) provide quite limited `content`
section, thus it is desirable to load the URL into the message preview.

* Support displayUrl for all feed types
This commit is contained in:
igrekster 2022-01-18 17:40:22 +11:00 committed by GitHub
parent 9b3e41344f
commit 547754e83d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 51 additions and 6 deletions

View File

@ -44,6 +44,7 @@ CREATE TABLE Feeds (
custom_id TEXT NOT NULL CHECK (custom_id != ''), /* Custom ID cannot be empty, it must contain either service-specific ID, or Feeds/id. */
/* Custom column for (serialized) custom account-specific data. */
custom_data TEXT,
display_url BOOLEAN NOT NULL DEFAULT FALSE,
FOREIGN KEY (account_id) REFERENCES Accounts (id) ON DELETE CASCADE
);
@ -100,4 +101,4 @@ CREATE TABLE LabelsInMessages (
account_id INTEGER NOT NULL,
FOREIGN KEY (account_id) REFERENCES Accounts (id) ON DELETE CASCADE
);
);

View File

@ -1990,7 +1990,7 @@ void DatabaseQueries::createOverwriteFeed(const QSqlDatabase& db, Feed* feed, in
"SET title = :title, description = :description, date_created = :date_created, "
" icon = :icon, category = :category, source = :source, update_type = :update_type, "
" update_interval = :update_interval, account_id = :account_id, "
" custom_id = :custom_id, custom_data = :custom_data "
" custom_id = :custom_id, custom_data = :custom_data, display_url = :display_url "
"WHERE id = :id;");
q.bindValue(QSL(":title"), feed->title());
q.bindValue(QSL(":description"), feed->description());
@ -2003,6 +2003,7 @@ void DatabaseQueries::createOverwriteFeed(const QSqlDatabase& db, Feed* feed, in
q.bindValue(QSL(":account_id"), account_id);
q.bindValue(QSL(":custom_id"), feed->customId());
q.bindValue(QSL(":id"), feed->id());
q.bindValue(QSL(":display_url"), feed->displayUrl());
auto custom_data = feed->customDatabaseData();
QString serialized_custom_data = serializeCustomData(custom_data);

View File

@ -299,6 +299,7 @@ Assignment DatabaseQueries::getFeeds(const QSqlDatabase& db,
feed->setIcon(qApp->icons()->fromByteArray(query.value(FDS_DB_ICON_INDEX).toByteArray()));
feed->setAutoUpdateType(static_cast<Feed::AutoUpdateType>(query.value(FDS_DB_UPDATE_TYPE_INDEX).toInt()));
feed->setAutoUpdateInitialInterval(query.value(FDS_DB_UPDATE_INTERVAL_INDEX).toInt());
feed->setDisplayUrl(query.value(FDS_DB_DISPLAY_URL_INDEX).toBool());
qDebugNN << LOGSEC_CORE
<< "Custom ID of feed when loading from DB is"

View File

@ -249,6 +249,7 @@
#define FDS_DB_ACCOUNT_ID_INDEX 9
#define FDS_DB_CUSTOM_ID_INDEX 10
#define FDS_DB_CUSTOM_DATA_INDEX 11
#define FDS_DB_DISPLAY_URL_INDEX 12
// Indexes of columns for feed models.
#define FDS_MODEL_TITLE_INDEX 0

View File

@ -121,7 +121,15 @@ void MessagePreviewer::loadMessage(const Message& message, RootItem* root) {
if (!same_message) {
m_txtMessage->setVerticalScrollBarPosition(0.0);
m_txtMessage->loadMessage(message, m_root);
const auto * feed = root->getParentServiceRoot()->getItemFromSubTree(
[feedId = message.m_feedId](const RootItem * it) {
return it->kind() == RootItem::Kind::Feed && it->customId() == feedId;
})->toFeed();
if (feed && feed->displayUrl()) {
m_txtMessage->loadUrl(m_message.m_url);
} else {
m_txtMessage->loadMessage(message, m_root);
}
}
}
}

View File

@ -43,6 +43,7 @@ Feed::Feed(const Feed& other) : RootItem(other) {
setAutoUpdateInitialInterval(other.autoUpdateInitialInterval());
setAutoUpdateRemainingInterval(other.autoUpdateRemainingInterval());
setMessageFilters(other.messageFilters());
setDisplayUrl(other.displayUrl());
}
QList<Message> Feed::undeletedMessages() const {
@ -171,6 +172,14 @@ void Feed::setSource(const QString& source) {
m_source = source;
}
bool Feed::displayUrl() const {
return m_displayUrl;
}
void Feed::setDisplayUrl(bool flag) {
m_displayUrl = flag;
}
void Feed::appendMessageFilter(MessageFilter* filter) {
m_messageFilters.append(QPointer<MessageFilter>(filter));
}

View File

@ -73,6 +73,9 @@ class Feed : public RootItem {
QString source() const;
void setSource(const QString& source);
bool displayUrl() const;
void setDisplayUrl(bool flag);
void appendMessageFilter(MessageFilter* filter);
QList<QPointer<MessageFilter>> messageFilters() const;
void setMessageFilters(const QList<QPointer<MessageFilter>>& messageFilters);
@ -92,6 +95,7 @@ class Feed : public RootItem {
AutoUpdateType m_autoUpdateType;
int m_autoUpdateInitialInterval{};
int m_autoUpdateRemainingInterval{};
bool m_displayUrl{false};
int m_totalCount{};
int m_unreadCount{};
QList<QPointer<MessageFilter>> m_messageFilters;

View File

@ -47,6 +47,8 @@ void FormFeedDetails::apply() {
m_feed->setAutoUpdateType(static_cast<Feed::AutoUpdateType>(m_ui->m_cmbAutoUpdateType->itemData(
m_ui->m_cmbAutoUpdateType->currentIndex()).toInt()));
m_feed->setAutoUpdateInitialInterval(int(m_ui->m_spinAutoUpdateInterval->value()));
m_feed->setDisplayUrl(m_ui->m_cbLoadUrl->checkState() == Qt::CheckState::Checked);
if (!m_creatingNew) {
// We need to make sure that common data are saved.
@ -90,6 +92,7 @@ void FormFeedDetails::loadFeedData() {
m_ui->m_cmbAutoUpdateType->setCurrentIndex(m_ui->m_cmbAutoUpdateType->findData(QVariant::fromValue(int(m_feed->autoUpdateType()))));
m_ui->m_spinAutoUpdateInterval->setValue(m_feed->autoUpdateInitialInterval());
m_ui->m_cbLoadUrl->setCheckState(m_feed->displayUrl() ? Qt::CheckState::Checked : Qt::CheckState::Unchecked);
}
void FormFeedDetails::acceptIfPossible() {

View File

@ -21,7 +21,7 @@
</property>
<widget class="QWidget" name="tabUpdating">
<attribute name="title">
<string>Auto-downloading of articles</string>
<string>Articles</string>
</attribute>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
@ -52,6 +52,23 @@
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Display URL in preview</string>
</property>
<property name="buddy">
<cstring>m_cmbAutoUpdateType</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="m_cbLoadUrl">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
@ -87,8 +104,8 @@
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>325</x>
<y>342</y>
<x>331</x>
<y>556</y>
</hint>
<hint type="destinationlabel">
<x>286</x>