mirror of
https://github.com/kuaifan/dootask.git
synced 2026-03-04 16:37:06 +00:00
perf: 搜索对话可以搜索远程的对话
This commit is contained in:
parent
1fb70a4456
commit
e861e8d878
@ -81,19 +81,35 @@ class DialogController extends AbstractController
|
||||
$user = User::auth();
|
||||
//
|
||||
$key = trim(Request::input('key'));
|
||||
if (empty($key)) {
|
||||
return Base::retError('请输入搜索关键词');
|
||||
}
|
||||
//
|
||||
$list = WebSocketDialog::select(['web_socket_dialogs.*', 'u.top_at', 'u.mark_unread', 'm.id as search_msg_id'])
|
||||
$list = 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_msgs as m', 'web_socket_dialogs.id', '=', 'm.dialog_id')
|
||||
->where('web_socket_dialogs.name', 'LIKE', "%{$key}%")
|
||||
->where('u.userid', $user->userid)
|
||||
->where('m.key', 'LIKE', "%{$key}%")
|
||||
->orderByDesc('m.id')
|
||||
->orderByDesc('u.top_at')
|
||||
->orderByDesc('web_socket_dialogs.last_at')
|
||||
->take(20)
|
||||
->get();
|
||||
//
|
||||
$list->transform(function (WebSocketDialog $item) use ($user) {
|
||||
return $item->formatData($user->userid);
|
||||
});
|
||||
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')
|
||||
->join('web_socket_dialog_msgs as m', 'web_socket_dialogs.id', '=', 'm.dialog_id')
|
||||
->where('u.userid', $user->userid)
|
||||
->where('m.key', 'LIKE', "%{$key}%")
|
||||
->orderByDesc('m.id')
|
||||
->take(20 - count($list))
|
||||
->get();
|
||||
$msgs->transform(function (WebSocketDialog $item) use ($user) {
|
||||
return $item->formatData($user->userid);
|
||||
});
|
||||
$list = array_merge($list->toArray(), $msgs->toArray());
|
||||
}
|
||||
//
|
||||
return Base::retSuccess('success', $list);
|
||||
}
|
||||
|
||||
@ -271,18 +271,22 @@ class ProjectController extends AbstractController
|
||||
}
|
||||
//
|
||||
$project = Project::userProject($project_id, true, true);
|
||||
//
|
||||
if ($project->name != $name) {
|
||||
$project->addLog("修改项目名称", [
|
||||
'change' => [$project->name, $name]
|
||||
]);
|
||||
$project->name = $name;
|
||||
}
|
||||
if ($project->desc != $desc) {
|
||||
$project->desc = $desc;
|
||||
$project->addLog("修改项目介绍");
|
||||
}
|
||||
$project->save();
|
||||
AbstractModel::transaction(function () use ($desc, $name, $project) {
|
||||
if ($project->name != $name) {
|
||||
$project->addLog("修改项目名称", [
|
||||
'change' => [$project->name, $name]
|
||||
]);
|
||||
$project->name = $name;
|
||||
if ($project->dialog_id) {
|
||||
WebSocketDialog::updateData(['id' => $project->dialog_id], ['name' => $project->name]);
|
||||
}
|
||||
}
|
||||
if ($project->desc != $desc) {
|
||||
$project->desc = $desc;
|
||||
$project->addLog("修改项目介绍");
|
||||
}
|
||||
$project->save();
|
||||
});
|
||||
$project->pushMsg('update', $project);
|
||||
//
|
||||
return Base::retSuccess('修改成功', $project);
|
||||
@ -1543,7 +1547,7 @@ class ProjectController extends AbstractController
|
||||
AbstractModel::transaction(function() use ($task) {
|
||||
if (empty($task->dialog_id)) {
|
||||
$task->lockForUpdate();
|
||||
$dialog = WebSocketDialog::createGroup(null, $task->relationUserids(), 'task');
|
||||
$dialog = WebSocketDialog::createGroup($task->name, $task->relationUserids(), 'task');
|
||||
if ($dialog) {
|
||||
$task->dialog_id = $dialog->id;
|
||||
$task->save();
|
||||
|
||||
@ -537,7 +537,7 @@ class Project extends AbstractModel
|
||||
$column['project_id'] = $project->id;
|
||||
ProjectColumn::createInstance($column)->save();
|
||||
}
|
||||
$dialog = WebSocketDialog::createGroup(null, $project->userid, 'project');
|
||||
$dialog = WebSocketDialog::createGroup($project->name, $project->userid, 'project');
|
||||
if (empty($dialog)) {
|
||||
throw new ApiException('创建项目聊天室失败');
|
||||
}
|
||||
|
||||
@ -649,6 +649,9 @@ class ProjectTask extends AbstractModel
|
||||
'change' => [$this->name, $data['name']]
|
||||
]);
|
||||
$this->name = $data['name'];
|
||||
if ($this->dialog_id) {
|
||||
WebSocketDialog::updateData(['id' => $this->dialog_id], ['name' => $this->name]);
|
||||
}
|
||||
}
|
||||
// 负责人
|
||||
if (Arr::exists($data, 'owner')) {
|
||||
|
||||
@ -427,5 +427,4 @@ class WebSocketDialog extends AbstractModel
|
||||
return $dialog;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class UpdateWebSocketDialogsGroupName extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('web_socket_dialogs', function (Blueprint $table) {
|
||||
$table->string('name', 255)->nullable()->default('')->comment('对话名称')->change();
|
||||
});
|
||||
//
|
||||
\App\Models\WebSocketDialog::whereGroupType('project')
|
||||
->chunk(100, function ($lists) {
|
||||
/** @var \App\Models\WebSocketDialog $item */
|
||||
foreach ($lists as $item) {
|
||||
$item->name = \App\Models\Project::whereDialogId($item->id)->first()?->name;
|
||||
$item->save();
|
||||
}
|
||||
});
|
||||
\App\Models\WebSocketDialog::whereGroupType('task')
|
||||
->chunk(100, function ($lists) {
|
||||
/** @var \App\Models\WebSocketDialog $item */
|
||||
foreach ($lists as $item) {
|
||||
$item->name = \App\Models\ProjectTask::whereDialogId($item->id)->first()?->name;
|
||||
$item->save();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -266,7 +266,7 @@ export default {
|
||||
}
|
||||
})
|
||||
dialogSearch.forEach(item => {
|
||||
if (!msgIds.includes(item.last_msg.id)) {
|
||||
if (!item.last_msg || !msgIds.includes(item.last_msg.id)) {
|
||||
list.push(Object.assign(item, {is_search: true}))
|
||||
}
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user