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 message search not showing results from some conversations #10345

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

asliayk
Copy link
Contributor

@asliayk asliayk commented Feb 16, 2025

Checklist

General

Server

  • I strictly followed the principle of data economy for all database calls.
  • I strictly followed the server coding and design guidelines.
  • I added multiple integration tests (Spring) related to the features (with a high test coverage).

Motivation and Context

The message search, which is supposed to work for messages from all conversations, currently only works for channels marked as isCourseWide in the database. It does not return results for non-course-wide channels, direct chats, or group chats.
(Closes #10290)

Description

This PR fixes the issue by ensuring that message search retrieves results from all relevant conversations, including direct and group chats, as well as non-course-wide channels.

Steps for Testing

Prerequisites:

  • 1 User
  • 1 Course with Communication enabled
  1. Log in to Artemis.
  2. Navigate to the Communication section of a course.
  3. Send a direct message, a group message, or a message to a non-course-wide channel (a channel that does not include all course members).
  4. Use the search bar at the top to search for that message and verify that the relevant messages appear in the results.

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

Test Coverage

Screenshots

search message results for a direct chat and a non-course-wide channel
image

Summary by CodeRabbit

  • Refactor
    • Streamlined message filtering for more consistent search results.
  • Bug Fixes
    • Refined channel reference display so that only valid, non-empty names are shown.
  • Tests
    • Added tests to ensure message search now correctly retrieves direct and group chat messages.

@asliayk asliayk self-assigned this Feb 16, 2025
@github-actions github-actions bot added tests server Pull requests that update Java code. (Added Automatically!) client Pull requests that update TypeScript code. (Added Automatically!) communication Pull requests that affect the corresponding module labels Feb 16, 2025
@helios-aet helios-aet bot temporarily deployed to artemis-test3.artemis.cit.tum.de February 16, 2025 21:54 Inactive
@asliayk asliayk marked this pull request as ready for review February 16, 2025 22:09
@asliayk asliayk requested a review from a team as a code owner February 16, 2025 22:09
Copy link

coderabbitai bot commented Feb 16, 2025

Walkthrough

The pull request refines the filtering logic for course-wide messages and adjusts UI rendering along with adding a new integration test. In the ConversationMessageRepository, a redundant specification is removed and the variable type is made explicit. The HTML template in the post component now only displays the channel reference when a non-empty display name exists. Additionally, a test is added to verify that message searches include both direct chats and group chats.

Changes

File(s) Change Summary
src/main/java/de/tum/cit/.../ConversationMessageRepository.java Removed the call to getCourseWideChannelsSpecification and now uses only getConversationsSpecification. Changed variable declaration from var to Specification<Post>.
src/main/webapp/app/shared/metis/post/post.component.html Modified the condition for rendering the channel reference by adding a check for a non-empty contextInformation.displayName.
src/test/java/de/tum/cit/.../MessageIntegrationTest.java Added the test method testFindCourseWideMessages_IncludesDirectChatsAndNonCourseWideChannels to verify that both direct chat and group chat messages are included in the search results.

Possibly related PRs

Suggested labels

ready for review, component:Communication

Suggested reviewers

  • JohannesStoehr
  • egekurt123
  • FelberMartin
  • krusche
  • HanyangXu0508
  • sarpsahinalp
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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. (Beta)
  • @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.

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/test/java/de/tum/cit/aet/artemis/communication/MessageIntegrationTest.java (1)

760-784: Well-structured test covering the core functionality.

The test effectively verifies that the message search includes results from both direct chats and non-course-wide channels, which is crucial for the PR's objective.

A few suggestions to enhance the test:

  1. Add negative test cases
  2. Test with empty search results
  3. Test with special characters in search text
 @Test
 @WithMockUser(username = TEST_PREFIX + "student1", roles = "USER")
 void testFindCourseWideMessages_IncludesDirectChatsAndNonCourseWideChannels() throws Exception {
+    // Test with messages that should be found
     Post directPost = createPostWithOneToOneChat(TEST_PREFIX);
     directPost.setContent("SearchTestDirect");
     request.postWithResponseBody("/api/courses/" + courseId + "/messages", directPost, Post.class, HttpStatus.CREATED);

     Channel nonCourseWideChannel = conversationUtilService.createPublicChannel(course, "group-chat-test");
     conversationUtilService.addParticipantToConversation(nonCourseWideChannel, TEST_PREFIX + "student1");
     conversationUtilService.addParticipantToConversation(nonCourseWideChannel, TEST_PREFIX + "student2");
     Post groupPost = new Post();
     groupPost.setAuthor(userTestRepository.findOneByLogin(TEST_PREFIX + "student1").orElseThrow());
     groupPost.setConversation(nonCourseWideChannel);
     groupPost.setContent("SearchTestGroup");
     request.postWithResponseBody("/api/courses/" + courseId + "/messages", groupPost, Post.class, HttpStatus.CREATED);

+    // Test with a message that should not be found
+    Post irrelevantPost = createPostWithOneToOneChat(TEST_PREFIX);
+    irrelevantPost.setContent("IrrelevantContent");
+    request.postWithResponseBody("/api/courses/" + courseId + "/messages", irrelevantPost, Post.class, HttpStatus.CREATED);
+
     PostContextFilterDTO filter = new PostContextFilterDTO(course.getId(), new long[] {}, null, null, "SearchTest", false, false, false, PostSortCriterion.ANSWER_COUNT,
             SortingOrder.DESCENDING);

     var student1 = userTestRepository.findOneByLogin(TEST_PREFIX + "student1").orElseThrow();
     Page<Post> searchResults = conversationMessageRepository.findCourseWideMessages(filter, Pageable.unpaged(), student1.getId());
     List<Post> resultPosts = searchResults.getContent();
     assertThat(resultPosts).extracting(Post::getContent).contains("SearchTestDirect", "SearchTestGroup");
+    assertThat(resultPosts).extracting(Post::getContent).doesNotContain("IrrelevantContent");
+
+    // Test with no results
+    filter = new PostContextFilterDTO(course.getId(), new long[] {}, null, null, "NonExistentText", false, false, false, PostSortCriterion.ANSWER_COUNT,
+            SortingOrder.DESCENDING);
+    searchResults = conversationMessageRepository.findCourseWideMessages(filter, Pageable.unpaged(), student1.getId());
+    assertThat(searchResults.getContent()).isEmpty();
+
+    // Test with special characters
+    Post specialCharPost = createPostWithOneToOneChat(TEST_PREFIX);
+    specialCharPost.setContent("Search$Test#Special");
+    request.postWithResponseBody("/api/courses/" + courseId + "/messages", specialCharPost, Post.class, HttpStatus.CREATED);
+
+    filter = new PostContextFilterDTO(course.getId(), new long[] {}, null, null, "Search$Test#", false, false, false, PostSortCriterion.ANSWER_COUNT,
+            SortingOrder.DESCENDING);
+    searchResults = conversationMessageRepository.findCourseWideMessages(filter, Pageable.unpaged(), student1.getId());
+    assertThat(searchResults.getContent()).extracting(Post::getContent).contains("Search$Test#Special");
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 039e6c8 and 5b84611.

📒 Files selected for processing (3)
  • src/main/java/de/tum/cit/aet/artemis/communication/repository/ConversationMessageRepository.java (1 hunks)
  • src/main/webapp/app/shared/metis/post/post.component.html (1 hunks)
  • src/test/java/de/tum/cit/aet/artemis/communication/MessageIntegrationTest.java (2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
`src/main/webapp/**/*.html`: @if and @for are new and valid ...

src/main/webapp/**/*.html: @if and @for are new and valid Angular syntax replacing *ngIf and *ngFor. They should always be used over the old style.

  • src/main/webapp/app/shared/metis/post/post.component.html
`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/repository/ConversationMessageRepository.java
`src/test/java/**/*.java`: test_naming: descriptive; test_si...

src/test/java/**/*.java: test_naming: descriptive; test_size: small_specific; fixed_data: true; junit5_features: true; assert_use: assertThat; assert_specificity: true; archunit_use: enforce_package_rules; db_query_count_tests: track_performance; util_service_factory_pattern: true; avoid_db_access: true; mock_strategy: static_mocks; context_restart_minimize: true

  • src/test/java/de/tum/cit/aet/artemis/communication/MessageIntegrationTest.java
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (2)
src/main/java/de/tum/cit/aet/artemis/communication/repository/ConversationMessageRepository.java (1)

89-89: LGTM! Type declaration improvement and simplified filtering.

The change correctly removes redundant filtering and makes the type declaration more explicit, which improves code readability and allows message search to include results from all conversation types.

src/main/webapp/app/shared/metis/post/post.component.html (1)

45-45: LGTM! Improved UI by preventing empty channel references.

The additional check contextInformation.displayName !== '' prevents displaying empty channel references, which improves the user experience.

Copy link
Contributor

@SimonEntholzer SimonEntholzer left a comment

Choose a reason for hiding this comment

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

Bugfix code makes sense, added two questions to for the test

SortingOrder.DESCENDING);

var student1 = userTestRepository.findOneByLogin(TEST_PREFIX + "student1").orElseThrow();
Page<Post> searchResults = conversationMessageRepository.findCourseWideMessages(filter, Pageable.unpaged(), student1.getId());
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you save via a post request, would it also make sense to use a get request to get the actual searchResults, instead of simply using the repository?

@@ -756,6 +757,31 @@ void testGetCourseWideMessagesWithPinnedOnly() throws Exception {
assertThat(allPosts).extracting(Post::getId).containsExactlyInAnyOrder(createdPinnedPost.getId(), createdUnpinnedPost.getId());
}

@Test
@WithMockUser(username = TEST_PREFIX + "student1", roles = "USER")
void testFindCourseWideMessages_IncludesDirectChatsAndNonCourseWideChannels() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you are testing if this works for directChats, and courseWideChannels, would it make sense to split this into two tests, for maintainability?

@helios-aet helios-aet bot temporarily deployed to artemis-test3.artemis.cit.tum.de February 17, 2025 21:58 Inactive
Copy link

@HanyangXu0508 HanyangXu0508 left a comment

Choose a reason for hiding this comment

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

image
test server 3 and worked as expected.

@helios-aet helios-aet bot temporarily deployed to artemis-test2.artemis.cit.tum.de February 18, 2025 08:30 Inactive
Copy link

@simonbohnen simonbohnen left a comment

Choose a reason for hiding this comment

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

This doesn't quite work as expected yet. I noticed two problems while testing on TS2:

Search results are inconsistent

Steps to reproduce:

  • Log in on TS2 as artemis_test_user_16
  • Go to the chat with me, Simon Martin Bohnen
  • Search for 'Servus' in the main search bar
  • Verify that the message from the DM with me shows up
  • Go to the 'organization' channel
  • Search for 'test'
  • Search for 'servus'
  • Verify that the message from my DM does NOT show up

It's not possible to go to the corresponding DM from the search results

There is a link to the channel if the message is from a channel, but there is no link if the message is from a DM. This might be a separate issue.

Copy link

@sachmii sachmii 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 TS6, works just fine.

@helios-aet helios-aet bot temporarily deployed to artemis-test3.artemis.cit.tum.de February 19, 2025 10:27 Inactive
Copy link

@SindiBuklaji SindiBuklaji left a comment

Choose a reason for hiding this comment

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

Works as expected on TS3 👍
image

Copy link

@Feras797 Feras797 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 TS6, works as expected!
image

@helios-aet helios-aet bot temporarily deployed to artemis-test2.artemis.cit.tum.de February 19, 2025 11:18 Inactive
Copy link

@ahbitaqu ahbitaqu 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]

Works perfectly! neat change

@helios-aet helios-aet bot temporarily deployed to artemis-test3.artemis.cit.tum.de February 19, 2025 13:59 Inactive
Copy link

@sawys777 sawys777 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, everything works as expected
testsearch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix client Pull requests that update TypeScript code. (Added Automatically!) communication Pull requests that affect the corresponding module ready for review server Pull requests that update Java code. (Added Automatically!) small tests
Projects
Status: Ready For Review
Status: Todo
Development

Successfully merging this pull request may close these issues.

Communication Search doesn't show messages from some channels
9 participants