fix: 调整videoChat中获取房间人员的逻辑

This commit is contained in:
乾乾
2025-10-20 20:32:32 +08:00
parent 2c774d00ec
commit 9c3ff08350
2 changed files with 13 additions and 5 deletions

View File

@@ -110,16 +110,24 @@ public class OnlineService {
* @return 返回在线成员的uid
*/
public List<Long> getGroupOnlineMembers(@PathVariable @NotNull Long roomId) {
// 1. 构建缓存键
CacheKey cacheKey = PresenceCacheKeyBuilder.onlineGroupMembersKey(roomId);
return getGroupMembers(roomId, true);
}
// 2. 获取总在线人数
public List<Long> getGroupMembers(@RequestBody Long roomId) {
return getGroupMembers(roomId, false);
}
public List<Long> getGroupMembers(@PathVariable @NotNull Long roomId, boolean onlineOnly) {
// 1. 根据查询类型构建缓存键
CacheKey cacheKey = onlineOnly ? PresenceCacheKeyBuilder.onlineGroupMembersKey(roomId) : PresenceCacheKeyBuilder.groupMembersKey(roomId);
// 2. 获取集合大小
Long total = cachePlusOps.sSize(cacheKey.getKey());
if (total == null || total == 0) {
return new ArrayList<>();
}
// 4. 查询在线成员
// 3. 查询成员
return cachePlusOps.sMembers(cacheKey).stream().map(obj -> Long.parseLong(obj.toString())).collect(Collectors.toList());
}
}

View File

@@ -169,7 +169,7 @@ public class VideoChatService {
* @param roomId 房间id
*/
public List<Long> getOnlineUidList(Long roomId) {
return onlineService.getGroupOnlineMembers(roomId);
return onlineService.getGroupMembers(roomId);
}
/**