diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php index fb8e5c584..e1e806a70 100755 --- a/app/Http/Controllers/Api/DialogController.php +++ b/app/Http/Controllers/Api/DialogController.php @@ -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); diff --git a/app/Module/Base.php b/app/Module/Base.php index 9bc804732..36dd0d11e 100755 --- a/app/Module/Base.php +++ b/app/Module/Base.php @@ -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 diff --git a/resources/assets/js/pages/manage/messenger.vue b/resources/assets/js/pages/manage/messenger.vue index 4eb5ae1e8..952cf2c20 100644 --- a/resources/assets/js/pages/manage/messenger.vue +++ b/resources/assets/js/pages/manage/messenger.vue @@ -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) {