perf: 消息列表需支持多个置顶

This commit is contained in:
韦荣超 2022-02-18 10:10:17 +08:00
parent 503a719609
commit 2bd666efe7
4 changed files with 41 additions and 8 deletions

View File

@ -40,7 +40,7 @@ class DialogController extends AbstractController
{
$user = User::auth();
//
$list = WebSocketDialog::select(['web_socket_dialogs.*','u.top'])
$list = WebSocketDialog::select(['web_socket_dialogs.*','u.top','u.top_at'])
->join('web_socket_dialog_users as u', 'web_socket_dialogs.id', '=', 'u.dialog_id')
->where('u.userid', $user->userid)
->orderByDesc('u.top')
@ -500,12 +500,10 @@ class DialogController extends AbstractController
if (!$dialogUser) {
return Base::retError("会话不存在");
}
WebSocketDialogUser::whereUserid($user->userid)
->update([
'top' => 0
]);
$top = $dialogUser->top === 1 ? 0 : 1;
$topAt = $dialogUser->top === 1 ? null : Carbon::now();
$dialogUser->top = $top;
$dialogUser->top_at = $topAt;
$dialogUser->save();
return Base::retSuccess("success", $dialogId);
}

View File

@ -9,6 +9,7 @@ namespace App\Models;
* @property int|null $dialog_id 对话ID
* @property int|null $userid 会员ID
* @property int|null $top 是否置顶0否1是
* @property \Illuminate\Support\Carbon|null $top_at 置顶时间
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogUser newModelQuery()

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class WebSocketDialogUsersAddTopAt extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('web_socket_dialog_users', function (Blueprint $table) {
if (!Schema::hasColumn('web_socket_dialog_users', 'top_at')) {
$table->timestamp('top_at')->nullable()->after('top')->comment('置顶时间');
}
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('web_socket_dialog_users', function (Blueprint $table) {
$table->dropColumn("top_at");
});
}
}

View File

@ -159,7 +159,7 @@ export default {
if (dialogActive == '' && dialogKey == '') {
return this.cacheDialogs.filter(dialog => this.filterDialog(dialog)).sort((a, b) => {
if (a.top || b.top) {
return b.top - a.top;
return $A.Date(b.top_at) - $A.Date(a.top_at);
}
return $A.Date(b.last_at) - $A.Date(a.last_at);
});
@ -195,7 +195,7 @@ export default {
return true;
}).sort((a, b) => {
if (a.top || b.top) {
return b.top - a.top;
return $A.Date(b.top_at) - $A.Date(a.top_at);
}
return $A.Date(b.last_at) - $A.Date(a.last_at);
})
@ -311,7 +311,7 @@ export default {
},
filterDialog(dialog) {
if (dialog.unread > 0 || dialog.id == this.dialogId) {
if (dialog.unread > 0 || dialog.id == this.dialogId || dialog.top === 1) {
return true
}
if (dialog.name === undefined) {