Skip to content

feature/improve chat system messages#438

Open
vitorguima wants to merge 8 commits into
masterfrom
feature/chat-system-messages-mobile-parity
Open

feature/improve chat system messages#438
vitorguima wants to merge 8 commits into
masterfrom
feature/chat-system-messages-mobile-parity

Conversation

@vitorguima

@vitorguima vitorguima commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • Added automatic system messages for group chat events (creation, title/image changes, participant added/removed/left, and admin promotions).
    • System message generation can be turned off via the BASEAPP_CHATS_ENABLE_SYSTEM_MESSAGES setting.
  • Tests
    • Expanded GraphQL mutation tests to verify system messages are emitted (or suppressed) appropriately for each group action.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f0fd1702-c789-4e2f-a602-cdbefbe6a1df

📥 Commits

Reviewing files that changed from the base of the PR and between a5b5015 and bd1fdc9.

📒 Files selected for processing (3)
  • baseapp_chats/README.md
  • baseapp_chats/graphql/mutations.py
  • baseapp_chats/utils.py
✅ Files skipped from review due to trivial changes (1)
  • baseapp_chats/README.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • baseapp_chats/utils.py
  • baseapp_chats/graphql/mutations.py

Walkthrough

Adds centralized system-message template constants and two helper functions (send_system_message, send_chatroom_update_system_messages, and escape_format_braces) to utils.py. Updates ChatRoomCreate, ChatRoomUpdate, and ChatRoomToggleAdmin mutations to use these helpers instead of inline send_message calls. Adds tests covering all system-message event types and a feature-flag disable path. Includes documentation of the BASEAPP_CHATS_ENABLE_SYSTEM_MESSAGES setting.

Changes

Centralized system-message emission for chat events

Layer / File(s) Summary
System message constants and helper functions
baseapp_chats/utils.py
Adds SYSTEM_MESSAGE_* template string constants for group lifecycle and participant events. Implements escape_format_braces to sanitize dynamic titles, send_system_message (feature-flag-guarded wrapper around send_message), and send_chatroom_update_system_messages (conditionally dispatches per-event messages based on title/image/participant change flags and leaving state).
Mutation updates to use centralized helpers
baseapp_chats/graphql/mutations.py
Updates imports to include new constants, send_system_message, send_chatroom_update_system_messages, and escape_format_braces. Replaces inline send_message calls in ChatRoomCreate (group created with escaped title), ChatRoomUpdate (captures pre-update state and calls send_chatroom_update_system_messages for title/image/participant changes and leaving), and ChatRoomToggleAdmin (made admin) with the centralized helpers.
GraphQL mutation tests for system messages
baseapp_chats/tests/test_graphql_mutations.py
Adds _system_message_contents helper to extract SYSTEM_GENERATED messages from GraphQL payloads and tests covering title update, participant add/remove, group leave (with actor-aware messaging), image change, admin toggle system messages, and a BASEAPP_CHATS_ENABLE_SYSTEM_MESSAGES=False feature-flag assertion.
Configuration documentation
baseapp_chats/README.md
Adds Settings section documenting the BASEAPP_CHATS_ENABLE_SYSTEM_MESSAGES environment variable and its effect on system-message generation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • silverlogic/baseapp-backend#224: Introduced SYSTEM_GENERATED message type plumbing and the initial group-creation system message that this PR refactors into the centralized helper.
  • silverlogic/baseapp-backend#380: Introduced ChatRoomToggleAdmin mutation; this PR replaces its admin notification with send_system_message and SYSTEM_MESSAGE_MADE_ADMIN.
  • silverlogic/baseapp-backend#215: Modified ChatRoomUpdate participant removal handling; this PR adds pre-update state capture and system messages for participant-change events.

Suggested reviewers

  • nossila
  • Hercilio1
  • Ronan-Fernandes
  • tsl-ps2

🐇 A rabbit hops through the chat one day,
Finds messages scattered in disarray.
"Let's gather these notes in one tidy spot!"
Templates and helpers — a neat little knot.
Now group chats announce every change with flair,
System messages dancing through the digital air! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feature/improve chat system messages' directly aligns with the main change—refactoring the chatroom mutation system to use centralized helpers for system-message emission.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/chat-system-messages-mobile-parity

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@vitorguima vitorguima changed the title Feature/chat system messages mobile parity feature/improve chat system messages Jun 15, 2026
@vitorguima vitorguima marked this pull request as ready for review June 15, 2026 20:44
@vitorguima vitorguima marked this pull request as draft June 15, 2026 20:44

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@baseapp_chats/utils.py`:
- Around line 100-103: Titles containing curly braces will cause formatting
errors when inserted into system message templates that are later rendered with
.format(...). In baseapp_chats/utils.py at line 102, escape the braces in
new_title by replacing any { with {{ and any } with }} before passing it to
SYSTEM_MESSAGE_GROUP_RENAMED.replace("{title}", ...). Apply the same escaping
logic in baseapp_chats/graphql/mutations.py at line 189 for the title parameter
passed to SYSTEM_MESSAGE_GROUP_CREATED.replace("{title}", ...).
- Around line 72-98: The functions send_system_message and
send_chatroom_update_system_messages in baseapp_chats/utils.py lack type
annotations for their parameters and return values, which violates the coding
guidelines. Add proper type annotations to all function parameters (room,
content, actor, target, extra_data for send_system_message and room, actor,
new_title, title_changed, image_changed, added_participants,
removed_participants, is_leaving for send_chatroom_update_system_messages) and
their respective return types. Review the codebase to identify the appropriate
types for each parameter based on how these functions are used and what they
return.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2fc251d7-9560-45e4-89fe-d160725ce399

📥 Commits

Reviewing files that changed from the base of the PR and between 0550d9f and a5b5015.

📒 Files selected for processing (3)
  • baseapp_chats/graphql/mutations.py
  • baseapp_chats/tests/test_graphql_mutations.py
  • baseapp_chats/utils.py

Comment thread baseapp_chats/utils.py Outdated
Comment thread baseapp_chats/utils.py Outdated
@vitorguima vitorguima marked this pull request as ready for review June 16, 2026 15:37
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