mirror of
https://github.com/kuaifan/dootask.git
synced 2026-01-24 02:48:12 +00:00
perf: 优化消息已读
This commit is contained in:
parent
2693cf17ea
commit
4bef2f5287
@ -484,6 +484,36 @@ class DialogController extends AbstractController
|
|||||||
return Base::retSuccess('success', $msg);
|
return Base::retSuccess('success', $msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api {get} api/dialog/msg/read 11. 标记已读
|
||||||
|
*
|
||||||
|
* @apiDescription 需要token身份
|
||||||
|
* @apiVersion 1.0.0
|
||||||
|
* @apiGroup dialog
|
||||||
|
* @apiName msg__read
|
||||||
|
*
|
||||||
|
* @apiParam {Number} id 消息ID(组)
|
||||||
|
*
|
||||||
|
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
||||||
|
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||||
|
* @apiSuccess {Object} data 返回数据
|
||||||
|
*/
|
||||||
|
public function msg__read()
|
||||||
|
{
|
||||||
|
$user = User::auth();
|
||||||
|
//
|
||||||
|
$id = Request::input('id');
|
||||||
|
$ids = Base::arrayRetainInt(is_array($id) ? $id : Base::explodeInt($id));
|
||||||
|
//
|
||||||
|
WebSocketDialogMsg::whereIn('id', $ids)->chunkById(20, function($list) use ($user) {
|
||||||
|
/** @var WebSocketDialogMsg $item */
|
||||||
|
foreach ($list as $item) {
|
||||||
|
$item->readSuccess($user->userid);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return Base::retSuccess('success');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {get} api/dialog/msg/unread 11. 获取未读消息数量
|
* @api {get} api/dialog/msg/unread 11. 获取未读消息数量
|
||||||
*
|
*
|
||||||
|
|||||||
19
resources/assets/js/store/actions.js
vendored
19
resources/assets/js/store/actions.js
vendored
@ -2373,20 +2373,13 @@ export default {
|
|||||||
const id = $A.cloneJSON(state.wsReadWaitList);
|
const id = $A.cloneJSON(state.wsReadWaitList);
|
||||||
state.wsReadWaitList = [];
|
state.wsReadWaitList = [];
|
||||||
//
|
//
|
||||||
dispatch("websocketSend", {
|
dispatch("call", {
|
||||||
type: 'readMsg',
|
url: 'dialog/msg/read',
|
||||||
data: {id}
|
data: {
|
||||||
|
id: id.join(",")
|
||||||
|
}
|
||||||
}).catch(_ => {
|
}).catch(_ => {
|
||||||
// try again later
|
state.wsReadWaitList.push(...id)
|
||||||
setTimeout(_ => {
|
|
||||||
dispatch("websocketSend", {
|
|
||||||
type: 'readMsg',
|
|
||||||
data: {id}
|
|
||||||
}).catch(_ => {
|
|
||||||
// or fail
|
|
||||||
state.wsReadWaitList.push(...id)
|
|
||||||
});
|
|
||||||
}, 1000)
|
|
||||||
});
|
});
|
||||||
}, 50);
|
}, 50);
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user