zhibo/live-streaming/test-view-history.md
xiao12feng8 a619bb1750 修复:首页标签分类+我的挚友处理+历史记录
优化:缘池界面+消息搜索界面
2026-01-05 16:47:07 +08:00

102 lines
2.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 观看历史功能测试指南
## 功能说明
观看历史功能允许用户查看自己观看过的直播间、作品等内容,并保存到后台。
## 实现内容
### 1. 后台实现
#### 数据存储 (`live-streaming/server/store/viewHistoryStore.js`)
- 记录用户观看历史
- 支持按类型过滤room/work/profile
- 自动更新已存在的记录
- 支持分页查询
#### API路由 (`live-streaming/server/routes/viewHistory.js`)
- `POST /api/front/activity/record-view` - 记录观看历史
- `GET /api/front/activity/view-history` - 获取观看历史
- `DELETE /api/front/activity/view-history` - 清除观看历史
- `DELETE /api/front/activity/view-history/:id` - 删除单条记录
### 2. Android端实现
#### RoomDetailActivity
- `recordWatchHistory()` - 进入直播间时记录观看历史
- `updateWatchHistoryWithRoomInfo()` - 房间信息加载后更新详细信息
#### MyRecordsActivity
- 已支持显示观看历史("观看历史"标签页)
- 支持点击跳转到对应的直播间/作品
## 测试步骤
### 1. 启动后台服务
```bash
cd live-streaming
npm install
npm start
```
后台服务将在 http://localhost:3001 启动
### 2. 测试API使用Postman或curl
#### 记录观看历史
```bash
curl -X POST http://localhost:3001/api/front/activity/record-view \
-H "Content-Type: application/json" \
-H "Authorization: 1" \
-d '{
"targetType": "room",
"targetId": "test-room-id",
"targetTitle": "测试直播间",
"coverImage": "https://example.com/cover.jpg",
"streamerName": "测试主播",
"viewDuration": 120
}'
```
#### 获取观看历史
```bash
curl -X GET "http://localhost:3001/api/front/activity/view-history?page=1&pageSize=20" \
-H "Authorization: 1"
```
#### 清除观看历史
```bash
curl -X DELETE "http://localhost:3001/api/front/activity/view-history" \
-H "Authorization: 1"
```
### 3. Android端测试
1. 确保Android应用已连接到后台服务
2. 登录应用
3. 进入任意直播间
4. 观看历史会自动记录
5. 返回首页,进入"我的" -> "我的记录"
6. 切换到"观看历史"标签页
7. 应该能看到刚才观看的直播间
## 数据存储位置
观看历史数据保存在:`live-streaming/data/viewHistory.json`
## 注意事项
1. 用户必须登录才能记录观看历史
2. 同一用户观看同一内容会更新记录而不是创建新记录
3. 观看历史按更新时间倒序排列
4. 支持分页加载默认每页20条
## 后续优化建议
1. 添加观看时长统计
2. 支持删除单条观看历史
3. 添加观看历史的时间筛选
4. 支持导出观看历史
5. 添加隐私设置(是否记录观看历史)