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: Change posting deletion logic to not abort when deconstructing a post #9882

Conversation

badkeyy
Copy link
Contributor

@badkeyy badkeyy commented Nov 27, 2024

Checklist

General

Client

  • Important: I implemented the changes with a very good performance, prevented too many (unnecessary) REST calls and made sure the UI is responsive, even with large data (e.g. using paging).
  • I strictly followed the principle of data economy for all client-server REST calls.
  • 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 authorities to all new routes and checked the course groups for displaying navigation elements (links, buttons).
  • I documented the TypeScript code using JSDoc style.
  • I added multiple screenshots/screencasts of my UI changes.
  • I translated all newly inserted strings into English and German.

Motivation and Context

Proposed by: #9848
Currently when one deletes a message and switches the chat or generally leaves the communication area before the deletion countdown has expired the delete operation gets aborted. In my opinion this should not be the intended behaviour as I as a user expect a message to get deleted when I press the delete button and leave the page.

Description

When the posting gets deconstructed the client now stops the delete timeout and instantly deletes the posting as it would have once the timeout expired

Steps for Testing

Prerequisites:

  • 2 Students
  • Course with communication enabled
  1. Log in to Artemis
  2. Navigate to Course Communication
  3. Post any message
  4. Delete the message and switch to another chat/page etc... before the delete time runs out
  5. Go back to where you originally posted the message and find it to be deleted

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

Performance Review

  • I (as a reviewer) confirm that the client changes (in particular related to REST calls and UI responsiveness) are implemented with a very good performance even for very large courses with more than 2000 students.
  • I (as a reviewer) confirm that the server changes (in particular related to database calls) are implemented with a very good performance even for very large courses with more than 2000 students.

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Exam Mode Test

  • Test 1
  • Test 2

Performance Tests

  • Test 1
  • Test 2

Screenshots

video

Summary by CodeRabbit

  • Bug Fixes

    • Improved the post deletion process to ensure posts are deleted correctly when the directive is destroyed or when a delete event occurs.
  • Refactor

    • Streamlined the post deletion logic by centralizing it into a single method for better clarity and maintainability.

@github-actions github-actions bot added the client Pull requests that update TypeScript code. (Added Automatically!) label Nov 27, 2024
@badkeyy badkeyy marked this pull request as ready for review November 27, 2024 15:26
@badkeyy badkeyy requested a review from a team as a code owner November 27, 2024 15:26
Copy link

coderabbitai bot commented Nov 27, 2024

Walkthrough

The changes introduce a new private method, deletePostingWithoutTimeout(), in the PostingDirective class within the posting.directive.ts file. This method centralizes the logic for deleting posts, which is invoked during the ngOnDestroy() lifecycle hook and the onDeleteEvent() method. The refactoring enhances code maintainability by reducing redundancy and clarifying the deletion process while maintaining the overall control flow.

Changes

File Path Change Summary
src/main/webapp/app/shared/metis/posting.directive.ts Added a private method deletePostingWithoutTimeout() to handle post deletion logic. Replaced inline deletion logic in ngOnDestroy() and onDeleteEvent() with calls to this new method.

Suggested labels

ready for review, small, bugfix, component:Communication

Suggested reviewers

  • SimonEntholzer
  • krusche
  • JohannesStoehr
  • EneaGore

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 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: 1

🧹 Outside diff range and nitpick comments (1)
src/main/webapp/app/shared/metis/posting.directive.ts (1)

69-69: LGTM! Consider additional cleanup.

The centralized deletion logic improves maintainability while maintaining the original timing behavior.

Consider using takeUntil with a destroy subject for the interval to prevent potential memory leaks:

+ private readonly destroy$ = new Subject<void>();

  ngOnInit(): void {
    this.content = this.posting.content;
  }

  ngOnDestroy(): void {
+   this.destroy$.next();
+   this.destroy$.complete();
    if (this.deleteTimer !== undefined) {
      clearTimeout(this.deleteTimer);
      this.deletePostingWithoutTimeout();
    }
    if (this.deleteInterval !== undefined) {
      clearInterval(this.deleteInterval);
    }
  }

  onDeleteEvent(isDelete: boolean) {
    // ... existing code ...
-   this.deleteInterval = setInterval(() => {
+   interval(1000).pipe(
+     takeUntil(this.destroy$)
+   ).subscribe(() => {
      this.deleteTimerInSeconds = Math.max(0, this.deleteTimerInSeconds - 1);
      this.changeDetector.detectChanges();
-   }, 1000);
    });
  }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 83ac531 and 94a8e29.

📒 Files selected for processing (1)
  • src/main/webapp/app/shared/metis/posting.directive.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/main/webapp/app/shared/metis/posting.directive.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

🔇 Additional comments (2)
src/main/webapp/app/shared/metis/posting.directive.ts (2)

132-138: Consider a more descriptive method name and verify flag usage.

While the implementation is correct, consider renaming to better reflect its immediate nature, e.g., deletePostingImmediately().

Let's verify the isAnswerPost flag is properly set:

✅ Verification successful

Method name is appropriate, flag usage is correct

The isAnswerPost flag is properly declared and used in the directive. The current method name deletePostingWithoutTimeout is actually more precise than the suggested alternative as it clearly indicates its relationship with the timeout-based deletion mechanism in the class. The flag's usage is consistent with the codebase's pattern of distinguishing between answer posts and regular posts, as seen in the MetisService calls.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for isAnswerPost assignments
rg "this\.isAnswerPost\s*=" -A 3

Length of output: 640


Script:

#!/bin/bash
# Search for isAnswerPost declarations and usages in the directive file
rg "isAnswerPost" src/main/webapp/app/shared/metis/posting.directive.ts -A 3

# Search for PostingType.ANSWER usage to understand the type check pattern
rg "PostingType\.ANSWER" -A 3

Length of output: 10205


Script:

#!/bin/bash
# Let's check the posting directive file to understand how isAnswerPost is initialized
ast-grep --pattern 'class $_ {
  $$$
  posting: $_
  $$$
}'  src/main/webapp/app/shared/metis/posting.directive.ts

Length of output: 115


Script:

#!/bin/bash
# Let's check the entire posting directive file content
cat src/main/webapp/app/shared/metis/posting.directive.ts

Length of output: 4118


45-45: LGTM! Verify component cleanup behavior.

The immediate deletion in ngOnDestroy correctly addresses the issue of aborted deletions when navigating away.

Let's verify there are no other cleanup operations that might interfere:

✅ Verification successful

LGTM! Cleanup behavior is safe and correct.

The deletion cleanup in ngOnDestroy is properly implemented:

  • Clears the deleteTimer timeout if it exists
  • Immediately executes deletePostingWithoutTimeout() to ensure deletion is not aborted
  • The deletePostingWithoutTimeout() method correctly handles both answer posts and regular posts via the appropriate service methods
  • No other cleanup operations interfere with the deletion process
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other ngOnDestroy implementations in related components
ast-grep --pattern 'ngOnDestroy() {
  $$$
}'

Length of output: 46


Script:

#!/bin/bash
# Search for ngOnDestroy implementations with ripgrep for better coverage
rg "ngOnDestroy\(\)" -A 5 --type ts

# Also search for any cleanup related to posting deletion
rg "deletePosting|deleteTimer" --type ts

Length of output: 103803


Script:

#!/bin/bash
# Search for deletePosting and deleteTimer usage in the posting directive
rg "deletePosting|deleteTimer" src/main/webapp/app/shared/metis/posting.directive.ts -A 5

Length of output: 1806

@@ -42,6 +42,7 @@ export abstract class PostingDirective<T extends Posting> implements OnInit, OnD
ngOnDestroy(): void {
if (this.deleteTimer !== undefined) {
clearTimeout(this.deleteTimer);
this.deletePostingWithoutTimeout();
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Based on the analysis of the test files and implementation, I can now generate the final response:

Additional test coverage needed for deletion scenarios

The current test coverage is insufficient for the deletion scenarios. While there are tests for the UI components and basic deletion functionality, the following scenarios are not covered:

  • The deletePostingWithoutTimeout method implementation is not tested
  • No tests for deletion during navigation (ngOnDestroy)
  • No tests for the timeout-based deletion scenario
  • No tests verifying the cleanup of delete intervals

Please add test cases for:

  1. posting.directive.spec.ts:
    • Test deletePostingWithoutTimeout for both regular posts and answer posts
    • Test cleanup of intervals in ngOnDestroy
    • Test the timeout-based deletion with proper interval cleanup
    • Test the deletion timer functionality
🔗 Analysis chain

Verify test coverage for the deletion scenarios.

While the implementation looks good, please ensure there are tests covering:

  1. Deletion during navigation away
  2. Deletion after timeout
  3. Both answer posts and regular posts

Let's check the test coverage:

Also applies to: 69-69, 132-138

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for related test files and their content
fd "posting.directive.spec.ts" | xargs rg "deletePost|ngOnDestroy"

Length of output: 274


Script:

#!/bin/bash
# Let's get more context around the test file content
fd "posting.directive.spec.ts" | xargs cat

Length of output: 4484


Script:

#!/bin/bash
# Let's also check for any other test files that might be testing this functionality
rg -l "deletePosting" --type ts

Length of output: 462


Script:

#!/bin/bash
# Let's check the implementation to understand what scenarios need to be tested
ast-grep --pattern 'deletePostingWithoutTimeout() {
  $$$
}'

Length of output: 62


Script:

#!/bin/bash
# Let's check the implementation with a different pattern to understand the deletion scenarios
ast-grep --pattern 'class $_ {
  $$$
  deletePostingWithoutTimeout$_$_ {
    $$$
  }
  $$$
}'

Length of output: 219


Script:

#!/bin/bash
# Let's also check for ngOnDestroy implementation
ast-grep --pattern 'ngOnDestroy() {
  $$$
}'

Length of output: 46


Script:

#!/bin/bash
# Let's check the test coverage for the reactions bar components
fd "reactions-bar.*spec.ts" | xargs rg "deletePosting|ngOnDestroy"

Length of output: 68


Script:

#!/bin/bash
# Let's try to find the implementation details with ripgrep
rg -A 5 "deletePostingWithoutTimeout" --type ts

Length of output: 1685


Script:

#!/bin/bash
# Let's check the content of the reactions bar test files directly
fd "reactions-bar.*spec.ts" | xargs cat

Length of output: 30797


Script:

#!/bin/bash
# Let's also check for timeout-related code
rg "setTimeout.*delete" --type ts

Length of output: 35

@badkeyy badkeyy marked this pull request as draft November 27, 2024 15:39
@badkeyy badkeyy marked this pull request as ready for review November 27, 2024 15:43
Copy link

github-actions bot commented Dec 7, 2024

There hasn't been any activity on this pull request recently. Therefore, this pull request has been automatically marked as stale and will be closed if no further activity occurs within seven days. Thank you for your contributions.

@badkeyy
Copy link
Contributor Author

badkeyy commented Dec 8, 2024

Please unstale

@github-actions github-actions bot removed the stale label Dec 8, 2024
Copy link

There hasn't been any activity on this pull request recently. Therefore, this pull request has been automatically marked as stale and will be closed if no further activity occurs within seven days. Thank you for your contributions.

@github-actions github-actions bot added the stale label Dec 15, 2024
@badkeyy
Copy link
Contributor Author

badkeyy commented Dec 16, 2024

Please unstale

@github-actions github-actions bot removed the stale label Dec 18, 2024
@badkeyy badkeyy requested a review from a team as a code owner December 23, 2024 13:54
@badkeyy
Copy link
Contributor Author

badkeyy commented Dec 23, 2024

Continued in: #10073

@badkeyy badkeyy closed this Dec 23, 2024
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!)
Projects
Status: Ready For Review
Development

Successfully merging this pull request may close these issues.

3 participants