撤回消息优化
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user