Skip to content

Commit

Permalink
Added references to non-channel posts
Browse files Browse the repository at this point in the history
  • Loading branch information
cremertim committed Oct 28, 2024
1 parent f1562b2 commit dbe5e5f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ private Specification<Post> configureSearchSpecification(Specification<Post> spe
default Page<Post> findMessages(PostContextFilterDTO postContextFilter, Pageable pageable, long userId) {
var specification = Specification.where(getConversationSpecification(postContextFilter.conversationId()));
specification = configureSearchSpecification(specification, postContextFilter, userId);
String searchText = postContextFilter.searchText() != null ? postContextFilter.searchText() : "";
// Fetch all necessary attributes to avoid lazy loading (even though relations are defined as EAGER in the domain class, specification queries do not respect this)
return findPostsWithSpecification(pageable, specification);
}
Expand All @@ -89,7 +88,6 @@ default Page<Post> findCourseWideMessages(PostContextFilterDTO postContextFilter
var specification = Specification.where(getCourseWideChannelsSpecification(postContextFilter.courseId()))
.and(getConversationsSpecification(postContextFilter.courseWideChannelIds()));
specification = configureSearchSpecification(specification, postContextFilter, userId);
String searchText = postContextFilter.searchText() != null ? postContextFilter.searchText() : "";
return findPostsWithSpecification(pageable, specification);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ public static Specification<Post> getCourseWideChannelsSpecification(Long course
return (root, query, criteriaBuilder) -> {
final var conversationJoin = root.join(Post_.conversation, JoinType.LEFT);
final var isInCoursePredicate = criteriaBuilder.equal(conversationJoin.get(Channel_.COURSE).get(Course_.ID), courseId);
// final var isCourseWidePredicate = criteriaBuilder.isTrue(conversationJoin.get(Channel_.IS_COURSE_WIDE));
// make sure we only fetch channels (which are sub types of conversations)
// this avoids the creation of sub queries
// final var isChannelPredicate = criteriaBuilder.equal(conversationJoin.type(), criteriaBuilder.literal(Channel.class));
return criteriaBuilder.and(isInCoursePredicate);
};
}
Expand Down
20 changes: 17 additions & 3 deletions src/main/webapp/app/shared/metis/metis.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { User } from 'app/core/user/user.model';
import { AccountService } from 'app/core/auth/account.service';
import { Course } from 'app/entities/course.model';
import { Posting } from 'app/entities/metis/posting.model';
import { Injectable, OnDestroy } from '@angular/core';
import { Injectable, OnDestroy, inject } from '@angular/core';
import { AnswerPostService } from 'app/shared/metis/answer-post.service';
import { AnswerPost } from 'app/entities/metis/answer-post.model';
import { Reaction } from 'app/entities/metis/reaction.model';
Expand All @@ -27,10 +27,11 @@ import { JhiWebsocketService } from 'app/core/websocket/websocket.service';
import { MetisPostDTO } from 'app/entities/metis/metis-post-dto.model';
import dayjs from 'dayjs/esm';
import { PlagiarismCase } from 'app/exercises/shared/plagiarism/types/PlagiarismCase';
import { Conversation, ConversationDTO } from 'app/entities/metis/conversation/conversation.model';
import { Conversation, ConversationDTO, ConversationType } from 'app/entities/metis/conversation/conversation.model';
import { ChannelDTO, ChannelSubType, getAsChannelDTO } from 'app/entities/metis/conversation/channel.model';
import { ConversationService } from 'app/shared/metis/conversations/conversation.service';
import { NotificationService } from 'app/shared/notification/notification.service';
import { TranslateService } from '@ngx-translate/core';

@Injectable()
export class MetisService implements OnDestroy {
Expand All @@ -49,6 +50,7 @@ export class MetisService implements OnDestroy {
private subscriptionChannel?: string;

private courseWideTopicSubscription: Subscription;
private translateService = inject(TranslateService);

constructor(
protected postService: PostService,
Expand Down Expand Up @@ -515,14 +517,26 @@ export class MetisService implements OnDestroy {
let routerLinkComponents = undefined;
let queryParams = undefined;
let displayName = '';
console.log(post);
if (post.conversation) {
displayName = getAsChannelDTO(post.conversation)?.name ?? '';
displayName = this.getDisplayName(post)!;
routerLinkComponents = ['/courses', this.courseId, 'communication'];
queryParams = { conversationId: post.conversation.id! };
}
return { routerLinkComponents, displayName, queryParams };
}

getDisplayName(post: Post) {
switch (post.conversation!.type) {
case ConversationType.CHANNEL:
return getAsChannelDTO(post.conversation)?.name ?? '';
case ConversationType.ONE_TO_ONE:
return this.translateService.instant('artemisApp.conversationsLayout.conversationSelectionSideBar.groupChat');
case ConversationType.GROUP_CHAT:
return this.translateService.instant('artemisApp.conversationsLayout.conversationSelectionSideBar.directMessage');
}
}

/**
* Creates (and updates) the websocket channel for receiving messages in dedicated channels;
* On message reception, subsequent actions for updating the dependent components are defined based on the MetisPostAction encapsulated in the MetisPostDTO (message payload);
Expand Down
2 changes: 2 additions & 0 deletions src/main/webapp/i18n/de/conversation.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
"examChannels": "Klausuren",
"createChannel": "Kanal erstellen",
"browseChannels": "Kanäle durchsuchen",
"groupChat": "Gruppenchat",
"groupChats": "Gruppenchats",
"directMessage": "Direktnachricht",
"directMessages": "Direktnachrichten",
"filterConversationPlaceholder": "Konversationen filtern",
"sideBarSection": {
Expand Down
2 changes: 2 additions & 0 deletions src/main/webapp/i18n/en/conversation.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
"examChannels": "Exams",
"createChannel": "Create channel",
"browseChannels": "Browse channels",
"groupChat": "Group Chat",
"groupChats": "Group Chats",
"directMessage": "Direct Message",
"directMessages": "Direct Messages",
"filterConversationPlaceholder": "Filter conversations",
"sideBarSection": {
Expand Down

0 comments on commit dbe5e5f

Please sign in to comment.