Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Communication: Fix an issue with unread message count #10245

Merged

Conversation

PaRangger
Copy link
Contributor

@PaRangger PaRangger commented Feb 2, 2025

Checklist

General

Server

Motivation and Context

Currently, when composing a message in a channel and quickly switching to another, the message is counted toward the unread message count in that channel. This occurs because the last_read column updates asynchronously, leading to a delay in the server's update process. The issue is particularly noticeable on test servers, where the update can take up to 30 seconds to complete.

Addresses #10035

Description

I changed the query that counts the posts to not include posts with user id equal to the queried user.

Steps for Testing

Prerequisites:

  • 1 Student/Tutor/Instructor
  1. Log in to Artemis
  2. Navigate to course
  3. Navigate to the communication tab
  4. Select a channel with zero unread messages
  5. Write many posts (the more the more likely to reproduce the issue)
  6. Quickly change to another channel
  7. Observe that the "unread" count is still at zero

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

Summary by CodeRabbit

  • Bug Fixes
    • Improved conversation filtering so that only messages from others are displayed.
    • Updated the unread message indicator to exclude your own posts, ensuring more accurate notifications.

@PaRangger PaRangger added server Pull requests that update Java code. (Added Automatically!) small communication Pull requests that affect the corresponding module labels Feb 2, 2025
@PaRangger PaRangger self-assigned this Feb 2, 2025
Copy link

github-actions bot commented Feb 2, 2025

⚠️ Unable to deploy to test servers ⚠️

The docker build needs to run through before deploying.

@github-actions github-actions bot added the deployment-error Added by deployment workflows if an error occured label Feb 2, 2025
@PaRangger PaRangger added deploy:artemis-test5 and removed deployment-error Added by deployment workflows if an error occured labels Feb 2, 2025
@PaRangger PaRangger temporarily deployed to artemis-test5.artemis.cit.tum.de February 2, 2025 10:24 — with GitHub Actions Inactive
@PaRangger PaRangger marked this pull request as ready for review February 2, 2025 11:54
@PaRangger PaRangger requested a review from a team as a code owner February 2, 2025 11:54
Copy link

coderabbitai bot commented Feb 2, 2025

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 PMD (7.8.0)
src/main/java/de/tum/cit/aet/artemis/communication/repository/conversation/ConversationRepository.java

[ERROR] Error at ruleset.xml:58:5
56|
57|
58|
^^^^^ Unable to find referenced rule BooleanInstantiation; perhaps the rule name is misspelled?

59|
60|
[WARN] Warning at ruleset.xml:66:5
64|
65|
66|
^^^^^ Use Rule name category/java/bestpractices.xml/DefaultLabelNotLastInSwitch instead of the deprecated Rule name category/java/bestpractices.xml/DefaultLabelNotLastInSwitchStmt. PMD 8.0.0 will remove support for this deprecated Rule name usage.

67|
68|
[ERROR] Error at ruleset.xml:71:5
69|
70|
71|
^^^^^ Unable to find referenced rule DontImportJavaLang; perhaps the rule name is misspelled?

72|
73|
[ERROR] Error at ruleset.xml:75:5
73|
74|
75|
^^^^^ Unable to find referenced rule DuplicateImports; perhaps the rule name is misspelled?

76|
77|
[ERROR] Error at ruleset.xml:78:5
76|
77|
78|
^^^^^ Unable to find referenced rule EmptyFinallyBlock; perhaps the rule name is misspelled?

79|
80|
[ERROR] Error at ruleset.xml:79:5
77|
78|
79|
^^^^^ Unable to find referenced rule EmptyIfStmt; perhaps the rule name is misspelled?

80|
81|
[ERROR] Error at ruleset.xml:81:5
79|
80|
81|
^^^^^ Unable to find referenced rule EmptyInitializer; perhaps the rule name is misspelled?

82|
83|
[ERROR] Error at ruleset.xml:82:5
80|
81|
82|
^^^^^ Unable to find referenced rule EmptyStatementBlock; perhaps the rule name is misspelled?

83|
84|
[ERROR] Error at ruleset.xml:83:5
81|
82|
83|
^^^^^ Unable to find referenced rule EmptyStatementNotInLoop; perhaps the rule name is misspelled?

84|
85|
[ERROR] Error at ruleset.xml:84:5
82|
83|
84|
^^^^^ Unable to find referenced rule EmptySwitchStatements; perhaps the rule name is misspelled?

85|
86|
[ERROR] Error at ruleset.xml:85:5
83|
84|
85|
^^^^^ Unable to find referenced rule EmptySynchronizedBlock; perhaps the rule name is misspelled?

86|
87|
[ERROR] Error at ruleset.xml:86:5
84|
85|
86|
^^^^^ Unable to find referenced rule EmptyTryBlock; perhaps the rule name is misspelled?

87|
88|
[ERROR] Error at ruleset.xml:87:5
85|
86|
87|
^^^^^ Unable to find referenced rule EmptyWhileStmt; perhaps the rule name is misspelled?

88|
89|
[ERROR] Error at ruleset.xml:90:5
88|
89|
90|
^^^^^ Unable to find referenced rule ExcessiveClassLength; perhaps the rule name is misspelled?

91|
92|
[ERROR] Error at ruleset.xml:91:5
89|
90|
91|
^^^^^ Unable to find referenced rule ExcessiveMethodLength; perhaps the rule name is misspelled?

92|
93|
[ERROR] Error at ruleset.xml:106:5
104|
105|
106|
^^^^^ Unable to find referenced rule ImportFromSamePackage; perhaps the rule name is misspelled?

107|
108|
[ERROR] Error at ruleset.xml:119:5
117|
118|
119|
^^^^^ Unable to find referenced rule MissingBreakInSwitch; perhaps the rule name is misspelled?

120|
121|
[WARN] Warning at ruleset.xml:124:5
122|
123|
124|
^^^^^ Use Rule name category/java/errorprone.xml/NonCaseLabelInSwitch instead of the deprecated Rule name category/java/errorprone.xml/NonCaseLabelInSwitchStatement. PMD 8.0.0 will remove support for this deprecated Rule name usage.

125|
126|
[ERROR] Error at ruleset.xml:134:9
132|
133| // It's okay to use short variable names in DTOs, e.g. "id" or "name"
134| ./de/tum/in/www1/artemis/web/rest/dto/.
^^^^^^^^^^^^^^^^ Unexpected element 'exclude-pattern' in rule ShortVariable

135|
136|
[ERROR] Error at ruleset.xml:137:5
135|
136|
137|
^^^^^ Unable to find referenced rule SimplifyBooleanAssertion; perhaps the rule name is misspelled?

138|
139|
[WARN] Warning at ruleset.xml:184:5
182|
183|
184|
^^^^^ Use Rule name category/ecmascript/errorprone.xml/InaccurateNumericLiteral instead of the deprecated Rule name category/ecmascript/errorprone.xml/InnaccurateNumericLiteral. PMD 8.0.0 will remove support for this deprecated Rule name usage.

185|
186|
[ERROR] Cannot load ruleset category/vm/bestpractices.xml: Cannot resolve rule/ruleset reference 'category/vm/bestpractices.xml'. Make sure the resource is a valid file or URL and is on the CLASSPATH. Use --debug (or a fine log level) to see the current classpath.
[WARN] Progressbar rendering conflicts with reporting to STDOUT. No progressbar will be shown. Try running with argument -r to output the report to a file instead.

Walkthrough

The repository interface for conversation queries has been updated in the ConversationRepository. Both the getUserInformationForConversations and userHasUnreadMessageInCourse methods now include an additional JPQL condition to exclude posts authored by the user specified by :userId. This adjustment refines the query logic by ensuring that a user’s own posts are not returned in conversation details or counted as unread messages. The method signatures remain unchanged.

Changes

File Change Summary
src/.../ConversationRepository.java Updated JPQL queries in getUserInformationForConversations and userHasUnreadMessageInCourse to exclude posts authored by the user (p.author.id <> :userId).

Suggested labels

client

Suggested reviewers

  • FelberMartin
  • HawKhiem
  • sachmii
  • krusche
✨ 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: 1

🔭 Outside diff range comments (1)
src/main/java/de/tum/cit/aet/artemis/communication/repository/conversation/ConversationRepository.java (1)

41-60: Test Coverage for Modified Query Logic Appears Insufficient

  • No dedicated test files (e.g., ConversationRepositoryTest or ConversationRepositoryIT) were found covering the modified query.
  • The repository methods are only indirectly invoked via the ConversationService, leaving a gap in directly verifying that own messages are being excluded.
  • It is recommended to add explicit tests to validate the query logic change.
🔗 Analysis chain

Verify test coverage for the modified queries.

The query logic has been modified to exclude own messages. Let's verify the test coverage for these changes.

Run the following script to check for test files:

Also applies to: 80-93

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check test coverage for modified repository methods

# Search for test files
echo "Searching for test files..."
fd -e java "ConversationRepository(Test|IT).java"

# Search for test methods
echo -e "\nSearching for test methods..."
rg -A 5 "getUserInformationForConversations|userHasUnreadMessageInCourse" --type java

Length of output: 4075

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 45efb7f and b953103.

📒 Files selected for processing (1)
  • src/main/java/de/tum/cit/aet/artemis/communication/repository/conversation/ConversationRepository.java (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/main/java/de/tum/cit/aet/artemis/communication/repository/conversation/ConversationRepository.java (1)

Pattern src/main/java/**/*.java: naming:CamelCase; principles:{single_responsibility,small_methods,no_duplication}; db:{perf_queries,datetime_not_timestamp}; rest:{stateless,singleton,delegate_logic,http_only,minimal_dtos}; dtos:{java_records,no_entities,min_data,single_resp}; di:constructor_injection; kiss:simple_code; file_handling:os_indep_paths; practices:{least_access,avoid_transactions,code_reuse,static_member_ref,prefer_primitives}; sql:{param_annotation,uppercase,avoid_subqueries};java:avoid_star_imports

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (3)
src/main/java/de/tum/cit/aet/artemis/communication/repository/conversation/ConversationRepository.java (3)

23-25: LGTM! Repository interface structure follows best practices.

The interface is properly structured with correct annotations and follows Java coding guidelines.


55-55: LGTM! Query modification correctly excludes own messages.

The added condition p.author.id <> :userId properly addresses the issue of counting own messages towards unread amount while maintaining query performance.


87-87: LGTM! Query modification correctly excludes own messages from unread count.

The added condition p.author.id <> :userId properly addresses the issue while maintaining query performance and following SQL guidelines.

Copy link

github-actions bot commented Feb 2, 2025

⚠️ Unable to deploy to test servers ⚠️

Testserver "artemis-test4.artemis.cit.tum.de" is already in use by PR #10118.

@github-actions github-actions bot added the deployment-error Added by deployment workflows if an error occured label Feb 2, 2025
@asliayk asliayk added deploy:artemis-test5 and removed deployment-error Added by deployment workflows if an error occured labels Feb 2, 2025
@asliayk asliayk temporarily deployed to artemis-test5.artemis.cit.tum.de February 2, 2025 15:00 — with GitHub Actions Inactive
Copy link
Contributor

@asliayk asliayk left a comment

Choose a reason for hiding this comment

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

great job! I sent messages on random channels and switched between them, and I no longer encounter this issue as before.

Copy link

@HawKhiem HawKhiem 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 TS4. Works as expected

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 TS4. Works as expected, could not reproduce the original bug

@krusche krusche modified the milestones: 7.9.2, 7.9.1 Feb 2, 2025
@krusche krusche changed the title Communication: Fix issue that counts own messages towards unread amount Communication: Fix an issue with unread message count Feb 2, 2025
@krusche krusche merged commit b9c5f59 into develop Feb 2, 2025
131 of 139 checks passed
@krusche krusche deleted the bugfix/communication/stop-counting-own-messages-as-unread branch February 2, 2025 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix communication Pull requests that affect the corresponding module ready for review server Pull requests that update Java code. (Added Automatically!) small
Projects
Status: Merged
Development

Successfully merging this pull request may close these issues.

5 participants