Skip to content

Add meme share button variants#301

Merged
ohld merged 3 commits into
productionfrom
codex/meme-share-buttons-pr
May 25, 2026
Merged

Add meme share button variants#301
ohld merged 3 commits into
productionfrom
codex/meme-share-buttons-pr

Conversation

@ohld
Copy link
Copy Markdown
Member

@ohld ohld commented May 25, 2026

Summary

  • Adds a localized share button above private-feed like/skip buttons.
  • Supports two Telegram-native share adapters: t.me/share/url deep-link sharing and switch_inline_query_chosen_chat with #meme_id exact inline results.
  • Makes /start s_{sharer_user_id}_{meme_id} send the clicked meme first, add the meme language to the user, and defer new-user onboarding until after the first reaction.
  • Keeps share parsing and button construction behind src/tgbot/sharing.py so Share Attribution logic has one interface.

Telegram API notes

Verification

  • ruff check src/tgbot/sharing.py src/tgbot/senders/keyboards.py src/tgbot/senders/meme.py src/tgbot/senders/next_message.py src/tgbot/handlers/start.py src/tgbot/handlers/reaction.py src/tgbot/handlers/inline.py src/tgbot/handlers/deep_link.py src/tgbot/service.py src/storage/schemas.py tests/tgbot/test_sharing.py tests/tgbot/test_inline_search.py tests/tgbot/test_meme_like_count_experiment.py tests/tgbot/test_reaction_handler.py tests/tgbot/test_start.py
  • pytest -q tests/tgbot/test_sharing.py tests/tgbot/test_inline_search.py tests/tgbot/test_meme_like_count_experiment.py

Not run

  • DB-backed tests tests/tgbot/test_reaction_handler.py and tests/tgbot/test_start.py need the docker-compose Postgres hostname app_db; local host run failed with socket.gaierror for app_db.

@ohld
Copy link
Copy Markdown
Member Author

ohld commented May 25, 2026

STAFF ENGINEER REVIEW: CHANGES REQUESTED — inline search share attribution is unsafe with global Telegram caching, and CI lint is red.

Findings:

  • src/tgbot/handlers/inline.py:160 returns inline search results whose captions now include s_{user_id}_{meme_id} share links, but the non-exact search answer is still globally cacheable for 12 hours. Telegram can reuse the first user's cached result for another user with the same query, misattributing share rewards. Set is_personal=True for these personalized answers or remove user-specific attribution from globally cached inline results.
  • CI lint is red: ruff check src/ tests/ reports unsorted imports in src/tgbot/senders/utils.py:1.

I disabled auto-merge before posting this. No secrets or raw SQL interpolation were found in the new SQL helper, but the cache attribution bug is a reward/accounting integrity issue and blocks approval.

@ohld
Copy link
Copy Markdown
Member Author

ohld commented May 25, 2026

STAFF ENGINEER REVIEW: CHANGES REQUESTED — Existing users can be stranded by shared memes they have already reacted to.

src/tgbot/handlers/start.py:112 fetches and sends the shared meme without checking whether this user already has a user_meme_reaction row for it. send_meme_to_user then calls create_user_meme_reaction, but that insert is ON CONFLICT DO NOTHING on (user_id, meme_id). If the user has already liked/skipped that meme, the button callback later hits update_user_meme_reaction, which only updates rows with reaction_id IS NULL; it returns false and handle_reaction does not call next_message. The user taps like/skip and stays stuck on the shared meme.

Please filter already-reacted shared memes for existing users before sending them, or make the duplicate-reaction path advance to the next meme intentionally. Add a regression test for existing user + share link + already reacted meme.

@ohld
Copy link
Copy Markdown
Member Author

ohld commented May 25, 2026

STAFF ENGINEER REVIEW: APPROVED — current head b828519 is clean. Structural review, CSO diff pass, and Codex review found no blocking issues. Prior blockers are addressed: inline share results are personal-cache safe, already-reacted shared memes are skipped with regression coverage, CI is green. Local verification: ruff check on changed Python files; pytest -q tests/tgbot/test_sharing.py tests/tgbot/test_inline_search.py tests/tgbot/test_meme_like_count_experiment.py.

@ohld ohld merged commit ddc23cb into production May 25, 2026
3 checks passed
@ohld
Copy link
Copy Markdown
Member Author

ohld commented May 25, 2026

✅ Approved + merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant