fix: 修复置顶人员

This commit is contained in:
weifashi 2023-12-29 17:05:57 +08:00
parent 1a69e76fe7
commit 22415e6c61
4 changed files with 20 additions and 12 deletions

View File

@ -2277,13 +2277,16 @@ class DialogController extends AbstractController
$dialog = WebSocketDialog::checkDialog($msg->dialog_id); $dialog = WebSocketDialog::checkDialog($msg->dialog_id);
// //
$before = $dialog->top_msg_id; $before = $dialog->top_msg_id;
$beforeTopUserid = $dialog->top_userid;
$dialog->top_msg_id = $msg->id == $before ? 0 : $msg->id; $dialog->top_msg_id = $msg->id == $before ? 0 : $msg->id;
$dialog->top_userid = $dialog->top_msg_id ? $user->userid : 0;
$dialog->save(); $dialog->save();
// //
$data = [ $data = [
'update' => [ 'update' => [
'dialog_id' => $dialog->id, 'dialog_id' => $dialog->id,
'top_msg_id' => $dialog->top_msg_id, 'top_msg_id' => $dialog->top_msg_id,
'top_userid' => $dialog->top_userid,
] ]
]; ];
$res = $msg->sendMsg(null, $dialog->id, 'top', [ $res = $msg->sendMsg(null, $dialog->id, 'top', [
@ -2295,17 +2298,11 @@ class DialogController extends AbstractController
] ]
], $user->userid); ], $user->userid);
if (Base::isSuccess($res)) { if (Base::isSuccess($res)) {
if ($before != $dialog->top_msg_id) {
$oldTop = WebSocketDialog::whereTopMsgId($before)->first();
if ($oldTop){
$oldTop->top_msg_id = 0;
$oldTop->save();
}
}
$data['add'] = $res['data']; $data['add'] = $res['data'];
$dialog->pushMsg('updateTopMsg', $data['update']); $dialog->pushMsg('updateTopMsg', $data['update']);
} else { } else {
$dialog->top_msg_id = $before; $dialog->top_msg_id = $before;
$dialog->top_userid = $beforeTopUserid;
$dialog->save(); $dialog->save();
} }
// //

View File

@ -21,7 +21,8 @@ class AddWebSocketDialogsTop extends Migration
}); });
// //
Schema::table('web_socket_dialogs', function (Blueprint $table) { Schema::table('web_socket_dialogs', function (Blueprint $table) {
$table->bigInteger('top_msg_id')->nullable()->default(0)->after('link_id')->comment('置顶的消息ID'); $table->bigInteger('top_userid')->nullable()->default(0)->after('link_id')->comment('置顶的用户ID');
$table->bigInteger('top_msg_id')->nullable()->default(0)->after('top_userid')->comment('置顶的消息ID');
}); });
} }
@ -40,7 +41,12 @@ class AddWebSocketDialogsTop extends Migration
}); });
// //
Schema::table('web_socket_dialogs', function (Blueprint $table) { Schema::table('web_socket_dialogs', function (Blueprint $table) {
$table->dropColumn("top_msg_id"); if (Schema::hasColumn('web_socket_dialogs', 'top_msg_id')) {
$table->dropColumn("top_msg_id");
}
if (Schema::hasColumn('web_socket_dialogs', 'top_userid')) {
$table->dropColumn("top_userid");
}
}); });
} }
} }

View File

@ -147,7 +147,7 @@
<UserAvatar :userid="topMessageInfo.userid" showName :showIcon="false"/>: <UserAvatar :userid="topMessageInfo.userid" showName :showIcon="false"/>:
<span>{{$A.getMsgSimpleDesc(topMessageInfo)}}</span> <span>{{$A.getMsgSimpleDesc(topMessageInfo)}}</span>
</p> </p>
<p class="personnel">{{$L('置顶人员')}} <UserAvatar :userid="topMessageInfo.top" showName :showIcon="false"/> </p> <p class="personnel">{{$L('置顶人员')}} <UserAvatar :userid="dialogData.top_userid" showName :showIcon="false"/> </p>
</div> </div>
<div class="dialog-top-message-btn"> <div class="dialog-top-message-btn">
<Loading v-if="topViewPosLoad" type="pure"/> <Loading v-if="topViewPosLoad" type="pure"/>
@ -3399,7 +3399,8 @@ export default {
// //
this.$store.dispatch("saveDialog", { this.$store.dispatch("saveDialog", {
'id' : this.dialogId, 'id' : this.dialogId,
'top_msg_id' : data.update?.top_msg_id || 0 'top_msg_id' : data.update?.top_msg_id || 0,
'top_userid' : data.update?.top_userid || 0
}); });
// //
if (data.update?.top_msg_id) { if (data.update?.top_msg_id) {

View File

@ -3508,7 +3508,11 @@ export default {
break; break;
case 'updateTopMsg': case 'updateTopMsg':
// 更新置顶 // 更新置顶
dispatch("saveDialog", {id: data.dialog_id, top_msg_id: data.top_msg_id}) dispatch("saveDialog", {
id: data.dialog_id,
top_msg_id: data.top_msg_id,
top_userid: data.top_userid
})
dispatch("getDialogMsgTop", dialog_id) dispatch("getDialogMsgTop", dialog_id)
break; break;
} }