mirror of
https://github.com/kuaifan/dootask.git
synced 2026-01-24 02:48:12 +00:00
perf: 优化转发消息
This commit is contained in:
parent
55ade32589
commit
4430d85242
@ -1547,42 +1547,7 @@ class DialogController extends AbstractController
|
|||||||
$fileMsg .= "<p>{$leave_message}</p>";
|
$fileMsg .= "<p>{$leave_message}</p>";
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
return AbstractModel::transaction(function() use ($user, $fileMsg, $userids, $dialogids) {
|
return WebSocketDialogMsg::sendMsgBatch($user, $userids, $dialogids, $fileMsg);
|
||||||
$msgs = [];
|
|
||||||
$already = [];
|
|
||||||
if ($dialogids) {
|
|
||||||
if (!is_array($dialogids)) {
|
|
||||||
$dialogids = [$dialogids];
|
|
||||||
}
|
|
||||||
foreach ($dialogids as $dialogid) {
|
|
||||||
$res = WebSocketDialogMsg::sendMsg(null, $dialogid, 'text', ['text' => $fileMsg], $user->userid);
|
|
||||||
if (Base::isSuccess($res)) {
|
|
||||||
$msgs[] = $res['data'];
|
|
||||||
$already[] = $dialogid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($userids) {
|
|
||||||
if (!is_array($userids)) {
|
|
||||||
$userids = [$userids];
|
|
||||||
}
|
|
||||||
foreach ($userids as $userid) {
|
|
||||||
if (!User::whereUserid($userid)->exists()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$dialog = WebSocketDialog::checkUserDialog($user, $userid);
|
|
||||||
if ($dialog && !in_array($dialog->id, $already)) {
|
|
||||||
$res = WebSocketDialogMsg::sendMsg(null, $dialog->id, 'text', ['text' => $fileMsg], $user->userid);
|
|
||||||
if (Base::isSuccess($res)) {
|
|
||||||
$msgs[] = $res['data'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Base::retSuccess('发送成功', [
|
|
||||||
'msgs' => $msgs
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -9,7 +9,6 @@ use App\Models\Report;
|
|||||||
use App\Models\ReportLink;
|
use App\Models\ReportLink;
|
||||||
use App\Models\ReportReceive;
|
use App\Models\ReportReceive;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\WebSocketDialog;
|
|
||||||
use App\Models\WebSocketDialogMsg;
|
use App\Models\WebSocketDialogMsg;
|
||||||
use App\Module\Base;
|
use App\Module\Base;
|
||||||
use App\Module\Doo;
|
use App\Module\Doo;
|
||||||
@ -592,42 +591,7 @@ class ReportController extends AbstractController
|
|||||||
}
|
}
|
||||||
$msgText = implode("", $reportMsgs);
|
$msgText = implode("", $reportMsgs);
|
||||||
//
|
//
|
||||||
return AbstractModel::transaction(function() use ($user, $msgText, $userids, $dialogids) {
|
return WebSocketDialogMsg::sendMsgBatch($user, $userids, $dialogids, $msgText);
|
||||||
$msgs = [];
|
|
||||||
$already = [];
|
|
||||||
if ($dialogids) {
|
|
||||||
if (!is_array($dialogids)) {
|
|
||||||
$dialogids = [$dialogids];
|
|
||||||
}
|
|
||||||
foreach ($dialogids as $dialogid) {
|
|
||||||
$res = WebSocketDialogMsg::sendMsg(null, $dialogid, 'text', ['text' => $msgText], $user->userid);
|
|
||||||
if (Base::isSuccess($res)) {
|
|
||||||
$msgs[] = $res['data'];
|
|
||||||
$already[] = $dialogid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($userids) {
|
|
||||||
if (!is_array($userids)) {
|
|
||||||
$userids = [$userids];
|
|
||||||
}
|
|
||||||
foreach ($userids as $userid) {
|
|
||||||
if (!User::whereUserid($userid)->exists()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$dialog = WebSocketDialog::checkUserDialog($user, $userid);
|
|
||||||
if ($dialog && !in_array($dialog->id, $already)) {
|
|
||||||
$res = WebSocketDialogMsg::sendMsg(null, $dialog->id, 'text', ['text' => $msgText], $user->userid);
|
|
||||||
if (Base::isSuccess($res)) {
|
|
||||||
$msgs[] = $res['data'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Base::retSuccess('发送成功', [
|
|
||||||
'msgs' => $msgs
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1261,6 +1261,55 @@ class WebSocketDialogMsg extends AbstractModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量发送消息
|
||||||
|
* @param User $user 发送的会员
|
||||||
|
* @param array $userids 接收的会员ID
|
||||||
|
* @param array $dialogids 接收的会话ID
|
||||||
|
* @param string $msgText 发送的消息
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function sendMsgBatch($user, $userids, $dialogids, $msgText)
|
||||||
|
{
|
||||||
|
return AbstractModel::transaction(function() use ($user, $userids, $dialogids, $msgText) {
|
||||||
|
$msgs = [];
|
||||||
|
$already = [];
|
||||||
|
if ($dialogids) {
|
||||||
|
if (!is_array($dialogids)) {
|
||||||
|
$dialogids = [$dialogids];
|
||||||
|
}
|
||||||
|
foreach ($dialogids as $dialogid) {
|
||||||
|
$res = WebSocketDialogMsg::sendMsg(null, $dialogid, 'text', ['text' => $msgText], $user->userid);
|
||||||
|
if (Base::isSuccess($res)) {
|
||||||
|
$msgs[] = $res['data'];
|
||||||
|
$already[] = $dialogid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($userids) {
|
||||||
|
if (!is_array($userids)) {
|
||||||
|
$userids = [$userids];
|
||||||
|
}
|
||||||
|
foreach ($userids as $userid) {
|
||||||
|
if (!User::whereUserid($userid)->exists()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$dialog = WebSocketDialog::checkUserDialog($user, $userid);
|
||||||
|
if ($dialog && !in_array($dialog->id, $already)) {
|
||||||
|
$res = WebSocketDialogMsg::sendMsg(null, $dialog->id, 'text', ['text' => $msgText], $user->userid);
|
||||||
|
if (Base::isSuccess($res)) {
|
||||||
|
$msgs[] = $res['data'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Base::retSuccess('发送成功', [
|
||||||
|
'msgs' => $msgs
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将被@的人加入群
|
* 将被@的人加入群
|
||||||
* @param WebSocketDialog $dialog 对话
|
* @param WebSocketDialog $dialog 对话
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user