no message

This commit is contained in:
kuaifan 2022-07-05 14:34:23 +08:00
parent 8eb956f831
commit ef2b1dd321
5 changed files with 30 additions and 9 deletions

View File

@ -1185,7 +1185,7 @@ class ProjectTask extends AbstractModel
public function completeTask($complete_at) public function completeTask($complete_at)
{ {
AbstractModel::transaction(function () use ($complete_at) { AbstractModel::transaction(function () use ($complete_at) {
$addMsg = empty($this->parent_id) && $this->dialog_id > 0; $addMsg = $this->parent_id == 0 && $this->dialog_id > 0;
if ($complete_at === null) { if ($complete_at === null) {
// 标记未完成 // 标记未完成
$this->complete_at = null; $this->complete_at = null;
@ -1193,7 +1193,7 @@ class ProjectTask extends AbstractModel
if ($addMsg) { if ($addMsg) {
WebSocketDialogMsg::sendMsg(null, $this->dialog_id, 'notice', [ WebSocketDialogMsg::sendMsg(null, $this->dialog_id, 'notice', [
'notice' => '标记任务未完成' 'notice' => '标记任务未完成'
], 0, true); ], 0, true, true);
} }
} else { } else {
// 标记已完成 // 标记已完成
@ -1210,7 +1210,7 @@ class ProjectTask extends AbstractModel
if ($addMsg) { if ($addMsg) {
WebSocketDialogMsg::sendMsg(null, $this->dialog_id, 'notice', [ WebSocketDialogMsg::sendMsg(null, $this->dialog_id, 'notice', [
'notice' => '标记任务已完成' 'notice' => '标记任务已完成'
], 0, true); ], 0, true, true);
} }
} }
$this->save(); $this->save();

View File

@ -152,7 +152,7 @@ class WebSocketDialog extends AbstractModel
]); ]);
WebSocketDialogMsg::sendMsg(null, $this->id, 'notice', [ WebSocketDialogMsg::sendMsg(null, $this->id, 'notice', [
'notice' => User::userid2nickname($value) . " 已加入群组" 'notice' => User::userid2nickname($value) . " 已加入群组"
], $inviter, true); ], $inviter, true, true);
} }
} }
}); });
@ -197,7 +197,9 @@ class WebSocketDialog extends AbstractModel
} else { } else {
$notice = User::userid2nickname($item->userid) . " 退出群组"; $notice = User::userid2nickname($item->userid) . " 退出群组";
} }
WebSocketDialogMsg::sendMsg(null, $this->id, 'notice', ['notice' => $notice], User::userid(), true); WebSocketDialogMsg::sendMsg(null, $this->id, 'notice', [
'notice' => $notice
], User::userid(), true, true);
} }
}); });
}); });

View File

@ -526,9 +526,10 @@ class WebSocketDialogMsg extends AbstractModel
* @param array $msg 发送的消息 * @param array $msg 发送的消息
* @param int $sender 发送的会员ID默认自己0为系统 * @param int $sender 发送的会员ID默认自己0为系统
* @param bool $push_self 是否推送给自己 * @param bool $push_self 是否推送给自己
* @param bool $push_retry 推送失败后重试1次有时候在事务里执行数据还没生成时会出现找不到消息的情况
* @return array * @return array
*/ */
public static function sendMsg($action, $dialog_id, $type, $msg, $sender = 0, $push_self = false) public static function sendMsg($action, $dialog_id, $type, $msg, $sender = 0, $push_self = false, $push_retry = false)
{ {
$link = 0; $link = 0;
$mtype = $type; $mtype = $type;
@ -612,6 +613,9 @@ class WebSocketDialogMsg extends AbstractModel
if ($push_self) { if ($push_self) {
$task->setIgnoreFd(null); $task->setIgnoreFd(null);
} }
if ($push_retry) {
$task->setMsgNotExistRetry(true);
}
Task::deliver($task); Task::deliver($task);
// //
return Base::retSuccess('发送成功', $dialogMsg); return Base::retSuccess('发送成功', $dialogMsg);

View File

@ -21,15 +21,17 @@ class WebSocketDialogMsgTask extends AbstractTask
{ {
protected $id; protected $id;
protected $ignoreFd; protected $ignoreFd;
protected $msgNotExistRetry = false;
/** /**
* WebSocketDialogMsgTask constructor. * WebSocketDialogMsgTask constructor.
* @param int $id 消息ID * @param int $id 消息ID
* @param mixed $ignoreFd
*/ */
public function __construct($id) public function __construct($id, $ignoreFd = null)
{ {
$this->id = $id; $this->id = $id;
$this->ignoreFd = Request::header('fd'); $this->ignoreFd = $ignoreFd === null ? Request::header('fd') : $ignoreFd;
} }
/** /**
@ -40,6 +42,14 @@ class WebSocketDialogMsgTask extends AbstractTask
$this->ignoreFd = $ignoreFd; $this->ignoreFd = $ignoreFd;
} }
/**
* @param bool $msgNotExistRetry
*/
public function setMsgNotExistRetry(bool $msgNotExistRetry): void
{
$this->msgNotExistRetry = $msgNotExistRetry;
}
public function start() public function start()
{ {
global $_A; global $_A;
@ -50,6 +60,11 @@ class WebSocketDialogMsgTask extends AbstractTask
// //
$msg = WebSocketDialogMsg::find($this->id); $msg = WebSocketDialogMsg::find($this->id);
if (empty($msg)) { if (empty($msg)) {
if ($this->msgNotExistRetry) {
$task = new WebSocketDialogMsgTask($this->id, $this->ignoreFd || '');
$task->delay(1);
$this->addTask($task);
}
return; return;
} }
$dialog = WebSocketDialog::find($msg->dialog_id); $dialog = WebSocketDialog::find($msg->dialog_id);

View File

@ -682,7 +682,7 @@ export default {
this.msgNew += tmpList.length this.msgNew += tmpList.length
} else { } else {
if (!this.preventToBottom) { if (!this.preventToBottom) {
requestAnimationFrame(this.onToBottom) this.$nextTick(this.onToBottom)
} }
} }
}, },