Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

baseapp-chats [BA-2236]: Change message subscription to not publish to sender #245

Merged
merged 2 commits into from
Mar 19, 2025

Conversation

tsl-ps2
Copy link
Contributor

@tsl-ps2 tsl-ps2 commented Feb 7, 2025

Acceptance Criteria
Context
Loom: https://www.loom.com/share/9bcd130aa70f476fa3cebbb53ba338e0

Business Rules

  • Given I input text into the message box, when I send the message, then the message box should become empty immediately

  • Given I have sent a message, the message should be displayed in the chat history quickly.

  • If a message fails to be send, just remove the message from the chat history.

    • Display a toast informing this to the user.
  • Disable the send button until we know the message sending request was resolved, either successful or failed,

Approvd
https://app.approvd.io/silverlogic/BA/stories/38918

Copy link

coderabbitai bot commented Feb 7, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@tsl-ps2 tsl-ps2 changed the title Ba 2236 optimistic update backend packages baseapp-chats [BA-2236]: Change new message subscription to not publish for sender Feb 7, 2025
@tsl-ps2 tsl-ps2 changed the title baseapp-chats [BA-2236]: Change new message subscription to not publish for sender baseapp-chats [BA-2236]: Change message subscription to not publish to sender Feb 7, 2025
@tsl-ps2
Copy link
Contributor Author

tsl-ps2 commented Feb 7, 2025

Some context: I changed the new message subscription so that the sender of the message is not getting an update through the new message subscription. Before, the sender of the message received the new message both as payload to the mutation they send and through the subscription. This was no problem since relay automatically took care of "merging" the two (in this case, just ignoring the one that arrived later).

Using optimistic updates when committing the send message mutation on the frontend, these updates are only rolled back when the mutation for this payload is received, but not when the new message subscription triggers. So if the subscription reached the client before the payload, then there was a UI spike of the message showing up twice (once through the optimistic update and once through the subscription, which could not be "merged" by relay as the optimistic update has no id set) until the payload arrived (which rolled back the optimistic update and could be merged with the subscription response). The PR fixes this behavior by not publishing the new message to its sender in the subscription.

@tsl-ps2 tsl-ps2 force-pushed the BA-2236-optimistic-update-backend-packages branch from 45db7c4 to 1fd82f8 Compare March 3, 2025 10:05
Copy link

sonarqubecloud bot commented Mar 3, 2025

Quality Gate Failed Quality Gate failed for 'silverlogic_baseapp-backend_baseapp-chats'

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

):
return []

if not database_sync_to_async(room.participants.filter(profile=profile).exists)():
Copy link
Member

Choose a reason for hiding this comment

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

please lets change this to be like before:

Suggested change
if not database_sync_to_async(room.participants.filter(profile=profile).exists)():
if not database_sync_to_async(user.has_perm)(
"baseapp_chats.view_chatroom", room
)

it not only checks if the person is a member but also if he is blocked or not

Copy link
Contributor Author

@tsl-ps2 tsl-ps2 Mar 17, 2025

Choose a reason for hiding this comment

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

@nossila: I am not sure whether we necessarily need to check this again since it is only for real-time updates about sent messages. When a message is sent, we check for permission (including blocks), so I think it'd be reasonable to assume that we can always synchronize messages sent on the server with the client without checking again. Also user.has_perm only checks whether some profile accessible to user is in the chatroom, but not the given profile. I'll switch to

if not database_sync_to_async(room.participants.filter(profile=profile).exists)() 
    or not database_sync_to_async(user.has_perm)("baseapp_chats.view_chatroom", room):
...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it would be good to rethink some of these permissions. E.g. all chat features are related to profiles, not users. So permissions like view_chatroom should use the profile, not just user. Also, I am currently not allowed to view a chat if there is any user blocked by me on a chat. For large chat groups, this might not make much sense; I might even lose access to all previous messages from a chat if such a user joins the group.

Copy link
Member

Choose a reason for hiding this comment

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

@tsl-ps2 you are completely right! We should rethink those permissions.

@tsl-ps2 tsl-ps2 force-pushed the BA-2236-optimistic-update-backend-packages branch from 8727981 to 3553905 Compare March 14, 2025 14:58
@nossila nossila merged commit 29538a8 into master Mar 19, 2025
49 of 52 checks passed
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.

4 participants