feat: add online presence tracking with last_seen column and configurable timeout

Add `last_seen` column to users table with index, implement `set_last_seen` and `get_online_users` database functions, expose presence config env vars (`PRESENCE_TIMEOUT_SECONDS`, `PRESENCE_ONLINE_LIMIT`, `PRESENCE_ONLINE_MARGIN_SECONDS`), include `last_seen` in follow list responses, and update profile docs to mention online indicator.
This commit is contained in:
2026-07-04 22:08:20 +00:00
parent 7002b23eeb
commit 0f872336b1
41 changed files with 935 additions and 94 deletions
+11
View File
@@ -906,3 +906,14 @@ def test_feed_pagination_emits_rel_next(page, app_server):
assert nxt.count() == 1
href = nxt.get_attribute("href")
assert "before=" in href and f"topic={topic}" in href, href
def test_feed_online_now_widget_lists_current_user(alice):
page, user = alice
page.goto(f"{BASE_URL}/feed", wait_until="domcontentloaded")
widget = page.locator(".online-users")
expect(widget).to_be_visible()
expect(
page.locator(f".online-user[title='{user['username']}']")
).to_have_count(1)
expect(page.locator(".online-users .presence-dot.online").first).to_be_visible()
+20
View File
@@ -1,5 +1,6 @@
# retoor <retoor@molodetz.nl>
import re
from tests.conftest import BASE_URL
FOLLOW = "form[action='/follow/bob_test'] button"
UNFOLLOW = "form[action='/follow/unfollow/bob_test'] button"
@@ -7,6 +8,25 @@ from playwright.sync_api import expect
from tests.e2e.post import create_post
def test_profile_shows_online_presence(alice):
page, user = alice
page.goto(
f"{BASE_URL}/profile/{user['username']}", wait_until="domcontentloaded"
)
presence = page.locator(".profile-presence")
expect(presence).to_be_visible()
expect(presence).to_have_class(re.compile(r"\bonline\b"))
expect(presence).to_have_text("online")
def test_nav_avatar_shows_online_presence_dot(alice):
page, _ = alice
page.goto(f"{BASE_URL}/feed", wait_until="domcontentloaded")
nav_dot = page.locator(".topnav-user .presence-dot")
expect(nav_dot).to_be_visible()
expect(nav_dot).to_have_class(re.compile(r"\bonline\b"))
def _post_comment(page, body):
textarea = page.locator(".comment-form textarea[name='content']")
textarea.fill(body)