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: Add pinned messages filter #10173

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from

Conversation

asliayk
Copy link
Contributor

@asliayk asliayk commented Jan 20, 2025

Checklist

General

Client

  • I strictly followed the client coding and design guidelines.
  • Following the theming guidelines, I specified colors only in the theming variable files and checked that the changes look consistent in both the light and the dark theme.
  • I added multiple integration tests (Jest) related to the features (with a high test coverage), while following the test guidelines.
  • I added multiple screenshots/screencasts of my UI changes.
  • I translated all newly inserted strings into English and German.

Motivation and Context

As discussed in the communication subgroup, displaying pinned messages at the top of the chat history was not the best approach. This is because, in conversations that have been open for a long time and contain many messages, pinned messages become practically invisible to the user, requiring them to scroll all the way to the top. Users need a separate/specific section to easily access pinned messages, similar to how it is implemented in Slack.

Description

  • A button has been added to allow users to view the pinned messages of a conversation separately. If there are pinned messages, the button becomes visible. When the user clicks this button, only the pinned messages are displayed on the screen. Clicking the button again restores the conversation to its original view.
  • The typo in the function name isisCourseWideChannelControl has been corrected to isCourseWideChannelControl.

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. Open a random channel, send some messages, and pin them.
  4. Notice that the pinned messages button, located next to the search button in the conversation header, becomes visible.
  5. Click on the pinned messages button to display a list of pinned messages on the page.
  6. Click the button again to return to the conversation.

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Test Coverage

Client

Class/File Line Coverage Confirmation (assert/expect)
course-conversations.component.ts 91.14% ✅ ❌
channel-form.component.ts 89.47% ✅ ❌
conversation-header.component.ts 96.51% ✅ ❌
conversation-messages.component.ts 96.26% ✅ ❌
metis.service.ts 91.5% ✅ ❌
metis.util.ts 100%
post.service.ts 78% ✅ ❌
posting.directive.ts 93.82% ✅ ❌

Screenshots

pinned messages button
image

applying pinned messages filter
image

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added ability to view and toggle pinned messages in course conversations.
    • Introduced pinned message count display.
    • Enhanced conversation message filtering options based on pinned status.
    • Added functionality to fetch and manage pinned posts.
    • Improved localization with new translations for pinned message functionality.
  • Bug Fixes

    • Corrected method naming in channel form component.
  • Style

    • Added styling for pinned messages button in conversation header.
  • Tests

    • Added comprehensive test coverage for new pinned message features.
    • Enhanced tests for pinning and unpinning posts.
    • Improved tests for managing pinned posts in the service.

@asliayk asliayk added feature tests client Pull requests that update TypeScript code. (Added Automatically!) component:Communication labels Jan 20, 2025
@asliayk asliayk self-assigned this Jan 20, 2025
@asliayk asliayk temporarily deployed to artemis-test2.artemis.cit.tum.de January 20, 2025 12:13 — with GitHub Actions Inactive
@asliayk asliayk marked this pull request as ready for review January 20, 2025 12:17
@asliayk asliayk requested a review from a team as a code owner January 20, 2025 12:17
Copy link

coderabbitai bot commented Jan 20, 2025

Walkthrough

This pull request introduces functionality for managing pinned messages in course conversations. The changes span multiple components and files, focusing on enhancing the user interface for displaying and interacting with pinned messages. Key modifications include adding new properties and methods to handle pinned message visibility, implementing filtering mechanisms, and updating the UI to show pinned message counts and toggle options.

Changes

File Change Summary
src/main/webapp/app/overview/course-conversations/course-conversations.component.html Added bindings for pinned message functionality in conversation header and messages components.
src/main/webapp/app/overview/course-conversations/course-conversations.component.ts Introduced showOnlyPinned and pinnedCount properties with methods to toggle and update pinned message view.
src/main/webapp/app/overview/course-conversations/layout/conversation-header/conversation-header.component.* Added UI elements and logic to display and toggle pinned messages, including new styles and event handling.
src/main/webapp/app/overview/course-conversations/layout/conversation-messages/conversation-messages.component.ts Implemented filtering of posts based on pinned status, added showOnlyPinned input and pinnedCount output.
src/main/webapp/i18n/de/metis.json Added German translations for pinned message display.
src/main/webapp/i18n/en/metis.json Added English translations for pinned message display.
src/test/javascript/spec/component/overview/course-conversations/course-conversations.component.spec.ts Added tests for toggling pinned view and updating pinned count.
src/test/javascript/spec/component/overview/course-conversations/layout/conversation-header/conversation-header.component.spec.ts Added tests for toggling pinned messages and handling visibility state.
src/test/javascript/spec/component/overview/course-conversations/layout/conversation-messages/conversation-messages.component.spec.ts Added tests for filtering posts based on pinned status and verifying emitted counts.
src/main/java/de/tum/cit/aet/artemis/communication/dto/PostContextFilterDTO.java Added pinnedOnly parameter to filter posts based on pinned status.
src/main/java/de/tum/cit/aet/artemis/communication/repository/ConversationMessageRepository.java Integrated new filtering criterion for pinned messages in search specifications.
src/main/java/de/tum/cit/aet/artemis/communication/repository/MessageSpecs.java Added method to get pinned specifications for filtering posts.
src/main/webapp/app/shared/metis/metis.service.ts Added methods to fetch and manage pinned posts.
src/main/webapp/app/shared/metis/metis.util.ts Updated PostContextFilter interface to include pinnedOnly property.
src/main/webapp/app/shared/metis/post.service.ts Enhanced getPosts method to filter based on pinned status.

Possibly related PRs

  • Communication: Fix user interface reload on channel selection #9464: The changes in the main PR are related to the modifications in the CourseConversationsComponent class, specifically regarding the handling of loading states and the management of conversation messages, which aligns with the updates made in the retrieved PR.
  • Communication: Improve visibility of pinned messages #10117: The changes in the main PR are related to those in the retrieved PR as both involve enhancements to the handling and display of pinned messages within the conversation components, specifically modifying the same components to improve their functionality regarding pinned message visibility and interaction.
  • Communication: Resolve an issues when displaying replies to a post #10122: The changes in the main PR are related to the modifications in the jhi-conversation-messages component, specifically regarding the handling of pinned messages, which aligns with the event handling changes in the retrieved PR's jhi-conversation-messages component.

Suggested labels

ready to merge

Suggested reviewers

  • sachmii
  • cremertim
  • PaRangger
✨ 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

🔭 Outside diff range comments (2)
src/main/webapp/app/overview/course-conversations/layout/conversation-messages/conversation-messages.component.ts (1)

Line range hint 324-338: Improve type safety for post processing.

The post processing logic uses 'any' type for creationDateDayjs, which bypasses TypeScript's type checking. Consider adding proper typing:

+interface PostWithDayjs extends Post {
+    creationDateDayjs?: dayjs.Dayjs;
+}

-setPosts(): void {
+setPosts(): void {
     if (this.content) {
         this.previousScrollDistanceFromTop = this.content.nativeElement.scrollHeight - this.content.nativeElement.scrollTop;
     }

     this.applyPinnedMessageFilter();

-    this.posts = this.posts
+    this.posts = (this.posts as PostWithDayjs[])
         .slice()
         .reverse()
         .map((post) => {
-            (post as any).creationDateDayjs = post.creationDate ? dayjs(post.creationDate) : undefined;
+            post.creationDateDayjs = post.creationDate ? dayjs(post.creationDate) : undefined;
             return post;
         });

     this.groupPosts();
 }
src/main/webapp/app/overview/course-conversations/course-conversations.component.html (1)

Line range hint 1-90: *Migrate remaining ngIf directives to @if syntax.

Per the coding guidelines, @if syntax should be used instead of *ngIf. Please update the remaining *ngIf directives:

-    <div class="input-group mb-2 rounded-3 p-2 me-2 module-bg" [hidden]="!isCodeOfConductAccepted">
+    @if (isCodeOfConductAccepted) {
+    <div class="input-group mb-2 rounded-3 p-2 me-2 module-bg">
🧹 Nitpick comments (4)
src/main/webapp/app/overview/course-conversations/layout/conversation-header/conversation-header.component.html (1)

52-74: Well-structured implementation of the pinned messages filter!

The implementation follows best practices with:

  • Proper conditional rendering
  • Clear visual feedback with emojis
  • Internationalized text with number interpolation

Consider adding aria-label for better accessibility

Add aria-label to the button to improve screen reader support.

-                                <button type="button" (click)="togglePinnedMessages()" class="btn btn-sm btn-outline-secondary">
+                                <button 
+                                    type="button" 
+                                    (click)="togglePinnedMessages()" 
+                                    class="btn btn-sm btn-outline-secondary"
+                                    [attr.aria-label]="showPinnedMessages ? 'Hide pinned messages' : 'Show pinned messages'">
src/main/webapp/app/overview/course-conversations/layout/conversation-messages/conversation-messages.component.ts (1)

147-155: Consider optimizing array operations.

While the implementation is functionally correct, creating new arrays on each filter operation could impact performance with large datasets. Consider these optimizations:

  1. Cache the pinned posts count to avoid recalculating it
  2. Use a getter for filtered posts instead of maintaining a separate array

Example implementation:

-applyPinnedMessageFilter(): void {
-    if (this.showOnlyPinned()) {
-        this.posts = this.allPosts.filter((post) => post.displayPriority === DisplayPriority.PINNED);
-    } else {
-        this.posts = [...this.allPosts];
-    }
-    const pinnedCount = this.allPosts.filter((post) => post.displayPriority === DisplayPriority.PINNED).length;
-    this.pinnedCount.emit(pinnedCount);
-}
+private cachedPinnedCount = 0;
+
+private updatePinnedCount(): void {
+    this.cachedPinnedCount = this.allPosts.filter((post) => post.displayPriority === DisplayPriority.PINNED).length;
+    this.pinnedCount.emit(this.cachedPinnedCount);
+}
+
+get filteredPosts(): Post[] {
+    return this.showOnlyPinned() 
+        ? this.allPosts.filter((post) => post.displayPriority === DisplayPriority.PINNED)
+        : this.allPosts;
+}
+
+applyPinnedMessageFilter(): void {
+    this.updatePinnedCount();
+    this.posts = this.filteredPosts;
+}
src/main/webapp/app/overview/course-conversations/course-conversations.component.ts (1)

165-166: Consider using a more TypeScript-idiomatic initialization.

The pinnedCount property initialization can be more concise:

-showOnlyPinned = false;
-pinnedCount: number = 0;
+showOnlyPinned = false;
+pinnedCount = 0;
src/main/webapp/app/overview/course-conversations/course-conversations.component.html (1)

67-68: Consider adding an aria-label for accessibility.

The implementation looks good! To enhance accessibility, consider adding an aria-label to indicate when pinned messages are being filtered.

-        [showOnlyPinned]="showOnlyPinned"
+        [showOnlyPinned]="showOnlyPinned"
+        [attr.aria-label]="showOnlyPinned ? 'Showing only pinned messages' : 'Showing all messages'"
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between acb1220 and ccba632.

📒 Files selected for processing (12)
  • src/main/webapp/app/overview/course-conversations/course-conversations.component.html (1 hunks)
  • src/main/webapp/app/overview/course-conversations/course-conversations.component.ts (2 hunks)
  • src/main/webapp/app/overview/course-conversations/dialogs/channels-create-dialog/channel-form/channel-form.component.ts (2 hunks)
  • src/main/webapp/app/overview/course-conversations/layout/conversation-header/conversation-header.component.html (1 hunks)
  • src/main/webapp/app/overview/course-conversations/layout/conversation-header/conversation-header.component.scss (1 hunks)
  • src/main/webapp/app/overview/course-conversations/layout/conversation-header/conversation-header.component.ts (4 hunks)
  • src/main/webapp/app/overview/course-conversations/layout/conversation-messages/conversation-messages.component.ts (8 hunks)
  • src/main/webapp/i18n/de/metis.json (1 hunks)
  • src/main/webapp/i18n/en/metis.json (1 hunks)
  • src/test/javascript/spec/component/overview/course-conversations/course-conversations.component.spec.ts (1 hunks)
  • src/test/javascript/spec/component/overview/course-conversations/layout/conversation-header/conversation-header.component.spec.ts (1 hunks)
  • src/test/javascript/spec/component/overview/course-conversations/layout/conversation-messages/conversation-messages.component.spec.ts (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/main/webapp/app/overview/course-conversations/layout/conversation-header/conversation-header.component.scss
🧰 Additional context used
📓 Path-based instructions (10)
src/main/webapp/app/overview/course-conversations/layout/conversation-header/conversation-header.component.html (1)

Pattern 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/test/javascript/spec/component/overview/course-conversations/layout/conversation-header/conversation-header.component.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

src/main/webapp/i18n/de/metis.json (1)

Pattern src/main/webapp/i18n/de/**/*.json: German language translations should be informal (dutzen) and should never be formal (sietzen). So the user should always be addressed with "du/dein" and never with "sie/ihr".

src/main/webapp/app/overview/course-conversations/course-conversations.component.html (1)

Pattern 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/test/javascript/spec/component/overview/course-conversations/layout/conversation-messages/conversation-messages.component.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

src/main/webapp/app/overview/course-conversations/dialogs/channels-create-dialog/channel-form/channel-form.component.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

src/main/webapp/app/overview/course-conversations/layout/conversation-header/conversation-header.component.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

src/main/webapp/app/overview/course-conversations/course-conversations.component.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

src/main/webapp/app/overview/course-conversations/layout/conversation-messages/conversation-messages.component.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

src/test/javascript/spec/component/overview/course-conversations/course-conversations.component.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (15)
src/main/webapp/app/overview/course-conversations/dialogs/channels-create-dialog/channel-form/channel-form.component.ts (1)

60-60: LGTM! The getter method name has been corrected.

The typo in the getter method name has been fixed from isisCourseWideChannelControl to isCourseWideChannelControl, which aligns with the PR objectives.

Also applies to: 110-110

src/main/webapp/app/overview/course-conversations/layout/conversation-header/conversation-header.component.ts (4)

28-29: LGTM! New imports and component metadata are properly configured.

The imports for EmojiComponent and ArtemisTranslatePipe are correctly added and included in the component's metadata.

Also applies to: 35-35


42-43: LGTM! Properties are properly initialized using the new input/output syntax.

The properties are correctly initialized:

  • pinnedMessageCount as an input with a default value of 0
  • togglePinnedMessage as an output event emitter

66-66: LGTM! State management and dependency injection are properly configured.

The component correctly:

  • Initializes the showPinnedMessages state
  • Injects the ChangeDetectorRef for managing view updates

Also applies to: 69-69


81-85: LGTM! The toggle method is properly implemented.

The togglePinnedMessages method correctly:

  1. Emits the toggle event
  2. Updates the local state
  3. Triggers change detection
src/test/javascript/spec/component/overview/course-conversations/layout/conversation-header/conversation-header.component.spec.ts (2)

154-165: LGTM! The visibility toggle test is comprehensive.

The test case properly verifies:

  1. Initial state is false
  2. State changes after first toggle
  3. State reverts after second toggle

167-172: LGTM! The event emission test is properly implemented.

The test case correctly verifies that the togglePinnedMessage event is emitted when the toggle method is called.

src/main/webapp/i18n/en/metis.json (1)

14-16: LGTM! Clear and consistent translations.

The translations are well-structured with proper handling of singular/plural cases.

src/main/webapp/i18n/de/metis.json (1)

14-16: LGTM! Translations follow German language guidelines.

The translations correctly use:

  • Informal style (dutzen) as required
  • Proper singular/plural forms
  • Consistent terminology with existing translations
src/main/webapp/app/overview/course-conversations/layout/conversation-messages/conversation-messages.component.ts (2)

70-70: LGTM! Properties are well-defined and follow Angular patterns.

The new properties are correctly typed and follow Angular's signal-based input/output pattern. The naming is clear and follows conventions.

Also applies to: 95-96, 116-116


141-145: LGTM! OnChanges implementation is correct.

The ngOnChanges implementation correctly handles changes to showOnlyPinned and avoids unnecessary setPosts calls on first change.

src/test/javascript/spec/component/overview/course-conversations/layout/conversation-messages/conversation-messages.component.spec.ts (1)

300-380: LGTM! Test coverage is comprehensive.

The test cases thoroughly cover the new pinned messages functionality:

  • Filtering of pinned posts
  • Showing all posts
  • Pinned count emission
  • Change detection handling
src/main/webapp/app/overview/course-conversations/course-conversations.component.ts (1)

208-214: LGTM! Methods are concise and focused.

The togglePinnedView and onPinnedCountChanged methods are well-implemented and follow the single responsibility principle.

src/test/javascript/spec/component/overview/course-conversations/course-conversations.component.spec.ts (1)

661-676: LGTM! Test cases are well-structured.

The test cases effectively verify:

  • Toggle behavior of showOnlyPinned
  • Update behavior of pinnedCount
src/main/webapp/app/overview/course-conversations/course-conversations.component.html (1)

54-59: LGTM! Clean implementation of pinned message header functionality.

The new bindings for toggling pinned messages and displaying their count are well-integrated into the existing header component.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 20, 2025
Malekos74
Malekos74 previously approved these changes Jan 20, 2025
Copy link

@Malekos74 Malekos74 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 Server 02

Works as expected

SindiBuklaji
SindiBuklaji previously approved these changes Jan 20, 2025
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.

Tested on TS2 and it works as described. 👍
image

Copy link

@Cathy0123456789 Cathy0123456789 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 TS5.

  • When deleting a pinned message, the count does not update until you reload the page
  • When pinning a post, and a student being in the same channel at the same time, the change is reflected in the color change, but the count does not update for the student and when clicking the pinned-messages-button, the newly pinned message does not show up in the list as well for the student

@asliayk asliayk dismissed stale reviews from HawKhiem and coderabbitai[bot] via c39b0da January 31, 2025 15:44
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: 1

🧹 Nitpick comments (1)
src/main/webapp/app/shared/metis/metis.service.ts (1)

298-318: Consider adding error logging for better debugging.

The error handling in fetchAllPinnedPosts silently swallows errors. While resetting to an empty array is appropriate, logging the error would help with debugging.

 catchError((err) => {
+    console.error('Error fetching pinned posts:', err);
     this.pinnedPosts$.next([]);
     return of([]);
 }),
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5095d44 and c39b0da.

📒 Files selected for processing (2)
  • src/main/webapp/app/shared/metis/metis.service.ts (7 hunks)
  • src/test/javascript/spec/service/metis/metis.service.spec.ts (5 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/main/webapp/app/shared/metis/metis.service.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

src/test/javascript/spec/service/metis/metis.service.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

🪛 Biome (1.9.4)
src/main/webapp/app/shared/metis/metis.service.ts

[error] 705-705: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 709-709: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 710-710: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Call Build Workflow / Build .war artifact
  • GitHub Check: Call Build Workflow / Build and Push Docker Image
  • GitHub Check: client-tests-selected
  • GitHub Check: client-tests
  • GitHub Check: Analyse
🔇 Additional comments (3)
src/main/webapp/app/shared/metis/metis.service.ts (2)

51-51: LGTM! Well-structured observable pattern implementation.

The pinnedPosts$ BehaviorSubject and its public getter method follow Angular best practices for state management.

Also applies to: 89-91


771-782: LGTM! Well-documented and focused helper method.

The removeFromPinnedPosts method is well-documented and follows the single responsibility principle.

src/test/javascript/spec/service/metis/metis.service.spec.ts (1)

Line range hint 163-790: LGTM! Comprehensive test coverage with clear test cases.

The test suite thoroughly covers the pinned messages functionality:

  • Tests WebSocket interactions for pinning/unpinning
  • Verifies server fetching behavior
  • Includes edge cases for post removal
  • Uses proper test cleanup with subscription management

src/main/webapp/app/shared/metis/metis.service.ts Outdated Show resolved Hide resolved
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 31, 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/test/javascript/spec/component/overview/course-conversations/course-conversations.component.spec.ts (2)

661-669: LGTM! Consider improving test description.

The test correctly verifies the toggle functionality. Consider making the test description more specific about the behavior being tested.

-            it('should toggle the value of showOnlyPinned', () => {
+            it('should toggle pinned messages visibility between shown and hidden states', () => {

671-676: LGTM! Consider adding edge case tests.

The test correctly verifies the pinned count update. Consider adding tests for edge cases.

Add these test cases for better coverage:

it('should handle negative pinnedCount values by setting to 0', () => {
    component.onPinnedCountChanged(-1);
    expect(component.pinnedCount).toBe(0);
});

it('should handle undefined pinnedCount by setting to 0', () => {
    component.onPinnedCountChanged(undefined);
    expect(component.pinnedCount).toBe(0);
});
src/test/javascript/spec/component/overview/course-conversations/layout/conversation-header/conversation-header.component.spec.ts (1)

174-191: Enhance boolean assertions for better error messages.

The change detection tests are well-structured but could benefit from more specific assertions.

Update the boolean assertions to follow the coding guidelines:

-                expect(component.showPinnedMessages).toBeFalse();
+                expect(component.showPinnedMessages).toBe(false);
-                expect(component.showPinnedMessages).toBeTrue();
+                expect(component.showPinnedMessages).toBe(true);

This change aligns with the coding guidelines which specify using toBe(false) and toBe(true) instead of toBeFalse() and toBeTrue() for boolean assertions.

Also applies to: 193-210, 212-229

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c39b0da and 6a06761.

📒 Files selected for processing (2)
  • src/test/javascript/spec/component/overview/course-conversations/course-conversations.component.spec.ts (1 hunks)
  • src/test/javascript/spec/component/overview/course-conversations/layout/conversation-header/conversation-header.component.spec.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/test/javascript/spec/component/overview/course-conversations/layout/conversation-header/conversation-header.component.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

src/test/javascript/spec/component/overview/course-conversations/course-conversations.component.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Call Build Workflow / Build and Push Docker Image
  • GitHub Check: Call Build Workflow / Build .war artifact
  • GitHub Check: client-tests-selected
  • GitHub Check: client-tests
  • GitHub Check: Analyse
🔇 Additional comments (4)
src/test/javascript/spec/component/overview/course-conversations/course-conversations.component.spec.ts (1)

678-692: LGTM! Tests follow Jest's expectation specificity guidelines.

The tests correctly use Jest's toBeTrue() and toBeFalse() instead of toBe(true) and toBe(false) as recommended by the coding guidelines.

src/test/javascript/spec/component/overview/course-conversations/layout/conversation-header/conversation-header.component.spec.ts (3)

29-30: LGTM!

The new imports are appropriate for the added test functionality.


154-165: LGTM! Well-structured toggle visibility test.

The test properly verifies the toggle behavior with clear assertions and spy usage.


167-172: LGTM! Event emission test follows best practices.

The test correctly verifies the event emission using a spy.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 31, 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 (1)
src/main/webapp/app/shared/metis/metis.service.ts (1)

299-319: LGTM with a minor suggestion.

The implementation is solid with proper error handling and state management. Consider adding a loading state to handle the async operation.

Add a loading state to improve the user experience:

+private pinnedPostsLoading$ = new BehaviorSubject<boolean>(false);
+
+getPinnedPostsLoading(): Observable<boolean> {
+  return this.pinnedPostsLoading$.asObservable();
+}

 public fetchAllPinnedPosts(conversationId: number): Observable<Post[]> {
+  this.pinnedPostsLoading$.next(true);
   const pinnedFilter: PostContextFilter = {
     courseId: this.courseId,
     conversationId: conversationId,
     postSortCriterion: PostSortCriterion.CREATION_DATE,
     sortingOrder: SortDirection.DESCENDING,
     pinnedOnly: true,
     pagingEnabled: false,
   };

   return this.postService.getPosts(this.courseId, pinnedFilter).pipe(
     map((res: HttpResponse<Post[]>) => res.body ?? []),
     tap((pinnedPosts: Post[]) => {
       this.pinnedPosts$.next(pinnedPosts);
+      this.pinnedPostsLoading$.next(false);
     }),
     catchError((err) => {
       this.pinnedPosts$.next([]);
+      this.pinnedPostsLoading$.next(false);
       return of([]);
     }),
   );
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6a06761 and 4086cb7.

📒 Files selected for processing (2)
  • src/main/webapp/app/shared/metis/metis.service.ts (7 hunks)
  • src/test/javascript/spec/service/metis/metis.service.spec.ts (5 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/main/webapp/app/shared/metis/metis.service.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

src/test/javascript/spec/service/metis/metis.service.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

🪛 Biome (1.9.4)
src/main/webapp/app/shared/metis/metis.service.ts

[error] 709-709: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 713-713: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 714-714: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)

src/test/javascript/spec/service/metis/metis.service.spec.ts

[error] 819-821: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Call Build Workflow / Build and Push Docker Image
  • GitHub Check: client-tests
  • GitHub Check: client-tests-selected
  • GitHub Check: Analyse
🔇 Additional comments (5)
src/main/webapp/app/shared/metis/metis.service.ts (4)

51-51: LGTM!

The pinnedPosts$ BehaviorSubject is well-designed for managing the pinned posts state.


694-705: Wrap switch case declarations in blocks to prevent variable hoisting.

The declarations inside the switch case could be hoisted to the outer scope. This is flagged by the static analysis tool.

 case MetisPostAction.UPDATE:
+    {
     const indexToUpdate = this.cachedPosts.findIndex((post) => post.id === postDTO.post.id);
     if (indexToUpdate > -1) {
         postDTO.post.authorRole = this.cachedPosts[indexToUpdate].authorRole;
         postDTO.post.answers?.forEach((answer: AnswerPost) => {
             const cachedAnswer = this.cachedPosts[indexToUpdate].answers?.find((a) => a.id === answer.id);
             if (cachedAnswer) {
                 answer.authorRole = cachedAnswer.authorRole;
             }
         });
         this.cachedPosts[indexToUpdate] = postDTO.post;
     }

     if (postDTO.post.displayPriority === DisplayPriority.PINNED) {
         const currentPinnedPosts = this.pinnedPosts$.getValue();
         const indexPinned = currentPinnedPosts.findIndex((pinnedPost) => pinnedPost.id === postDTO.post.id);
         if (indexPinned > -1) {
             currentPinnedPosts[indexPinned] = postDTO.post;
             this.pinnedPosts$.next([...currentPinnedPosts]);
         } else {
             this.pinnedPosts$.next([postDTO.post, ...currentPinnedPosts]);
         }
     } else {
         this.removeFromPinnedPosts(postDTO.post.id!);
     }
     this.addTags(postDTO.post.tags);
+    }
     break;

713-718: Wrap switch case declarations in blocks to prevent variable hoisting.

The declarations inside the switch case could be hoisted to the outer scope. This is flagged by the static analysis tool.

 case MetisPostAction.DELETE:
+    {
     const indexToDelete = this.cachedPosts.findIndex((post) => post.id === postDTO.post.id);
     if (indexToDelete > -1) {
         this.cachedPosts.splice(indexToDelete, 1);
     }
     const currentPinnedPosts = this.pinnedPosts$.getValue();
     const isPinned = currentPinnedPosts.some((pinnedPost) => pinnedPost.id === postDTO.post.id);
     if (isPinned) {
         const updatedPinnedPosts = currentPinnedPosts.filter((pinnedPost) => pinnedPost.id !== postDTO.post.id);
         this.pinnedPosts$.next(updatedPinnedPosts);
     }
+    }
     break;
🧰 Tools
🪛 Biome (1.9.4)

[error] 713-713: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 714-714: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


779-786: LGTM!

The helper method is well-documented and efficiently implements the removal of posts from the pinned posts list.

src/test/javascript/spec/service/metis/metis.service.spec.ts (1)

163-825: LGTM! Comprehensive test coverage.

The test suite thoroughly covers all aspects of the pinned messages functionality:

  • Pinning/unpinning posts
  • WebSocket interactions
  • Edge cases and error scenarios
🧰 Tools
🪛 Biome (1.9.4)

[error] 819-821: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

@asliayk
Copy link
Contributor Author

asliayk commented Feb 2, 2025

I have also fixed the synchronization issues with pinned messages. Now, when a message is deleted or another user pins a message, the pinned count updates in real-time for other users without requiring a page refresh.

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

Successfully merging this pull request may close these issues.