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

Merged
merged 3 commits into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,11 @@ default Page<Post> findMessages(PostContextFilterDTO postContextFilter, Pageable
* @return returns a Page of Messages
*/
default Page<Post> findCourseWideMessages(PostContextFilterDTO postContextFilter, Pageable pageable, long userId) {
var specification = Specification.where(getCourseWideChannelsSpecification(postContextFilter.courseId()))
Specification<Post> specification = Specification.where(getCourseWideChannelsSpecification(postContextFilter.courseId()))
.and(getConversationsSpecification(postContextFilter.courseWideChannelIds()));
if (postContextFilter.searchText() != null && !postContextFilter.searchText().isEmpty()) {
specification = Specification.where(getConversationsSpecification(postContextFilter.courseWideChannelIds()));
}
specification = configureSearchSpecification(specification, postContextFilter, userId);
return findPostsWithSpecification(pageable, specification);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
}
<!-- in the course all-messages as well as in the preview mode during similarity check, the context (lecture, exercise, course-wide topic) is shown -->
<!-- not shown in course messages page -->
@if (showChannelReference && (pageType === PageType.OVERVIEW || previewMode())) {
@if (showChannelReference && (pageType === PageType.OVERVIEW || previewMode()) && contextInformation.displayName !== '') {
<span>
@if (contextInformation.routerLinkComponents) {
<a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.security.test.context.support.WithMockUser;
Expand Down Expand Up @@ -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 {
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);

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");
}

private long getUnreadMessagesCount(Conversation conversation, User user) {
return oneToOneChatRepository.findByIdWithConversationParticipantsAndUserGroups(conversation.getId()).orElseThrow().getConversationParticipants().stream()
.filter(conversationParticipant -> Objects.equals(conversationParticipant.getUser().getId(), user.getId())).findFirst().orElseThrow().getUnreadMessagesCount();
Expand Down
Loading