perf: 支持会话自己

This commit is contained in:
kuaifan 2022-05-25 23:06:42 +08:00
parent 3ce2ec0a46
commit 1d8b4ba83f
7 changed files with 48 additions and 41 deletions

View File

@ -111,8 +111,8 @@ class DialogController extends AbstractController
$user = User::auth(); $user = User::auth();
// //
$userid = intval(Request::input('userid')); $userid = intval(Request::input('userid'));
if ($userid == $user->userid) { if (empty($userid)) {
return Base::retError('不能对话自己'); return Base::retError('错误的会话');
} }
// //
$dialog = WebSocketDialog::checkUserDialog($user->userid, $userid); $dialog = WebSocketDialog::checkUserDialog($user->userid, $userid);

View File

@ -76,6 +76,9 @@ class WebSocketDialog extends AbstractModel
switch ($this->type) { switch ($this->type) {
case "user": case "user":
$dialog_user = $builder->where('userid', '!=', $userid)->first(); $dialog_user = $builder->where('userid', '!=', $userid)->first();
if ($dialog_user->userid === 0) {
$dialog_user->userid = $userid;
}
$this->name = User::userid2nickname($dialog_user->userid); $this->name = User::userid2nickname($dialog_user->userid);
$this->dialog_user = $dialog_user; $this->dialog_user = $dialog_user;
break; break;
@ -300,6 +303,9 @@ class WebSocketDialog extends AbstractModel
*/ */
public static function checkUserDialog($userid, $userid2) public static function checkUserDialog($userid, $userid2)
{ {
if ($userid == $userid2) {
$userid2 = 0;
}
$dialogUser = self::select(['web_socket_dialogs.*']) $dialogUser = self::select(['web_socket_dialogs.*'])
->join('web_socket_dialog_users as u1', 'web_socket_dialogs.id', '=', 'u1.dialog_id') ->join('web_socket_dialog_users as u1', 'web_socket_dialogs.id', '=', 'u1.dialog_id')
->join('web_socket_dialog_users as u2', 'web_socket_dialogs.id', '=', 'u2.dialog_id') ->join('web_socket_dialog_users as u2', 'web_socket_dialogs.id', '=', 'u2.dialog_id')

View File

@ -194,14 +194,16 @@
}, },
'user.online'(val) { 'user.online'(val) {
if (val) { if (val || this.userId === this.userid) {
this.$emit('update:online', true) this.$emit('update:online', true)
} else { } else {
const now = $A.Time() const now = $A.Time()
const line = $A.Time(this.user.line_at) const line = $A.Time(this.user.line_at)
const seconds = now - line const seconds = now - line
let stats = '最后在线于很久以前'; let stats = '最后在线于很久以前';
if (seconds < 3600) { if (seconds < 60) {
stats = `最后在线于刚刚`
} else if (seconds < 3600) {
stats = `最后在线于 ${Math.floor(seconds / 60)} 分钟前` stats = `最后在线于 ${Math.floor(seconds / 60)} 分钟前`
} else if (seconds < 3600 * 6) { } else if (seconds < 3600 * 6) {
stats = `最后在线于 ${Math.floor(seconds / 3600)} 小时前` stats = `最后在线于 ${Math.floor(seconds / 3600)} 小时前`

View File

@ -50,33 +50,35 @@
<div v-if="timeShow" class="time" @click="timeShow=false">{{msgData.created_at}}</div> <div v-if="timeShow" class="time" @click="timeShow=false">{{msgData.created_at}}</div>
<div v-else class="time" :title="msgData.created_at" @click="timeShow=true">{{$A.formatTime(msgData.created_at)}}</div> <div v-else class="time" :title="msgData.created_at" @click="timeShow=true">{{$A.formatTime(msgData.created_at)}}</div>
<div v-if="msgData.send > 1 || dialogType === 'group'" class="percent" @click="openReadPercentage"> <template v-if="!hiddenPercentage">
<EPopover <div v-if="msgData.send > 1 || dialogType === 'group'" class="percent" @click="openReadPercentage">
v-model="popperShow" <EPopover
ref="percent" v-model="popperShow"
popper-class="dialog-wrapper-read-poptip" ref="percent"
placement="left-end"> popper-class="dialog-wrapper-read-poptip"
<div class="read-poptip-content"> placement="left-end">
<ul class="read overlay-y"> <div class="read-poptip-content">
<li class="read-title"><em>{{ readList.length }}</em>{{ $L('已读') }}</li> <ul class="read overlay-y">
<li v-for="item in readList"> <li class="read-title"><em>{{ readList.length }}</em>{{ $L('已读') }}</li>
<UserAvatar :userid="item.userid" :size="26" showName/> <li v-for="item in readList">
</li> <UserAvatar :userid="item.userid" :size="26" showName/>
</ul> </li>
<ul class="unread overlay-y"> </ul>
<li class="read-title"><em>{{ unreadList.length }}</em>{{ $L('未读') }}</li> <ul class="unread overlay-y">
<li v-for="item in unreadList"> <li class="read-title"><em>{{ unreadList.length }}</em>{{ $L('未读') }}</li>
<UserAvatar :userid="item.userid" :size="26" showName/> <li v-for="item in unreadList">
</li> <UserAvatar :userid="item.userid" :size="26" showName/>
</ul> </li>
</div> </ul>
<div slot="reference"></div> </div>
</EPopover> <div slot="reference"></div>
<Loading v-if="popperLoad > 0"/> </EPopover>
<WCircle v-else :percent="msgData.percentage" :size="14"/> <Loading v-if="popperLoad > 0"/>
</div> <WCircle v-else :percent="msgData.percentage" :size="14"/>
<Icon v-else-if="msgData.percentage === 100" class="done" type="md-done-all"/> </div>
<Icon v-else class="done" type="md-checkmark"/> <Icon v-else-if="msgData.percentage === 100" class="done" type="md-done-all"/>
<Icon v-else class="done" type="md-checkmark"/>
</template>
</div> </div>
<div v-else class="dialog-foot"><Loading/></div> <div v-else class="dialog-foot"><Loading/></div>
@ -101,6 +103,10 @@ export default {
type: String, type: String,
default: '' default: ''
}, },
hiddenPercentage: {
type: Boolean,
default: false
},
}, },
data() { data() {

View File

@ -92,7 +92,7 @@
<div class="dialog-avatar"> <div class="dialog-avatar">
<UserAvatar :userid="item.userid" :tooltipDisabled="item.userid == userId" :size="30"/> <UserAvatar :userid="item.userid" :tooltipDisabled="item.userid == userId" :size="30"/>
</div> </div>
<DialogView :msg-data="item" :dialog-type="dialogData.type"/> <DialogView :msg-data="item" :dialog-type="dialogData.type" :hidden-percentage="dialogData.dialog_user.userid == userId"/>
</DynamicScrollerItem> </DynamicScrollerItem>
</template> </template>
</DynamicScroller> </DynamicScroller>

View File

@ -35,7 +35,7 @@
ref="dialogWrapper" ref="dialogWrapper"
class="dialog" > class="dialog" >
<li v-if="dialogList.length === 0" class="nothing"> <li v-if="dialogList.length === 0" class="nothing">
{{$L(dialogKey ? `没有任何与"${dialogKey}"相关的对话` : `没有任何对`)}} {{$L(dialogKey ? `没有任何与"${dialogKey}"相关的会话` : `没有任何会`)}}
</li> </li>
<li <li
v-else v-else
@ -64,7 +64,7 @@
<Tag :color="tag.color" :fade="false">{{$L(tag.text)}}</Tag> <Tag :color="tag.color" :fade="false">{{$L(tag.text)}}</Tag>
</template> </template>
<span>{{dialog.name}}</span> <span>{{dialog.name}}</span>
<Icon v-if="dialog.type == 'user' && lastMsgReadDone(dialog.last_msg)" :type="lastMsgReadDone(dialog.last_msg)"/> <Icon v-if="dialog.type == 'user' && lastMsgReadDone(dialog.last_msg) && dialog.dialog_user.userid != userId" :type="lastMsgReadDone(dialog.last_msg)"/>
<em v-if="dialog.last_at">{{$A.formatTime(dialog.last_at)}}</em> <em v-if="dialog.last_at">{{$A.formatTime(dialog.last_at)}}</em>
</div> </div>
<div class="dialog-text no-dark-content"> <div class="dialog-text no-dark-content">
@ -460,9 +460,6 @@ export default {
this.contactsData = []; this.contactsData = [];
} }
data.data.some((user) => { data.data.some((user) => {
if (user.userid === this.userId) {
return false;
}
if (this.contactsData.findIndex(item => item.userid == user.userid) === -1) { if (this.contactsData.findIndex(item => item.userid == user.userid) === -1) {
this.contactsData.push(user) this.contactsData.push(user)
} }

View File

@ -2020,10 +2020,6 @@ export default {
*/ */
openDialogUserid({state, dispatch}, userid) { openDialogUserid({state, dispatch}, userid) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
if (userid === state.userId) {
reject({msg: 'Parameter error'});
return;
}
dispatch("call", { dispatch("call", {
url: 'dialog/open/user', url: 'dialog/open/user',
data: { data: {