mirror of
https://github.com/kuaifan/dootask.git
synced 2026-03-18 03:33:24 +00:00
perf: 消息搜索支持会员结果
This commit is contained in:
parent
6f255189bd
commit
675987d1f2
@ -85,8 +85,8 @@ class DialogController extends AbstractController
|
|||||||
if (empty($key)) {
|
if (empty($key)) {
|
||||||
return Base::retError('请输入搜索关键词');
|
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')
|
->join('web_socket_dialog_users as u', 'web_socket_dialogs.id', '=', 'u.dialog_id')
|
||||||
->where('web_socket_dialogs.name', 'LIKE', "%{$key}%")
|
->where('web_socket_dialogs.name', 'LIKE', "%{$key}%")
|
||||||
->where('u.userid', $user->userid)
|
->where('u.userid', $user->userid)
|
||||||
@ -94,9 +94,30 @@ class DialogController extends AbstractController
|
|||||||
->orderByDesc('web_socket_dialogs.last_at')
|
->orderByDesc('web_socket_dialogs.last_at')
|
||||||
->take(20)
|
->take(20)
|
||||||
->get();
|
->get();
|
||||||
$list->transform(function (WebSocketDialog $item) use ($user) {
|
$dialogs->transform(function (WebSocketDialog $item) use ($user) {
|
||||||
return $item->formatData($user->userid);
|
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) {
|
if (count($list) < 20) {
|
||||||
$msgs = WebSocketDialog::select(['web_socket_dialogs.*', 'u.top_at', 'u.mark_unread', 'm.id as search_msg_id'])
|
$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')
|
->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) {
|
$msgs->transform(function (WebSocketDialog $item) use ($user) {
|
||||||
return $item->formatData($user->userid);
|
return $item->formatData($user->userid);
|
||||||
});
|
});
|
||||||
$list = array_merge($list->toArray(), $msgs->toArray());
|
$list = array_merge($list, $msgs->toArray());
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
return Base::retSuccess('success', $list);
|
return Base::retSuccess('success', $list);
|
||||||
|
|||||||
@ -106,11 +106,21 @@ class Base
|
|||||||
*/
|
*/
|
||||||
public static function checkClientVersion($min)
|
public static function checkClientVersion($min)
|
||||||
{
|
{
|
||||||
if (version_compare(Base::getClientVersion(), $min, '<')) {
|
if (!self::judgeClientVersion($min)) {
|
||||||
throw new ApiException('当前版本 (v' . Base::getClientVersion() . ') 过低,最低版本要求 (v' . $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
|
* @param $domain
|
||||||
|
|||||||
@ -275,14 +275,24 @@ export default {
|
|||||||
})
|
})
|
||||||
if (dialogSearch.length > 0) {
|
if (dialogSearch.length > 0) {
|
||||||
const msgIds = [];
|
const msgIds = [];
|
||||||
|
const userIds = [];
|
||||||
list.forEach(item => {
|
list.forEach(item => {
|
||||||
if (item.last_msg && !msgIds.includes(item.last_msg.id)) {
|
if (item.last_msg && !msgIds.includes(item.last_msg.id)) {
|
||||||
msgIds.push(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 => {
|
dialogSearch.forEach(item => {
|
||||||
if (!item.last_msg || !msgIds.includes(item.last_msg.id)) {
|
if ($A.leftExists(item.id, "u:")) {
|
||||||
list.push(Object.assign(item, {is_search: true}))
|
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
|
return
|
||||||
}
|
}
|
||||||
this.dialogKey = "";
|
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) {
|
openContacts(user) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user