| | |
| | | }); |
| | | } |
| | | |
| | | int start = cacheIndex(messageId, result); |
| | | /*int start = cacheIndex(messageId, result); |
| | | // start = start == 0 ? start : start + 1;// 空消息则表示首页,消息索引的后一条为起始 |
| | | int end = start + pageSize; |
| | | |
| | |
| | | |
| | | List<OnlineChatMessage> list = result.subList(start, end); |
| | | |
| | | return list; |
| | | return list;*/ |
| | | |
| | | // 4. 计算分页起始位置 |
| | | int start = cacheIndex(messageId, result); |
| | | int end = Math.min(start + pageSize, result.size()); |
| | | |
| | | // 5. 安全截取 |
| | | return start >= end ? new LinkedList<>() : result.subList(start, end); |
| | | } |
| | | |
| | | /** |
| | |
| | | index = i; |
| | | } |
| | | } |
| | | if (index == -1) { |
| | | /*if (index == -1) { |
| | | throw new BusinessException("参数异常,消息获取失败"); |
| | | } |
| | | return index + 1; |
| | | return index + 1;*/ |
| | | // 修复1:没找到消息,返回0(首页),不抛异常 |
| | | if (index == -1) { |
| | | return 0; |
| | | } |
| | | // 修复2:最后一条消息,返回列表长度,不越界 |
| | | return Math.min(index + 1, list.size()); |
| | | } |
| | | |
| | | @Override |