Skip to content

feat: 为站内信收件箱添加未读消息数接口#68

Open
gtn1024 wants to merge 1 commit intomasterfrom
getn/unread-count
Open

feat: 为站内信收件箱添加未读消息数接口#68
gtn1024 wants to merge 1 commit intomasterfrom
getn/unread-count

Conversation

@gtn1024
Copy link
Contributor

@gtn1024 gtn1024 commented Nov 12, 2025

No description provided.

@gtn1024 gtn1024 requested review from aruis and Copilot November 12, 2025 05:20
@gtn1024 gtn1024 self-assigned this Nov 12, 2025
@gtn1024 gtn1024 added the enhancement New feature or request label Nov 12, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a new API endpoint to retrieve the count of unread messages in a user's inbox. The feature enables clients to display unread message counts without fetching all messages.

  • Adds /inbox/unread_count GET endpoint to query unread message count for the current user
  • Includes comprehensive test coverage verifying the count updates correctly when messages are sent and read
  • Implements SQL query filtering on user ID, read status, and delete status

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
muyun-platform/src/main/java/net/ximatai/muyun/platform/controller/InboxController.java Adds getUnreadCount() method with necessary imports to support the unread message count API endpoint
muyun-boot/src/test/java/net/ximatai/muyun/test/plaform/TestMessage.java Extends existing message flow test to validate unread count returns 1 after sending and 0 after reading

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +51 to +62
public Map<String, Object> getUnreadCount() {
String userId = getUser().getId();

List<Map<String, Object>> result = getDB().query(
"SELECT COUNT(*) as count FROM %s.app_message_person WHERE id_at_auth_user__to = ? AND b_read = false AND b_delete = false"
.formatted(getSchemaName()),
userId
);

long count = result.isEmpty() ? 0 : ((Number) result.getFirst().get("count")).longValue();
return Map.of("count", count);
}
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

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

The return type and API design is inconsistent with the similar ReceiveController.unreadCount() method which returns long directly instead of wrapping it in a Map. Consider returning long directly to maintain consistency:

@GET
@Path("/unread_count")
@Operation(summary = "查询当前用户未读消息数量")
public long getUnreadCount() {
    String userId = getUser().getId();
    
    List<Map<String, Object>> result = getDB().query(
        "SELECT COUNT(*) as count FROM %s.app_message_person WHERE id_at_auth_user__to = ? AND b_read = false AND b_delete = false"
            .formatted(getSchemaName()),
        userId
    );
    
    return result.isEmpty() ? 0L : ((Number) result.getFirst().get("count")).longValue();
}

This would also simplify the test assertions to Assertions.assertEquals(1L, inboxCount); instead of Assertions.assertEquals(1, inboxCount.get("count"));

Copilot uses AI. Check for mistakes.
@aruis
Copy link
Collaborator

aruis commented Nov 24, 2025

可以考虑 提供 count 接口,然后通过参数过滤是要查询什么条件下的 count

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants