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 unread message marker in conversation #10018

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

asliayk
Copy link
Contributor

@asliayk asliayk commented Dec 14, 2024

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.

Motivation and Context

Description

  • Added an unread marker to indicate where unread messages start in a conversation.
  • Fixed the issue where a "Deleted" label appeared incorrectly by ensuring the authorRole is properly assigned.

Steps for Testing

Prerequisites:

  • 2 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 to the second user, or send a message in a channel that includes the second user.
  4. Edit the message and verify that no "Deleted" label appears in the user role section of the message header.
  5. Log in to Artemis as the second user.
  6. Navigate to the Communication section to read the new message.
  7. Notice the unread message marker at the top of the first unread message in that 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

Class/File Line Coverage Confirmation (assert/expect)
conversation-messages.component.ts 94.46% ✅ ❌
metis.service.ts 86.73% ✅ ❌

Screenshots

unread message marker
image
unread message marker (consecutive view)
image

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced visual indicators for unread messages in conversation threads.
    • Added functionality to track and display the first unread message.
  • Bug Fixes

    • Enhanced handling of post and answer updates to consistently manage author roles.
  • Tests

    • Expanded test coverage for unread message handling and post grouping in the conversation messages component.
  • Style

    • Updated styles for the unread message marker and adjusted layout in the post header component.

@asliayk asliayk added tests client Pull requests that update TypeScript code. (Added Automatically!) small component:Communication labels Dec 14, 2024
@asliayk asliayk self-assigned this Dec 14, 2024
@asliayk asliayk requested a review from a team as a code owner December 14, 2024 09:27
Copy link

coderabbitai bot commented Dec 14, 2024

Walkthrough

The pull request introduces enhancements to the conversation messages component, focusing on improving the visibility of unread messages within a channel. The changes span multiple files, including the component's HTML, TypeScript, and SCSS files. A new mechanism is implemented to identify and visually mark the first unread message in a conversation thread. Additionally, the Metis service is updated to preserve the author's role during post updates, and minor styling adjustments are made to the post header component.

Changes

File Change Summary
...conversation-messages.component.html Added conditional rendering for unread message marker with positioning and styling
...conversation-messages.component.scss Introduced .unread-marker and .unread-text CSS classes for styling unread message indicators
...conversation-messages.component.ts Added unreadCount property and isFirstUnreadMarker() method to track and identify first unread messages
...metis.service.ts Updated updatePost and updateAnswerPost methods to preserve authorRole during updates
...post-header.component.html Added inline style for top padding in the header div
...conversation-messages.component.spec.ts Enhanced tests for unread markers and post grouping functionality

Assessment against linked issues

Objective Addressed Explanation
Indicator for unread messages [#9947]
Prevent "Deleted" label after message edit [#9987] The changes do not address the issue of the "Deleted" label appearing after a message edit.

Possibly related PRs

Suggested labels

bugfix, ready to merge

Suggested reviewers

  • HawKhiem
  • SimonEntholzer
  • krusche
  • eceeeren
  • ahbitaqu

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. This feature will be included in our Pro Plan when released.


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

🧹 Outside diff range and nitpick comments (2)
src/main/webapp/app/overview/course-conversations/layout/conversation-messages/conversation-messages.component.scss (1)

116-137: Consider extracting magic numbers into CSS variables for better maintainability.

The styling looks good, but we can improve maintainability by extracting magic numbers into CSS variables.

 .unread-marker {
     position: absolute;
     left: 0;
     right: 0;
-    min-height: 0.09rem;
+    --unread-marker-height: 0.09rem;
+    --unread-text-offset: 0.6rem;
+    min-height: var(--unread-marker-height);
     background-color: var(--bs-danger);
     z-index: 1;

     .unread-text {
         position: absolute;
-        top: -0.6rem;
+        top: calc(-1 * var(--unread-text-offset));
         left: 95%;
         transform: translateX(-50%);
         background-color: var(--bs-danger);
         color: var(--bs-white);
-        font-size: 0.6rem;
+        font-size: var(--unread-text-offset);
         font-weight: bold;
         padding: 0.1rem 0.3rem;
         border-radius: 0.2rem;
         z-index: 2;
     }
 }
src/main/webapp/app/overview/course-conversations/layout/conversation-messages/conversation-messages.component.ts (1)

154-187: Consider improving readability of the unread marker logic.

The core logic for determining the first unread message is correct and handles edge cases well. However, consider these improvements for better maintainability:

  1. Break down the method into smaller, focused functions
  2. Add more descriptive comments explaining the algorithm
  3. Use more descriptive variable names (e.g., remainingUnread could be remainingUnreadMessages)

Example refactor:

-    isFirstUnreadMarker(post: Post, group: PostGroup): boolean {
-        let remainingUnread = this.unreadCount;
-        let firstUnreadFound = false;
+    isFirstUnreadMarker(targetPost: Post, targetGroup: PostGroup): boolean {
+        const groupIndex = this.findGroupIndex(targetGroup);
+        if (groupIndex === -1) return false;
+        
+        return this.isFirstUnreadInGroup(targetPost, groupIndex);
+    }
+
+    private findGroupIndex(group: PostGroup): number {
+        return this.groupedPosts.findIndex((g) => g === group);
+    }
+
+    private isFirstUnreadInGroup(targetPost: Post, targetGroupIndex: number): boolean {
+        let remainingUnreadMessages = this.unreadCount;
+        
+        // Process groups from newest to oldest
+        for (let i = this.groupedPosts.length - 1; i >= 0; i--) {
+            const currentGroup = this.groupedPosts[i];
+            
+            if (i > targetGroupIndex) {
+                // Subtract messages from newer groups
+                remainingUnreadMessages -= currentGroup.posts.length;
+            } else if (i === targetGroupIndex) {
+                // Check if this post is at the unread boundary
+                const postIndex = currentGroup.posts.indexOf(targetPost);
+                return postIndex === currentGroup.posts.length - remainingUnreadMessages;
+            } else {
+                // Post is in an older group
+                return false;
+            }
+        }
+        
+        return false;
+    }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fafe68c and 58a30aa.

📒 Files selected for processing (6)
  • src/main/webapp/app/overview/course-conversations/layout/conversation-messages/conversation-messages.component.html (1 hunks)
  • src/main/webapp/app/overview/course-conversations/layout/conversation-messages/conversation-messages.component.scss (1 hunks)
  • src/main/webapp/app/overview/course-conversations/layout/conversation-messages/conversation-messages.component.ts (2 hunks)
  • src/main/webapp/app/shared/metis/metis.service.ts (1 hunks)
  • src/main/webapp/app/shared/metis/posting-header/post-header/post-header.component.html (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/shared/metis/posting-header/post-header/post-header.component.html
🧰 Additional context used
📓 Path-based instructions (4)
src/main/webapp/app/overview/course-conversations/layout/conversation-messages/conversation-messages.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/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/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/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

🔇 Additional comments (6)
src/test/javascript/spec/component/overview/course-conversations/layout/conversation-messages/conversation-messages.component.spec.ts (3)

32-35: LGTM! Clean interface definition.

The PostGroup interface is well-structured and properly typed.


277-295: LGTM! Comprehensive test coverage for unread marker identification.

The test case thoroughly verifies the logic for identifying the first unread marker in different scenarios.


297-325: LGTM! Well-structured test cases for marker rendering.

The test cases effectively verify both the presence and absence of the unread marker based on the component's state.

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

62-62: LGTM: Property declaration follows Angular guidelines.

The unreadCount property is correctly typed and initialized.


149-149: LGTM: Safe assignment of unread count.

The code safely handles potential undefined values using optional chaining and provides a fallback to 0.

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

258-258: LGTM: Fix for "Deleted" label persistence.

The code correctly preserves the authorRole during post updates, fixing the issue where the "Deleted" label persisted until page refresh.

coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 14, 2024
@asliayk asliayk temporarily deployed to artemis-test5.artemis.cit.tum.de December 14, 2024 09:48 — with GitHub Actions Inactive
@asliayk asliayk marked this pull request as draft December 14, 2024 10:00
coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 14, 2024
@asliayk
Copy link
Contributor Author

asliayk commented Dec 14, 2024

Tested on TS3. works great. However the unread message marker is kind of blocked by the header. Could you change this also, it looks a bit odd

Screenshot 2024-12-14 135934

Thank you for noticing this :) I have removed the unread marker completely if the first unread message of the conversation is also the very first message of that conversation. Since all the content is new to the user, there is no need to separate old and new content with a marker.

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 TS2,
when answering in the post, the marker would move step by step down. Is this intended behaviour?
Bildschirmfoto 2024-12-14 um 23 35 51
Bildschirmfoto 2024-12-14 um 23 35 55
Bildschirmfoto 2024-12-14 um 23 36 04

Copy link

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

Feature works mostly as described. When user has the chat open and new messages come in, red line does not appear (I assume this is desired behavior)

  1. When the unread messages are under a new user in the chat (meaning the User is shown before the chats, no red line is shown.
    image
    Here, all messages sent by user 4 are unread messages, but there is no red line shown. Is this desired behavior? Suggestion would be to show the line directly between the user and the first unread message

Copy link
Contributor

@ole-ve ole-ve left a comment

Choose a reason for hiding this comment

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

Code looks good, added a suggestion for readability.

/**
* Determines whether a post is the "first unread message" in the conversation.
*/
isFirstUnreadMarker(post: Post, group: PostGroup): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this method is quite hard to read. What about sth like:

isFirstUnreadMarker(post: Post, group: PostGroup): boolean {
    const groupIndex = this.groupedPosts.findIndex((g) => g === group);

    if (groupIndex === -1) {
        return false;
    }

    let remainingUnread = this.unreadCount;

    for (let i = this.groupedPosts.length - 1; i >= 0; i--) {
        const currentGroup = this.groupedPosts[i];

        if (i > groupIndex) {
            remainingUnread -= currentGroup.posts.length;
            continue;
        }

        if (i === groupIndex) {
            const postIndexInGroup = currentGroup.posts.indexOf(post);

            if (postIndexInGroup === currentGroup.posts.length - remainingUnread) {
                return !(groupIndex === 0 && postIndexInGroup === 0);
            }

            remainingUnread--;
            return false;
        }

        return false;
    }

    return false;
}

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]
Nice feature! I found some issues though:

  1. When reading messages and changing the channel, the channel shows those messages to be unread again.
Screen.Recording.2024-12-17.171307.mp4
  1. The Marker is not attached to the messages. When writing a message the position of the marker stays fixed even though the message has gone up (See @sachmii 's comment)

  2. The marker behaves oddly when writing in an empty channel

Screen.Recording.2024-12-17.171622.mp4
  1. In Message threads, the replies are not rendered. It shows that the amout of replies is increasing, but those messages only appear once the page is refreshed.
Screen.Recording.2024-12-17.171515.mp4

@asliayk asliayk marked this pull request as draft December 18, 2024 14:42
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!) component:Communication feature small tests
Projects
Status: Ready For Review
Status: In Progress
9 participants