diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php index b3fc0f9ea..23d708a42 100755 --- a/app/Http/Controllers/Api/DialogController.php +++ b/app/Http/Controllers/Api/DialogController.php @@ -1765,7 +1765,9 @@ class DialogController extends AbstractController * @apiParam {String} type 设待办对象 * - all: 会话全部成员(默认) * - user: 会话指定成员 - * @apiParam {Array} userids 会员ID组(type=user有效,格式: [userid1, userid2, userid3]) + * @apiParam {Array} userids 会员ID组 + * - type=user 有效,格式: [userid1, userid2, userid3] + * - 可通过 type=user 及 userids:[] 一起使用来清除所有人的待办 * * @apiSuccess {Number} ret 返回状态码(1正确、0错误) * @apiSuccess {String} msg 返回信息(错误描述) @@ -1773,26 +1775,24 @@ class DialogController extends AbstractController */ public function msg__todo() { + Base::checkClientVersion('0.37.18'); $user = User::auth(); // $msg_id = intval(Request::input("msg_id")); $type = trim(Request::input("type", "all")); $userids = Request::input('userids'); // - if ($type === 'user') { - if (empty($userids)) { - return Base::retError("选择指定成员"); - } - } else { - $userids = []; - } - // $msg = WebSocketDialogMsg::whereId($msg_id)->first(); if (empty($msg)) { return Base::retError("消息不存在或已被删除"); } - WebSocketDialog::checkDialog($msg->dialog_id); + $dialog = WebSocketDialog::checkDialog($msg->dialog_id); // + if ($type === 'all') { + $userids = $dialog->dialogUser->pluck('userid')->toArray(); + } else { + $userids = is_array($userids) ? $userids : []; + } return $msg->toggleTodoMsg($user->userid, $userids); } diff --git a/app/Models/WebSocketDialogMsg.php b/app/Models/WebSocketDialogMsg.php index d60db901c..9b1bb69c0 100644 --- a/app/Models/WebSocketDialogMsg.php +++ b/app/Models/WebSocketDialogMsg.php @@ -320,41 +320,54 @@ class WebSocketDialogMsg extends AbstractModel if (in_array($this->type, ['tag', 'todo', 'notice'])) { return Base::retError('此消息不支持设待办'); } - if ($this->todo && $this->todo != $sender) { - return Base::retError('仅支持设此待办人员【' . User::userid2nickname($this->todo) . '】取消'); - } - $before = $this->todo; - $this->todo = $before ? 0 : $sender; + $current = WebSocketDialogMsgTodo::whereMsgId($this->id)->pluck('userid')->toArray(); + $cancel = array_diff($current, $userids); + $setup = array_diff($userids, $current); + // + $this->todo = $setup || count($current) > count($cancel) ? $sender : 0; $this->save(); - $resData = [ + $upData = [ 'id' => $this->id, 'todo' => $this->todo, + 'dialog_id' => $this->dialog_id, ]; + $dialog = WebSocketDialog::find($this->dialog_id); + $dialog->pushMsg('update', $upData); // - $data = [ - 'update' => $resData + $retData = [ + 'add' => [], + 'update' => $upData ]; - $res = self::sendMsg(null, $this->dialog_id, 'todo', [ - 'action' => $this->todo ? 'add' : 'remove', - 'data' => [ - 'id' => $this->id, - 'type' => $this->type, - 'msg' => $this->quoteTextMsg(), - 'userids' => implode(",", $userids), - ] - ], $sender); - if (Base::isSuccess($res)) { - $data['add'] = $res['data']; - $dialog = WebSocketDialog::find($this->dialog_id); - $dialog->pushMsg('update', array_merge($resData, ['dialog_id' => $this->dialog_id])); - // - if ($this->todo) { + if ($cancel) { + $res = self::sendMsg(null, $this->dialog_id, 'todo', [ + 'action' => 'remove', + 'data' => [ + 'id' => $this->id, + 'type' => $this->type, + 'msg' => $this->quoteTextMsg(), + 'userids' => implode(",", $cancel), + ] + ], $sender); + if (Base::isSuccess($res)) { + $retData['add'][] = $res['data']; + WebSocketDialogMsgTodo::whereMsgId($this->id)->whereIn('userid', $cancel)->delete(); + } + } + if ($setup) { + $res = self::sendMsg(null, $this->dialog_id, 'todo', [ + 'action' => 'add', + 'data' => [ + 'id' => $this->id, + 'type' => $this->type, + 'msg' => $this->quoteTextMsg(), + 'userids' => implode(",", $setup), + ] + ], $sender); + if (Base::isSuccess($res)) { + $retData['add'][] = $res['data']; $useridList = $dialog->dialogUser->pluck('userid')->toArray(); - foreach ($useridList as $userid) { - if ($userids && !in_array($userid, $userids)) { - continue; - } - if (empty($userid)) { + foreach ($setup as $userid) { + if (!in_array($userid, $useridList)) { continue; } WebSocketDialogMsgTodo::createInstance([ @@ -363,15 +376,10 @@ class WebSocketDialogMsg extends AbstractModel 'userid' => $userid, ])->saveOrIgnore(); } - } else { - WebSocketDialogMsgTodo::whereMsgId($this->id)->delete(); } - } else { - $this->todo = $before; - $this->save(); } // - return Base::retSuccess($this->todo ? '设置成功' : '取消成功', $data); + return Base::retSuccess($this->todo ? '设置成功' : '取消成功', $retData); } /** diff --git a/resources/assets/js/pages/manage/components/DialogItem.vue b/resources/assets/js/pages/manage/components/DialogItem.vue index e6e1b9ab2..806375a3e 100644 --- a/resources/assets/js/pages/manage/components/DialogItem.vue +++ b/resources/assets/js/pages/manage/components/DialogItem.vue @@ -53,6 +53,7 @@ @on-reply-list="onReplyList" @on-error="onError" @on-emoji="onEmoji" + @on-other="onOther" @on-show-emoji-user="onShowEmojiUser"/> @@ -258,6 +259,10 @@ export default { this.dispatch("on-emoji", data) }, + onOther(data) { + this.dispatch("on-other", data) + }, + onShowEmojiUser(data) { this.dispatch("on-show-emoji-user", data) }, diff --git a/resources/assets/js/pages/manage/components/DialogView.vue b/resources/assets/js/pages/manage/components/DialogView.vue index 363a7069d..3220dc0e0 100644 --- a/resources/assets/js/pages/manage/components/DialogView.vue +++ b/resources/assets/js/pages/manage/components/DialogView.vue @@ -196,7 +196,10 @@ :placement="isRightMsg ? 'bottom-end' : 'bottom-start'">
-
{{ todoDoneList.length }}{{ $L('完成') }}
+
+ {{ todoDoneList.length }} + {{ $L('完成') }} +
-
{{ todoUndoneList.length }}{{ $L('待办') }}
+
+ {{ todoUndoneList.length }} + {{ $L('待办') }} + + +