-
Notifications
You must be signed in to change notification settings - Fork 23
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
Fix Chat Room Bugs When Changing Rooms and in Direct Messages #160
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -349,6 +349,18 @@ async def publish_unread_pointers(self, body): | |||||||||||||
|
||||||||||||||
@event("notification") | ||||||||||||||
async def publish_notification(self, body): | ||||||||||||||
event_id = body.get("data", {}).get("event", {}).get("event_id") | ||||||||||||||
if event_id: | ||||||||||||||
async with aredis() as redis: | ||||||||||||||
read_pointer = await redis.hget(f"chat:read:{self.consumer.user.id}", body["data"]["event"]["channel"]) | ||||||||||||||
read_pointer = int(read_pointer.decode()) if read_pointer else 0 | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): Handle potential decoding errors Consider adding error handling for the |
||||||||||||||
if read_pointer >= event_id: | ||||||||||||||
if await self.service.remove_notifications(self.consumer.user.id, self.channel_id, read_pointer): | ||||||||||||||
notification_counts = await database_sync_to_async( | ||||||||||||||
self.service.get_notification_counts | ||||||||||||||
)(self.consumer.user.id) | ||||||||||||||
Comment on lines
+359
to
+361
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Consider using a more descriptive variable name The variable
Suggested change
|
||||||||||||||
await self.consumer.send_json(["chat.notification_counts", notification_counts]) | ||||||||||||||
return | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: Unnecessary return statement The |
||||||||||||||
await self.consumer.send_json(["chat.notification", body.get("data")]) | ||||||||||||||
|
||||||||||||||
@command("send") | ||||||||||||||
|
@@ -638,7 +650,7 @@ async def publish_event(self, body): | |||||||||||||
user_profiles_required |= extract_mentioned_user_ids( | ||||||||||||||
data["content"].get("body", "") | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
user_profiles_required -= self.users_known_to_client | ||||||||||||||
data["users"] = {} | ||||||||||||||
|
||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider refactoring the code to reduce nesting and encapsulate specific logic into helper methods.
The new code introduces increased complexity due to additional nested conditionals, asynchronous context management, multiple return points, and potential error handling issues. To improve readability and maintainability, consider refactoring the code to reduce nesting and encapsulate specific logic into helper methods. Here's a suggested refactor:
This refactor reduces complexity by introducing helper methods, making the main method cleaner and easier to follow. It also adheres to the Single Responsibility Principle, making future maintenance simpler.