撤回消息优化
This commit is contained in:
parent
35bd038802
commit
02eb386155
@ -8,9 +8,7 @@ use App\Models\User;
|
||||
use App\Models\WebSocketDialog;
|
||||
use App\Models\WebSocketDialogMsg;
|
||||
use App\Models\WebSocketDialogMsgRead;
|
||||
use App\Models\WebSocketDialogUser;
|
||||
use App\Module\Base;
|
||||
use Carbon\Carbon;
|
||||
use Request;
|
||||
use Response;
|
||||
|
||||
@ -417,8 +415,18 @@ class DialogController extends AbstractController
|
||||
}
|
||||
|
||||
/**
|
||||
* 聊天消息撤回
|
||||
* @return array
|
||||
* @api {get} api/dialog/msg/withdraw 11. 聊天消息撤回
|
||||
*
|
||||
* @apiDescription 需要token身份
|
||||
* @apiVersion 1.0.0
|
||||
* @apiGroup dialog
|
||||
* @apiName msg__withdraw
|
||||
*
|
||||
* @apiParam {Number} msg_id 消息ID
|
||||
*
|
||||
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
||||
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||
* @apiSuccess {Object} data 返回数据
|
||||
*/
|
||||
public function msg__withdraw()
|
||||
{
|
||||
@ -426,34 +434,9 @@ class DialogController extends AbstractController
|
||||
$msg_id = intval(Request::input("msg_id"));
|
||||
$msg = WebSocketDialogMsg::whereId($msg_id)->whereUserid($user->userid)->first();
|
||||
if (empty($msg)) {
|
||||
return Base::retError("此消息不可撤回");
|
||||
return Base::retError("消息不存在或已被删除");
|
||||
}
|
||||
$send_dt = Carbon::parse($msg->created_at)->addMinutes(5);
|
||||
if ($send_dt->lt(Carbon::now()))
|
||||
return Base::retError("已超过5分钟,此消息不能撤回");
|
||||
|
||||
|
||||
// 删除文件、图片
|
||||
if ($msg->type == WebSocketDialogMsg::MSG_TYPE_FILE) {
|
||||
if (is_array($msg->msg)) {
|
||||
// 删除本体
|
||||
if (!empty($msg->msg["file"]))
|
||||
@unlink($msg->msg["file"]);
|
||||
// 删除缩略图
|
||||
if (!empty($msg->msg["thumb"]))
|
||||
@unlink($msg->msg["thumb"]);
|
||||
}
|
||||
}
|
||||
|
||||
// 直接删除消息
|
||||
$msg->delete();
|
||||
|
||||
/* 原始需求:消息直接删除,无需提示 */
|
||||
// 发送撤回指令
|
||||
// WebSocketDialogMsg::sendMsg($msg->dialog_id, 'withdraw', [
|
||||
// "msg_id" => $msg->id, // 被撤回的消息Id
|
||||
// ], $user->userid);
|
||||
|
||||
$msg->deleteMsg();
|
||||
return Base::retSuccess("success");
|
||||
}
|
||||
}
|
||||
|
@ -127,6 +127,35 @@ class WebSocketDialogMsg extends AbstractModel
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除消息
|
||||
* @return void
|
||||
*/
|
||||
public function deleteMsg()
|
||||
{
|
||||
$send_dt = Carbon::parse($this->created_at)->addMinutes(5);
|
||||
if ($send_dt->lt(Carbon::now())) {
|
||||
throw new ApiException('已超过5分钟,此消息不能撤回');
|
||||
}
|
||||
$this->delete();
|
||||
//
|
||||
$dialog = WebSocketDialog::find($this->dialog_id);
|
||||
if ($dialog) {
|
||||
$userids = $dialog->dialogUser->pluck('userid')->toArray();
|
||||
PushTask::push([
|
||||
'userid' => $userids,
|
||||
'msg' => [
|
||||
'type' => 'dialog',
|
||||
'mode' => 'delete',
|
||||
'data' => [
|
||||
'id' => $this->id,
|
||||
'dialog_id' => $this->dialog_id
|
||||
],
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
* @param int $dialog_id 会话ID(即 聊天室ID)
|
||||
|
60
resources/assets/js/store/actions.js
vendored
60
resources/assets/js/store/actions.js
vendored
@ -1833,6 +1833,23 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 忘记消息数据
|
||||
* @param state
|
||||
* @param msg_id
|
||||
*/
|
||||
forgetDialogMsg({state}, msg_id) {
|
||||
$A.execMainDispatch("forgetDialogMsg", msg_id)
|
||||
//
|
||||
let ids = $A.isArray(msg_id) ? msg_id : [msg_id];
|
||||
ids.some(id => {
|
||||
let index = state.dialogMsgs.findIndex(item => item.id == id);
|
||||
if (index > -1) {
|
||||
state.dialogMsgs.splice(index, 1);
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取会话消息
|
||||
* @param state
|
||||
@ -2032,24 +2049,33 @@ export default {
|
||||
(function (msg) {
|
||||
const {mode, data} = msg;
|
||||
const {dialog_id} = data;
|
||||
if (["add", "chat"].includes(mode) && !state.dialogMsgs.find(({id}) => id == data.id)) {
|
||||
// 新增任务消息数量
|
||||
dispatch("increaseTaskMsgNum", dialog_id);
|
||||
if (mode === "chat") {
|
||||
return;
|
||||
}
|
||||
let dialog = state.cacheDialogs.find(({id}) => id == data.dialog_id);
|
||||
// 更新对话列表
|
||||
if (dialog) {
|
||||
// 新增未读数
|
||||
dialog.unread++;
|
||||
}
|
||||
Store.set('dialogMsgPush', data);
|
||||
switch (mode) {
|
||||
case 'delete':
|
||||
// 删除消息
|
||||
dispatch("forgetDialogMsg", data.id)
|
||||
break;
|
||||
case 'add':
|
||||
case 'chat':
|
||||
if (!state.dialogMsgs.find(({id}) => id == data.id)) {
|
||||
// 新增任务消息数量
|
||||
dispatch("increaseTaskMsgNum", dialog_id);
|
||||
if (mode === "chat") {
|
||||
return;
|
||||
}
|
||||
let dialog = state.cacheDialogs.find(({id}) => id == data.dialog_id);
|
||||
// 更新对话列表
|
||||
if (dialog) {
|
||||
// 新增未读数
|
||||
dialog.unread++;
|
||||
}
|
||||
Store.set('dialogMsgPush', data);
|
||||
}
|
||||
// 更新消息列表
|
||||
dispatch("saveDialogMsg", data)
|
||||
// 更新最后消息
|
||||
dispatch("updateDialogLastMsg", data);
|
||||
break;
|
||||
}
|
||||
// 更新消息列表
|
||||
dispatch("saveDialogMsg", data)
|
||||
// 更新最后消息
|
||||
dispatch("updateDialogLastMsg", data);
|
||||
})(msgDetail);
|
||||
break;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user