perf: 消息搜索支持会员结果

This commit is contained in:
kuaifan 2022-12-08 13:50:43 +08:00
parent 6f255189bd
commit 675987d1f2
3 changed files with 57 additions and 8 deletions

View File

@ -85,8 +85,8 @@ class DialogController extends AbstractController
if (empty($key)) {
return Base::retError('请输入搜索关键词');
}
//
$list = WebSocketDialog::select(['web_socket_dialogs.*', 'u.top_at', 'u.mark_unread'])
// 搜索会话
$dialogs = WebSocketDialog::select(['web_socket_dialogs.*', 'u.top_at', 'u.mark_unread'])
->join('web_socket_dialog_users as u', 'web_socket_dialogs.id', '=', 'u.dialog_id')
->where('web_socket_dialogs.name', 'LIKE', "%{$key}%")
->where('u.userid', $user->userid)
@ -94,9 +94,30 @@ class DialogController extends AbstractController
->orderByDesc('web_socket_dialogs.last_at')
->take(20)
->get();
$list->transform(function (WebSocketDialog $item) use ($user) {
$dialogs->transform(function (WebSocketDialog $item) use ($user) {
return $item->formatData($user->userid);
});
$list = $dialogs->toArray();
// 搜索联系人
if (count($list) < 20 && Base::judgeClientVersion("0.21.60")) {
$users = User::select(User::$basicField)
->where(function ($query) use ($key) {
$query->where("email", "like", "%{$key}%")->orWhere("nickname", "like", "%{$key}%");
})->orderBy('userid')
->take(20 - count($list))
->get();
$users->transform(function (User $item) {
return [
'id' => 'u:' . $item->userid,
'type' => 'user',
'name' => $item->nickname,
'dialog_user' => $item,
'last_msg' => null,
];
});
$list = array_merge($list, $users->toArray());
}
// 搜索消息会话
if (count($list) < 20) {
$msgs = WebSocketDialog::select(['web_socket_dialogs.*', 'u.top_at', 'u.mark_unread', 'm.id as search_msg_id'])
->join('web_socket_dialog_users as u', 'web_socket_dialogs.id', '=', 'u.dialog_id')
@ -109,7 +130,7 @@ class DialogController extends AbstractController
$msgs->transform(function (WebSocketDialog $item) use ($user) {
return $item->formatData($user->userid);
});
$list = array_merge($list->toArray(), $msgs->toArray());
$list = array_merge($list, $msgs->toArray());
}
//
return Base::retSuccess('success', $list);

View File

@ -106,11 +106,21 @@ class Base
*/
public static function checkClientVersion($min)
{
if (version_compare(Base::getClientVersion(), $min, '<')) {
if (!self::judgeClientVersion($min)) {
throw new ApiException('当前版本 (v' . Base::getClientVersion() . ') 过低,最低版本要求 (v' . $min . ')。');
}
}
/**
* 判断客户端版本
* @param $min
* @return bool
*/
public static function judgeClientVersion($min)
{
return !version_compare(Base::getClientVersion(), $min, '<');
}
/**
* 判断是否域名格式
* @param $domain

View File

@ -275,14 +275,24 @@ export default {
})
if (dialogSearch.length > 0) {
const msgIds = [];
const userIds = [];
list.forEach(item => {
if (item.last_msg && !msgIds.includes(item.last_msg.id)) {
msgIds.push(item.last_msg.id)
}
if (item.dialog_user && !userIds.includes(item.dialog_user.userid)) {
userIds.push(item.dialog_user.userid)
}
})
dialogSearch.forEach(item => {
if (!item.last_msg || !msgIds.includes(item.last_msg.id)) {
list.push(Object.assign(item, {is_search: true}))
if ($A.leftExists(item.id, "u:")) {
if (!userIds.includes(item.dialog_user.userid)) {
list.push(Object.assign(item, {is_search: true}))
}
} else {
if (!item.last_msg || !msgIds.includes(item.last_msg.id)) {
list.push(Object.assign(item, {is_search: true}))
}
}
})
}
@ -496,7 +506,15 @@ export default {
return
}
this.dialogKey = "";
this.$store.dispatch("openDialog", dialogId)
//
if ($A.isJson(dialogId) && $A.leftExists(dialogId.dialog_id, "u:")) {
this.$store.dispatch("showSpinner", 300)
this.$store.dispatch("openDialogUserid", $A.leftDelete(dialogId.dialog_id, "u:")).finally(_ => {
this.$store.dispatch("hiddenSpinner")
})
} else {
this.$store.dispatch("openDialog", dialogId)
}
},
openContacts(user) {