perf: 消息列表需支持多个置顶
This commit is contained in:
parent
503a719609
commit
2bd666efe7
@ -40,7 +40,7 @@ class DialogController extends AbstractController
|
|||||||
{
|
{
|
||||||
$user = User::auth();
|
$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')
|
->join('web_socket_dialog_users as u', 'web_socket_dialogs.id', '=', 'u.dialog_id')
|
||||||
->where('u.userid', $user->userid)
|
->where('u.userid', $user->userid)
|
||||||
->orderByDesc('u.top')
|
->orderByDesc('u.top')
|
||||||
@ -500,12 +500,10 @@ class DialogController extends AbstractController
|
|||||||
if (!$dialogUser) {
|
if (!$dialogUser) {
|
||||||
return Base::retError("会话不存在");
|
return Base::retError("会话不存在");
|
||||||
}
|
}
|
||||||
WebSocketDialogUser::whereUserid($user->userid)
|
|
||||||
->update([
|
|
||||||
'top' => 0
|
|
||||||
]);
|
|
||||||
$top = $dialogUser->top === 1 ? 0 : 1;
|
$top = $dialogUser->top === 1 ? 0 : 1;
|
||||||
|
$topAt = $dialogUser->top === 1 ? null : Carbon::now();
|
||||||
$dialogUser->top = $top;
|
$dialogUser->top = $top;
|
||||||
|
$dialogUser->top_at = $topAt;
|
||||||
$dialogUser->save();
|
$dialogUser->save();
|
||||||
return Base::retSuccess("success", $dialogId);
|
return Base::retSuccess("success", $dialogId);
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ namespace App\Models;
|
|||||||
* @property int|null $dialog_id 对话ID
|
* @property int|null $dialog_id 对话ID
|
||||||
* @property int|null $userid 会员ID
|
* @property int|null $userid 会员ID
|
||||||
* @property int|null $top 是否置顶:0否,1是
|
* @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 $created_at
|
||||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogUser newModelQuery()
|
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogUser newModelQuery()
|
||||||
|
@ -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");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -159,7 +159,7 @@ export default {
|
|||||||
if (dialogActive == '' && dialogKey == '') {
|
if (dialogActive == '' && dialogKey == '') {
|
||||||
return this.cacheDialogs.filter(dialog => this.filterDialog(dialog)).sort((a, b) => {
|
return this.cacheDialogs.filter(dialog => this.filterDialog(dialog)).sort((a, b) => {
|
||||||
if (a.top || b.top) {
|
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);
|
return $A.Date(b.last_at) - $A.Date(a.last_at);
|
||||||
});
|
});
|
||||||
@ -195,7 +195,7 @@ export default {
|
|||||||
return true;
|
return true;
|
||||||
}).sort((a, b) => {
|
}).sort((a, b) => {
|
||||||
if (a.top || b.top) {
|
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);
|
return $A.Date(b.last_at) - $A.Date(a.last_at);
|
||||||
})
|
})
|
||||||
@ -311,7 +311,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
filterDialog(dialog) {
|
filterDialog(dialog) {
|
||||||
if (dialog.unread > 0 || dialog.id == this.dialogId) {
|
if (dialog.unread > 0 || dialog.id == this.dialogId || dialog.top === 1) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if (dialog.name === undefined) {
|
if (dialog.name === undefined) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user