@@ -640,27 +640,35 @@ private function previewTemplateMsg($msg)
640640
641641 /**
642642 * 生成关键词并保存
643+ * @param string $key
643644 * @return void
644645 */
645- public function generateKeyAndSave (): void
646+ public function generateKeyAndSave (string $ key = '' ): void
646647 {
647- $ key = '' ;
648- switch ($ this ->type ) {
649- case 'text ' :
650- case 'vote ' :
651- case 'word-chain ' :
652- $ key = strip_tags ($ this ->msg ['text ' ]);
653- break ;
648+ if (empty ($ key )) {
649+ $ key = '' ;
650+ switch ($ this ->type ) {
651+ case 'text ' :
652+ if (!preg_match ("/<span[^>]*?data-quick-key=([ \"'])(.*?) \\1[^>]*?>/is " , $ this ->msg ['text ' ])) {
653+ $ key = strip_tags ($ this ->msg ['text ' ]);
654+ }
655+ break ;
654656
655- case 'file ' :
656- $ key = $ this ->msg ['name ' ];
657- $ key = preg_replace ("/^(image|\d+)\.(png|jpg|jpeg|webp|gif)$/i " , "" , $ key );
658- $ key = preg_replace ("/^LongText-(.*?)/i " , "" , $ key );
659- break ;
657+ case 'vote ' :
658+ case 'word-chain ' :
659+ $ key = strip_tags ($ this ->msg ['text ' ]);
660+ break ;
660661
661- case 'meeting ' :
662- $ key = $ this ->msg ['name ' ];
663- break ;
662+ case 'file ' :
663+ $ key = $ this ->msg ['name ' ];
664+ $ key = preg_replace ("/^(image|\d+)\.(png|jpg|jpeg|webp|gif)$/i " , "" , $ key );
665+ $ key = preg_replace ("/^LongText-(.*?)/i " , "" , $ key );
666+ break ;
667+
668+ case 'meeting ' :
669+ $ key = $ this ->msg ['name ' ];
670+ break ;
671+ }
664672 }
665673 $ key = str_replace (["" " , "& " , "< " , "> " ], "" , $ key );
666674 $ key = str_replace (["\r" , "\n" , "\t" , " " ], " " , $ key );
@@ -940,9 +948,10 @@ public static function formatMsg($text, $dialog_id)
940948 * @param bool $push_retry 推送-失败后重试1次(有时候在事务里执行,数据还没生成时会出现找不到消息的情况)
941949 * @param bool|null $push_silence 推送-静默
942950 * - type = [text|file|record|meeting] 默认为:false
951+ * @param string|null $search_key 搜索关键词(用于搜索,留空则自动生成)
943952 * @return array
944953 */
945- public static function sendMsg ($ action , $ dialog_id , $ type , $ msg , $ sender = null , $ push_self = false , $ push_retry = false , $ push_silence = null )
954+ public static function sendMsg ($ action , $ dialog_id , $ type , $ msg , $ sender = null , $ push_self = false , $ push_retry = false , $ push_silence = null , $ search_key = null )
946955 {
947956 $ link = 0 ;
948957 $ mtype = $ type ;
@@ -1017,7 +1026,7 @@ public static function sendMsg($action, $dialog_id, $type, $msg, $sender = null,
10171026 'modify ' => $ modify ,
10181027 ];
10191028 $ dialogMsg ->updateInstance ($ updateData );
1020- $ dialogMsg ->generateKeyAndSave ();
1029+ $ dialogMsg ->generateKeyAndSave ($ search_key );
10211030 //
10221031 WebSocketDialogUser::whereDialogId ($ dialog ->id )->whereUserid ($ sender )->whereHide (1 )->change ([
10231032 'hide ' => 0 , // 修改消息时,显示会话(仅自己)
@@ -1064,7 +1073,7 @@ public static function sendMsg($action, $dialog_id, $type, $msg, $sender = null,
10641073 ]);
10651074 AbstractModel::transaction (function () use ($ dialogMsg ) {
10661075 $ dialogMsg ->send = 1 ;
1067- $ dialogMsg ->generateKeyAndSave ();
1076+ $ dialogMsg ->generateKeyAndSave ($ search_key );
10681077 //
10691078 if ($ dialogMsg ->type === 'meeting ' ) {
10701079 MeetingMsg::createInstance ([
0 commit comments