diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php index f832f477c..13b9d2ac6 100755 --- a/app/Http/Controllers/Api/DialogController.php +++ b/app/Http/Controllers/Api/DialogController.php @@ -484,6 +484,36 @@ class DialogController extends AbstractController 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. 获取未读消息数量 * diff --git a/resources/assets/js/store/actions.js b/resources/assets/js/store/actions.js index 4741e9c79..573423f12 100644 --- a/resources/assets/js/store/actions.js +++ b/resources/assets/js/store/actions.js @@ -2373,20 +2373,13 @@ export default { const id = $A.cloneJSON(state.wsReadWaitList); state.wsReadWaitList = []; // - dispatch("websocketSend", { - type: 'readMsg', - data: {id} + dispatch("call", { + url: 'dialog/msg/read', + data: { + id: id.join(",") + } }).catch(_ => { - // try again later - setTimeout(_ => { - dispatch("websocketSend", { - type: 'readMsg', - data: {id} - }).catch(_ => { - // or fail - state.wsReadWaitList.push(...id) - }); - }, 1000) + state.wsReadWaitList.push(...id) }); }, 50); },