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

Communication: Fix an issue for answers in unnamed group chats #10424

Merged

Conversation

FelberMartin
Copy link
Contributor

@FelberMartin FelberMartin commented Feb 28, 2025

Checklist

General

Server

Motivation and Context

There has been an internal server error for creating answer posts in a group chat without a name.

This PR closes #10423

Description

Similar to the creation of a new base post, we use the conversationService.loadConversationWithParticipantsIfGroupChat() function to get the participants for a group chat (the participants are needed to construct the conversation title for the notifications.

Steps for Testing

Prerequisites:

  • 1 Student
  1. Go to a group chat with no name (or create a new group chat)
  2. Create a base post
  3. Reply to that post in a thread
  4. Notice there is no "Internal Server error"

Testserver States

You can manage test servers using Helios. Check environment statuses in the environment list. To deploy to a test server, go to the CI/CD page, find your PR or branch, and trigger the deployment.

Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Summary by CodeRabbit

  • Refactor
    • Streamlined the messaging process to enhance group conversation handling.
    • Improved the retrieval of conversation details, ensuring participants are accurately loaded while reducing redundant dependencies.

Sorry, something went wrong.

Fix
@FelberMartin FelberMartin added server Pull requests that update Java code. (Added Automatically!) small bugfix communication Pull requests that affect the corresponding module labels Feb 28, 2025
@FelberMartin FelberMartin self-assigned this Feb 28, 2025
@FelberMartin FelberMartin requested a review from a team as a code owner February 28, 2025 09:13
Copy link

coderabbitai bot commented Feb 28, 2025

Walkthrough

The change removes the ConversationRepository dependency from the AnswerMessageService. The constructor has been updated by eliminating the ConversationRepository parameter and its associated initialization. Additionally, within the createAnswerMessage method, the conversation retrieval logic has been refactored to use conversationService.loadConversationWithParticipantsIfGroupChat instead of the previous direct repository call, and a conversationId variable has been introduced for clarity.

Changes

File Change Summary
src/main/java/de/tum/cit/aet/artemis/communication/service/AnswerMessageService.java Removed the ConversationRepository dependency and its initialization in the constructor; refactored createAnswerMessage to retrieve conversations via conversationService.loadConversationWithParticipantsIfGroupChat

Sequence Diagram(s)

sequenceDiagram
    participant AMS as AnswerMessageService
    participant CS as ConversationService
    AMS ->> CS: loadConversationWithParticipantsIfGroupChat(conversationId, ...)
    CS -->> AMS: Returns conversation with participants if group chat

Suggested labels

component:Communication

Suggested reviewers

  • JohannesStoehr
  • EneaGore
  • krusche
  • HawKhiem
✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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 or @coderabbitai title anywhere in the PR title to generate the title automatically.

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.

Sorry, something went wrong.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/main/java/de/tum/cit/aet/artemis/communication/service/AnswerMessageService.java (1)

92-94: Be cautious with orElse vs orElseGet in the conversation loading logic

The implementation uses orElse() which will always evaluate the loadConversationWithParticipantsIfGroupChat() method regardless of whether the first method returns a value. This could lead to unnecessary database operations.

Consider using orElseGet() instead:

-        var conversation = conversationService.isMemberOrCreateForCourseWideElseThrow(conversationId, author, Optional.empty())
-                .orElse(conversationService.loadConversationWithParticipantsIfGroupChat(conversationId));
+        var conversation = conversationService.isMemberOrCreateForCourseWideElseThrow(conversationId, author, Optional.empty())
+                .orElseGet(() -> conversationService.loadConversationWithParticipantsIfGroupChat(conversationId));
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6fc669b and c3ac9bc.

📒 Files selected for processing (1)
  • src/main/java/de/tum/cit/aet/artemis/communication/service/AnswerMessageService.java (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`src/main/java/**/*.java`: naming:CamelCase; principles:{sin...

src/main/java/**/*.java: naming:CamelCase; principles:{single_responsibility,small_methods,no_duplication}; db:{perf_queries,datetime_not_timestamp}; rest:{stateless,singleton,delegate_logic,http_only,minimal_dtos}; dtos:{java_records,no_entities,min_data,single_resp}; di:constructor_injection; kiss:simple_code; file_handling:os_indep_paths; practices:{least_access,avoid_transactions,code_reuse,static_member_ref,prefer_primitives}; sql:{param_annotation,uppercase,avoid_subqueries};java:avoid_star_imports

  • src/main/java/de/tum/cit/aet/artemis/communication/service/AnswerMessageService.java
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Call Build Workflow / Build and Push Docker Image
  • GitHub Check: Call Build Workflow / Build .war artifact
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: server-tests
  • GitHub Check: client-tests-selected
  • GitHub Check: server-style
  • GitHub Check: client-tests
  • GitHub Check: client-style
  • GitHub Check: Analyse
🔇 Additional comments (1)
src/main/java/de/tum/cit/aet/artemis/communication/service/AnswerMessageService.java (1)

64-64: Clear removal of unnecessary dependency

The removal of the ConversationRepository parameter from the constructor aligns with dependency injection best practices by eliminating unused dependencies. This change maintains the single responsibility principle while reducing the complexity of the service's initialization.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 28, 2025
@FelberMartin FelberMartin changed the title Bugfix/communication/error for answer in group chat Communication: Fix error for answer in group chat Feb 28, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/main/java/de/tum/cit/aet/artemis/communication/service/AnswerMessageService.java (3)

64-64: Consider reducing constructor dependencies for cleaner design.
Removing the ConversationRepository dependency is consistent with delegating conversation logic to ConversationService. However, the constructor parameter list remains quite large. Consider consolidating dependencies or employing a design pattern (e.g., a service aggregator) to reduce complexity.


93-93: Clarify the rationale behind group-chat participant loading.
This comment is helpful but could be slightly expanded to explain the dependency on participants for generating conversation titles, making future maintenance more intuitive.


94-95: Consider encapsulating fallback logic in a single method.
Chaining isMemberOrCreateForCourseWideElseThrow(...).orElse(loadConversationWithParticipantsIfGroupChat(...)) is functionally correct but slightly cumbersome. You might unify both calls in a dedicated service method for improved readability.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c3ac9bc and a98870a.

📒 Files selected for processing (1)
  • src/main/java/de/tum/cit/aet/artemis/communication/service/AnswerMessageService.java (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`src/main/java/**/*.java`: naming:CamelCase; principles:{sin...

src/main/java/**/*.java: naming:CamelCase; principles:{single_responsibility,small_methods,no_duplication}; db:{perf_queries,datetime_not_timestamp}; rest:{stateless,singleton,delegate_logic,http_only,minimal_dtos}; dtos:{java_records,no_entities,min_data,single_resp}; di:constructor_injection; kiss:simple_code; file_handling:os_indep_paths; practices:{least_access,avoid_transactions,code_reuse,static_member_ref,prefer_primitives}; sql:{param_annotation,uppercase,avoid_subqueries};java:avoid_star_imports

  • src/main/java/de/tum/cit/aet/artemis/communication/service/AnswerMessageService.java
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyse
  • GitHub Check: client-style
  • GitHub Check: server-tests
🔇 Additional comments (1)
src/main/java/de/tum/cit/aet/artemis/communication/service/AnswerMessageService.java (1)

92-92: Verify non-null conversation object.
answerMessage.getPost().getConversation() might be null if a conversation is not set on the post, causing potential runtime errors when invoking .getId().

Copy link
Collaborator

@MaximilianAnzinger MaximilianAnzinger left a comment

Choose a reason for hiding this comment

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

Thank you for considering my feedback 👍 Code LGTM

@helios-aet helios-aet bot temporarily deployed to artemis-test2.artemis.cit.tum.de February 28, 2025 21:35 Inactive
Copy link
Member

@anian03 anian03 left a comment

Choose a reason for hiding this comment

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

Tested on TS2, sending replies in unnamed groups works without an internal server error now 👍

Copy link
Contributor

@coolchock coolchock left a comment

Choose a reason for hiding this comment

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

code

@helios-aet helios-aet bot temporarily deployed to artemis-test1.artemis.cit.tum.de March 1, 2025 20:21 Inactive
Copy link

@SimonKaran13 SimonKaran13 left a comment

Choose a reason for hiding this comment

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

Tested on TS1, when writing an answer to a message in a group chat no error occurrs.

group-answer-pr.mov

@helios-aet helios-aet bot temporarily deployed to artemis-test3.artemis.cit.tum.de March 3, 2025 08:53 Inactive
Copy link
Contributor

@julian-wls julian-wls left a comment

Choose a reason for hiding this comment

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

Tested on TS3, works as expected!

@krusche krusche added this to the 7.10.5 milestone Mar 9, 2025
@krusche krusche changed the title Communication: Fix error for answer in group chat Communication: Fix an issue for answers in unnamed group chat Mar 9, 2025
@krusche krusche changed the title Communication: Fix an issue for answers in unnamed group chat Communication: Fix an issue for answers in unnamed group chats Mar 9, 2025
@krusche krusche merged commit d7e5652 into develop Mar 9, 2025
46 of 53 checks passed
@krusche krusche deleted the bugfix/communication/error-for-answer-in-group-chat branch March 9, 2025 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix communication Pull requests that affect the corresponding module ready to merge server Pull requests that update Java code. (Added Automatically!) small
Projects
Status: Merged
Status: Done
Development

Successfully merging this pull request may close these issues.

Internal server error when sending thread answer in unnamed group
7 participants