Generalize content_encoded into just content to support unencoded content as well

This commit is contained in:
A git user 2023-08-15 15:55:58 +02:00
parent 8a95b2edbc
commit 9f1d4a0e93
No known key found for this signature in database
GPG Key ID: 7920D03B7AA7CD7B
3 changed files with 7 additions and 7 deletions

View File

@ -296,7 +296,7 @@ class RSSBot(Plugin):
title=getattr(entry, "title", ""),
summary=getattr(entry, "description", "").strip(),
link=getattr(entry, "link", ""),
content_encoded=entry["content"][0]["value"].strip(),
content=entry["content"][0]["value"].strip(),
)
@staticmethod
@ -429,7 +429,7 @@ class RSSBot(Plugin):
title="Sample entry",
summary="This is a sample entry to demonstrate your new template",
link="http://example.com",
content_encoded="<b>Sample encoded content</b>"
content="<b>Sample formatted content</b>"
)
await evt.reply(f"Template for feed ID {feed.id} updated. Sample notification:")
await self._send(feed, sample_entry, sub)

View File

@ -101,7 +101,7 @@ class Entry:
title: str
summary: str
link: str
content_encoded: str
content: str
@classmethod
def from_row(cls, row: Record | None) -> Entry | None:
@ -149,7 +149,7 @@ class DBManager:
return [(Feed.from_row(row), row["user_id"]) for row in rows]
async def get_entries(self, feed_id: int) -> list[Entry]:
q = "SELECT feed_id, id, date, title, summary, link, content_encoded FROM entry WHERE feed_id = $1"
q = "SELECT feed_id, id, date, title, summary, link, content FROM entry WHERE feed_id = $1"
return [Entry.from_row(row) for row in await self.db.fetch(q, feed_id)]
async def add_entries(self, entries: list[Entry], override_feed_id: int | None = None) -> None:
@ -159,13 +159,13 @@ class DBManager:
for entry in entries:
entry.feed_id = override_feed_id
records = [attr.astuple(entry) for entry in entries]
columns = ("feed_id", "id", "date", "title", "summary", "link", "content_encoded")
columns = ("feed_id", "id", "date", "title", "summary", "link", "content")
async with self.db.acquire() as conn:
if self.db.scheme == Scheme.POSTGRES:
await conn.copy_records_to_table("entry", records=records, columns=columns)
else:
q = (
"INSERT INTO entry (feed_id, id, date, title, summary, link, content_encoded) "
"INSERT INTO entry (feed_id, id, date, title, summary, link, content) "
"VALUES ($1, $2, $3, $4, $5, $6, $7)"
)
await conn.executemany(q, records)

View File

@ -75,5 +75,5 @@ async def upgrade_v3(conn: Connection) -> None:
@upgrade_table.register(description="Add support for encoded content")
async def upgrade_v4(conn: Connection) -> None:
await conn.execute("ALTER TABLE entry ADD COLUMN content_encoded TEXT")
await conn.execute("ALTER TABLE entry ADD COLUMN content TEXT")
await conn.execute("ALTER TABLE subscription ADD COLUMN send_encoded BOOLEAN DEFAULT false")