no message

This commit is contained in:
kuaifan 2021-06-06 16:51:26 +08:00
parent c9bcf6ac83
commit 4a526ecefb
8 changed files with 53 additions and 29 deletions

View File

@ -125,8 +125,14 @@ class WebSocketService implements WebSocketHandlerInterface
* 已阅消息
*/
case 'readMsg':
$dialogMsg = WebSocketDialogMsg::whereId(intval($data['id']))->first();
$dialogMsg && $dialogMsg->readSuccess($this->getUserid($frame->fd));
$ids = is_array($data['id']) ? $data['id'] : [$data['id']];
$userid = $this->getUserid($frame->fd);
$list = WebSocketDialogMsg::whereIn('id', $ids)->get();
if ($list->isNotEmpty()) {
foreach ($list as $item) {
$item->readSuccess($userid);
}
}
return;
}
//

View File

@ -36,7 +36,7 @@ class LineTask extends AbstractTask
$fd[] = $ws->fd;
}
if ($fd) {
PushTask::pushIgnoreFail([
PushTask::push([
'fd' => $fd,
'msg' => [
'type' => 'line',

View File

@ -69,21 +69,19 @@ class PushTask extends AbstractTask
*/
public static function resendTmpMsgForUserid($userid)
{
$lists = WebSocketTmpMsg::whereCreateId($userid)
WebSocketTmpMsg::whereCreateId($userid)
->whereSend(0)
->where('created_at', '>', Carbon::now()->subMinute()) // 1分钟内添加的数据
->orderBy('id')
->get();
if ($lists->isNotEmpty()) {
foreach ($lists as $item) {
self::push([
'tmp_msg_id' => $item->id,
'userid' => $userid,
'msg' => Base::json2array($item->msg),
]);
}
}
->chunk(100, function($list) use ($userid) {
foreach ($list as $item) {
self::push([
'tmp_msg_id' => $item->id,
'userid' => $userid,
'msg' => Base::json2array($item->msg),
]);
}
});
}
/**
@ -93,7 +91,7 @@ class PushTask extends AbstractTask
* @param int $delay 延迟推送时间默认1秒$key填写时有效
* @param bool $addFail 失败后是否保存到临时表,等上线后继续发送
*/
public static function push(array $lists, $key = '', $delay = 1, $addFail = true)
public static function push(array $lists, $key = '', $delay = 1, $addFail = false)
{
if (!is_array($lists) || empty($lists)) {
return;
@ -169,11 +167,11 @@ class PushTask extends AbstractTask
}
/**
* 推送消息(忽略错误
* 推送消息(出错后保存临时表,上线后尝试重新发送
* @param array $lists 消息列表
*/
public static function pushIgnoreFail(array $lists)
public static function pushR(array $lists)
{
self::push($lists, '', 1, false);
self::push($lists, '', 1, true);
}
}

View File

@ -79,7 +79,7 @@ export default {
},
mounted() {
this.parsingData()
this.parsingRead()
},
computed: {
@ -96,7 +96,7 @@ export default {
watch: {
msgData() {
this.parsingData()
this.parsingRead()
}
},
@ -115,14 +115,11 @@ export default {
});
},
parsingData() {
parsingRead() {
const {userid, r, id} = this.msgData;
if (userid == this.userId) return;
if ($A.isJson(r) && r.read_at) return;
this.$store.commit('wsSend', {
type: 'readMsg',
data: {id}
});
this.$store.commit('wsMsgRead', id);
},
formatTime(date) {

View File

@ -24,7 +24,7 @@
</ul>
</div>
</ScrollerY>
<div :class="['dialog-footer', msgNew > 0 ? 'newmsg' : '']">
<div :class="['dialog-footer', msgNew > 0 && dialogMsgList.length > 0 ? 'newmsg' : '']">
<div class="dialog-newmsg" @click="goNewBottom">{{$L('' + msgNew + '条新消息')}}</div>
<DragInput class="dialog-input" v-model="msgText" type="textarea" :rows="1" :autosize="{ minRows: 1, maxRows: 3 }" :maxlength="255" @on-keydown="chatKeydown" @on-input-paste="pasteDrag" :placeholder="$L('输入消息...')" />
<DialogUpload

View File

@ -1,3 +1,5 @@
import state from "./state";
export default {
/**
* 切换Boolean变量
@ -419,6 +421,25 @@ export default {
}
},
/**
* 发送已阅消息
* @param state
* @param msgId
*/
wsMsgRead(state, msgId) {
state.wsReadWaitList.push(msgId);
clearTimeout(state.wsReadTimeout);
state.wsReadTimeout = setTimeout(() => {
this.commit('wsSend', {
type: 'readMsg',
data: {
id: $A.cloneJSON(state.wsReadWaitList)
}
});
state.wsReadWaitList = [];
}, 10);
},
/**
* 监听消息
* @param state

View File

@ -172,6 +172,8 @@ state.wsMsg = {};
state.wsCall = {};
state.wsTimeout = null;
state.wsListener = {};
state.wsReadTimeout = null;
state.wsReadWaitList = [];
// 项目信息
state.projectLoad = 0;

View File

@ -1119,8 +1119,8 @@ body {
}
.dialog-num {
position: absolute;
top: 12px;
left: 38px;
top: 10px;
left: 42px;
font-size: 12px;
.ivu-badge-count {
height: 18px;