feat(backend): feed lists name, username and photo changes of people and chat renames, merged per day
This commit is contained in:
1 parent
9aa8690e33
commit
8e0f828dd4
4 files changed
+352
-12
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import json
|
||||
from dataclasses import dataclass
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from enum import StrEnum
|
||||
@@ -24,7 +25,8 @@ _EPOCH = datetime(1970, 1, 1, tzinfo=UTC)
|
||||
_MICROSECOND = timedelta(microseconds=1)
|
||||
|
||||
_ITEM_COLS = (
|
||||
"id, kind, chat_id, chat_kind, message_id, message_date, at, since, message_count"
|
||||
"id, kind, chat_id, chat_kind, message_id, message_date, at, since, "
|
||||
"message_count, detail"
|
||||
)
|
||||
|
||||
_VERSIONS = """
|
||||
@@ -59,8 +61,10 @@ SET seen_at = greatest(feed_seen.seen_at, EXCLUDED.seen_at)
|
||||
|
||||
class FeedKind(StrEnum):
|
||||
ALL = "all"
|
||||
MESSAGES = "messages"
|
||||
DELETED = "deleted"
|
||||
EDITED = "edited"
|
||||
PROFILE = "profile"
|
||||
|
||||
|
||||
class FeedChatKind(StrEnum):
|
||||
@@ -91,8 +95,11 @@ def _where(
|
||||
) -> tuple[str, list[object]]:
|
||||
params: list[object] = [account_id]
|
||||
clauses = ["account_id = $1"]
|
||||
if feed.kind is FeedKind.MESSAGES:
|
||||
clauses.append("kind <> 'profile'")
|
||||
exact = feed.kind not in {FeedKind.ALL, FeedKind.MESSAGES}
|
||||
conditions = (
|
||||
("kind = {}", None if feed.kind is FeedKind.ALL else feed.kind.value),
|
||||
("kind = {}", feed.kind.value if exact else None),
|
||||
("chat_id = {}", feed.chat_id),
|
||||
("chat_kind = {}", feed.chat_kind.value if feed.chat_kind else None),
|
||||
("at >= {}", feed.since),
|
||||
@@ -153,7 +160,11 @@ async def _build_items(
|
||||
messages = await chats.get_messages_at(
|
||||
pool,
|
||||
account_id,
|
||||
[(row["chat_id"], row["message_id"], row["message_date"]) for row in rows],
|
||||
[
|
||||
(row["chat_id"], row["message_id"], row["message_date"])
|
||||
for row in rows
|
||||
if row["kind"] != FeedKind.PROFILE
|
||||
],
|
||||
)
|
||||
versions = await _versions(pool, account_id, rows)
|
||||
chat_views = {
|
||||
@@ -192,6 +203,7 @@ async def _build_items(
|
||||
after=version["text"] if version else None,
|
||||
has_before=bool(version and version["has_before"]),
|
||||
edit_date=version["edit_date"] if version else None,
|
||||
detail=json.loads(row["detail"]) if row["detail"] else None,
|
||||
)
|
||||
)
|
||||
return items
|
||||
@@ -226,7 +238,9 @@ async def unseen(pool: asyncpg.Pool, account_id: int) -> FeedUnseen:
|
||||
"SELECT seen_at FROM feed_seen WHERE account_id = $1", account_id
|
||||
)
|
||||
counts = await pool.fetchrow(_UNSEEN, account_id, seen_at)
|
||||
latest = await list_feed(pool, account_id, FeedFilter(), limit=1)
|
||||
latest = await list_feed(
|
||||
pool, account_id, FeedFilter(kind=FeedKind.MESSAGES), limit=1
|
||||
)
|
||||
return FeedUnseen(
|
||||
count=counts["deleted"] + counts["edited"],
|
||||
deleted=counts["deleted"],
|
||||
|
||||
Reference in new issue
Block a user