turms-im / turms

🕊️ The world's most advanced open source instant messaging engine for 100K~10M concurrent users https://turms-im.github.io/docs
Apache License 2.0
1.68k stars 255 forks source link

MessageService.queryMessagesWithTotal批量获取消息总数时,只返回了一个 #1495

Open lovemianhuatang opened 1 week ago

lovemianhuatang commented 1 week ago

开启 turms.service.message.use-conversation-id=true 当前登录用户Id=10,我想获取与用户['11', '12', '13']每个会话的未读消息数量。但现在只返回了第一条消息的记录;

MessageService.queryMessagesWithTotal({
                fromIds: ['11', '12', '13'],
                areGroupMessages: false,
                maxCount: 1,
                descending: true,
});

实际响应:

[
    {
        "total": 24,
        "isGroupMessage": false,
        "fromId": "11",
        "messages": [
            {
                "id": "4071732935080833024",
                "text": "Hello Turms, My userId is 998",
                .........
            }
        ]
    }
]

预期响应:

[
    {
        "total": 24,
        "isGroupMessage": false,
        "fromId": "11",
        "messages": [
            {
                "id": "4071732935080833021",
                "text": "xxx",
                .........
            }
        ]
    },
    {
        "total": 10,
        "isGroupMessage": false,
        "fromId": "12",
        "messages": [
            {
                "id": "4071732935080833022",
                "text": "xxx",
                .........
            }
        ]
    },
    {
        "total": 6,
        "isGroupMessage": false,
        "fromId": "13",
        "messages": [
            {
                "id": "4071732935080833023",
                "text": "xxx",
                .........
            }
        ]
    }
]
JamesChenX commented 1 week ago

This is an expected behavior when you set maxCount: 1. Consider the performance of implementation between your expected behavior and the current behavior when querying messages in databases (for our cases, MongoDB), and the performance of Restrict message results to top N messages per group is unacceptable, especially since it's a frequently used method.

btw, we will support counting unread messages in another way, you can read https://github.com/turms-im/turms/issues/575 for details.

lovemianhuatang commented 1 week ago

好的,请问 #575 是在进行中吗?进展如何

JamesChenX commented 1 week ago

好的,请问 #575 是在进行中吗?进展如何

I will start developing and publish the feature in 2024/08 or 2024/09 when I am available. I will @ you once the new feature is published, and you can use queryMessagesWithTotal currently.