perf: 优化已读回执
This commit is contained in:
parent
7107409b1b
commit
f4e4252227
@ -70,11 +70,7 @@ class WebSocketDialogMsg extends AbstractModel
|
||||
public function getPercentageAttribute()
|
||||
{
|
||||
if (!isset($this->appendattrs['percentage'])) {
|
||||
if ($this->read > $this->send || empty($this->send)) {
|
||||
$this->appendattrs['percentage'] = 100;
|
||||
} else {
|
||||
$this->appendattrs['percentage'] = intval($this->read / $this->send * 100);
|
||||
}
|
||||
$this->generatePercentage();
|
||||
}
|
||||
return $this->appendattrs['percentage'];
|
||||
}
|
||||
@ -98,6 +94,22 @@ class WebSocketDialogMsg extends AbstractModel
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取占比
|
||||
* @param bool $increment 是否新增阅读数
|
||||
* @return int
|
||||
*/
|
||||
public function generatePercentage($increment = false) {
|
||||
if ($increment) {
|
||||
$this->increment('read');
|
||||
}
|
||||
if ($this->read > $this->send || empty($this->send)) {
|
||||
return $this->appendattrs['percentage'] = 100;
|
||||
} else {
|
||||
return $this->appendattrs['percentage'] = intval($this->read / $this->send * 100);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 标记已送达 同时 告诉发送人已送达
|
||||
* @param $userid
|
||||
@ -127,13 +139,17 @@ class WebSocketDialogMsg extends AbstractModel
|
||||
if (!$msgRead->read_at) {
|
||||
$msgRead->read_at = Carbon::now();
|
||||
$msgRead->save();
|
||||
$this->increment('read');
|
||||
$this->generatePercentage(true);
|
||||
PushTask::push([
|
||||
'userid' => $this->userid,
|
||||
'msg' => [
|
||||
'type' => 'dialog',
|
||||
'mode' => 'update',
|
||||
'data' => $this->toArray(),
|
||||
'mode' => 'readed',
|
||||
'data' => [
|
||||
'id' => $this->id,
|
||||
'read' => $this->read,
|
||||
'percentage' => $this->percentage,
|
||||
],
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
@ -127,9 +127,11 @@ class WebSocketService implements WebSocketHandlerInterface
|
||||
case 'readMsg':
|
||||
$ids = is_array($data['id']) ? $data['id'] : [$data['id']];
|
||||
$userid = $this->getUserid($frame->fd);
|
||||
$list = WebSocketDialogMsg::whereIn('id', $ids)->get();
|
||||
$list->transform(function(WebSocketDialogMsg $item) use ($userid) {
|
||||
$item->readSuccess($userid);
|
||||
WebSocketDialogMsg::whereIn('id', $ids)->chunkById(20, function($list) use ($userid) {
|
||||
/** @var WebSocketDialogMsg $item */
|
||||
foreach ($list as $item) {
|
||||
$item->readSuccess($userid);
|
||||
}
|
||||
});
|
||||
return;
|
||||
|
||||
|
@ -46,6 +46,7 @@
|
||||
<div class="time" :title="msgData.created_at">{{$A.formatTime(msgData.created_at)}}</div>
|
||||
<Poptip
|
||||
v-if="msgData.send > 1 || dialogType == 'group'"
|
||||
ref="percent"
|
||||
class="percent"
|
||||
placement="left-end"
|
||||
transfer
|
||||
@ -134,13 +135,13 @@ export default {
|
||||
}
|
||||
this.msgData._r = true;
|
||||
//
|
||||
this.$nextTick(() => {
|
||||
setTimeout(() => {
|
||||
if (!this.$el.offsetParent) {
|
||||
this.msgData._r = false;
|
||||
return
|
||||
}
|
||||
this.$store.dispatch("dialogMsgRead", this.msgData);
|
||||
})
|
||||
}, 50)
|
||||
},
|
||||
|
||||
popperShow() {
|
||||
@ -151,6 +152,7 @@ export default {
|
||||
},
|
||||
}).then(({data}) => {
|
||||
this.read_list = data;
|
||||
this.$refs.percent.updatePopper();
|
||||
}).catch(() => {
|
||||
this.read_list = [];
|
||||
});
|
||||
|
8
resources/assets/js/store/actions.js
vendored
8
resources/assets/js/store/actions.js
vendored
@ -2046,7 +2046,7 @@ export default {
|
||||
}
|
||||
});
|
||||
state.wsReadWaitList = [];
|
||||
}, 20);
|
||||
}, 50);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -2174,6 +2174,12 @@ export default {
|
||||
// 更新最后消息
|
||||
dispatch("updateDialogLastMsg", data);
|
||||
break;
|
||||
case 'readed':
|
||||
// 已读回执
|
||||
if (state.dialogMsgs.find(({id}) => id == data.id)) {
|
||||
dispatch("saveDialogMsg", data)
|
||||
}
|
||||
break;
|
||||
}
|
||||
})(msgDetail);
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user