perf: 优化通知类消息字符长度

This commit is contained in:
kuaifan 2022-07-11 07:30:22 +08:00
parent 4561efc3ce
commit 43a4e5741a
2 changed files with 20 additions and 3 deletions

View File

@ -1130,7 +1130,7 @@ class DialogController extends AbstractController
'data' => [
'id' => $msg->id,
'type' => $msg->type,
'msg' => $msg->msg,
'msg' => $msg->quoteTextMsg(),
]
]);
if (Base::isSuccess($res)) {

View File

@ -283,7 +283,7 @@ class WebSocketDialogMsg extends AbstractModel
'data' => [
'id' => $this->id,
'type' => $this->type,
'msg' => $this->msg,
'msg' => $this->quoteTextMsg(),
]
], $sender);
if (Base::isSuccess($res)) {
@ -328,7 +328,7 @@ class WebSocketDialogMsg extends AbstractModel
'data' => [
'id' => $this->id,
'type' => $this->type,
'msg' => $this->msg,
'msg' => $this->quoteTextMsg(),
'userids' => implode(",", $userids),
]
], $sender);
@ -490,6 +490,23 @@ class WebSocketDialogMsg extends AbstractModel
};
}
/**
* 返回引用消息(如果是文本消息则截取)
* @param int $strlen
* @return array|mixed
*/
public function quoteTextMsg($strlen = 30)
{
$msg = $this->msg;
if ($this->type === 'text') {
$msg['text'] = $this->previewTextMsg($msg['text']);
if (mb_strlen($msg['text']) > $strlen) {
$msg['text'] = mb_substr($msg['text'], 0, $strlen - 3) . "...";
}
}
return $msg;
}
/**
* 返回文本预览消息
* @param $text