mirror of
https://github.com/kuaifan/dootask.git
synced 2026-01-04 10:58:18 +00:00
no message
This commit is contained in:
parent
e74aeb9393
commit
b209040978
@ -673,7 +673,11 @@ class DialogController extends AbstractController
|
||||
* @apiGroup dialog
|
||||
* @apiName msg__read
|
||||
*
|
||||
* @apiParam {Number} id 消息ID(组)
|
||||
* @apiParam {Object} id 消息ID(组)
|
||||
* - 1、多个ID用逗号分隔,如:1,2,3
|
||||
* - 2、另一种格式:{"id": "[会话ID]"},如:{"2": 0, "3": 10}
|
||||
* -- 会话ID:标记id之后的消息已读
|
||||
* -- 其他:标记已读
|
||||
*
|
||||
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
||||
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||
@ -684,17 +688,31 @@ class DialogController extends AbstractController
|
||||
$user = User::auth();
|
||||
//
|
||||
$id = Request::input('id');
|
||||
$ids = Base::explodeInt($id);
|
||||
$ids = $id && is_array($id) ? $id : array_fill_keys(Base::explodeInt($id), 'r');
|
||||
//
|
||||
$dialogIds = [];
|
||||
WebSocketDialogMsg::whereIn('id', $ids)->chunkById(20, function($list) use ($user, &$dialogIds) {
|
||||
$markIds = [];
|
||||
WebSocketDialogMsg::whereIn('id', array_keys($ids))->chunkById(100, function($list) use ($ids, $user, &$dialogIds, &$markIds) {
|
||||
/** @var WebSocketDialogMsg $item */
|
||||
foreach ($list as $item) {
|
||||
$item->readSuccess($user->userid);
|
||||
$dialogIds[$item->dialog_id] = $item->dialog_id;
|
||||
if ($ids[$item->id] == $item->dialog_id) {
|
||||
$markIds[$item->dialog_id] = min($item->id, $markIds[$item->dialog_id] ?? 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
//
|
||||
foreach ($markIds as $dialogId => $msgId) {
|
||||
WebSocketDialogMsgRead::whereDialogId($dialogId)
|
||||
->whereUserid($user->userid)
|
||||
->whereReadAt(null)
|
||||
->where('msg_id', '>=', $msgId)
|
||||
->chunkById(100, function ($list) {
|
||||
WebSocketDialogMsgRead::onlyMarkRead($list);
|
||||
});
|
||||
}
|
||||
//
|
||||
$data = [];
|
||||
$dialogUsers = WebSocketDialogUser::with(['webSocketDialog'])->whereUserid($user->userid)->whereIn('dialog_id', array_values($dialogIds))->get();
|
||||
foreach ($dialogUsers as $dialogUser) {
|
||||
|
||||
43
resources/assets/js/store/actions.js
vendored
43
resources/assets/js/store/actions.js
vendored
@ -2677,9 +2677,9 @@ export default {
|
||||
} else {
|
||||
state.dialogIns.push(data);
|
||||
}
|
||||
// 会话消息总数量大于1500时只保留最近打开的30个会话
|
||||
const msg_max = 1500
|
||||
const retain_num = 30
|
||||
// 会话消息总数量大于5000时只保留最近打开的50个会话
|
||||
const msg_max = 5000
|
||||
const retain_num = 500
|
||||
state.dialogHistory = state.dialogHistory.filter(id => id != data.dialog_id)
|
||||
state.dialogHistory.push(data.dialog_id)
|
||||
if (state.dialogMsgs.length > msg_max && state.dialogHistory.length > retain_num) {
|
||||
@ -3012,7 +3012,7 @@ export default {
|
||||
requestData.page = 1
|
||||
}
|
||||
if (typeof requestData.pagesize === "undefined") {
|
||||
requestData.pagesize = 20
|
||||
requestData.pagesize = 50
|
||||
}
|
||||
if (typeof requestData.latest_id === "undefined") {
|
||||
requestData.latest_id = state.loadDialogLatestId
|
||||
@ -3058,7 +3058,7 @@ export default {
|
||||
if (data.userid == state.userId) return;
|
||||
if (data.read_at) return;
|
||||
data.read_at = $A.formatDate();
|
||||
state.readWaitData[data.id] = data.id;
|
||||
state.readWaitData[data.id] = state.readWaitData[data.id] || 0
|
||||
//
|
||||
const dialog = state.cacheDialogs.find(({id}) => id == data.dialog_id);
|
||||
if (dialog) {
|
||||
@ -3075,8 +3075,8 @@ export default {
|
||||
}
|
||||
}
|
||||
if (mark) {
|
||||
state.readEndMark[data.dialog_id] = Math.max(data.id, $A.runNum(state.readEndMark[data.dialog_id]))
|
||||
dispatch("saveDialog", dialog)
|
||||
state.readWaitData[data.id] = data.dialog_id
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3087,34 +3087,33 @@ export default {
|
||||
if (state.userId === 0) {
|
||||
return;
|
||||
}
|
||||
const ids = Object.values(state.readWaitData);
|
||||
state.readWaitData = {};
|
||||
if (ids.length === 0) {
|
||||
if (Object.values(state.readWaitData).length === 0) {
|
||||
return
|
||||
}
|
||||
const ids = $A.cloneJSON(state.readWaitData);
|
||||
state.readWaitData = {};
|
||||
//
|
||||
dispatch("call", {
|
||||
method: 'post',
|
||||
url: 'dialog/msg/read',
|
||||
data: {
|
||||
id: ids.join(",")
|
||||
id: ids
|
||||
}
|
||||
}).then(({data}) => {
|
||||
for (const id in ids) {
|
||||
if (ids.hasOwnProperty(id) && /^\d+$/.test(ids[id])) {
|
||||
state.dialogMsgs.some(item => {
|
||||
if (item.dialog_id == ids[id] && item.id >= id) {
|
||||
item.read_at = $A.formatDate()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
dispatch("saveDialog", data)
|
||||
}).catch(_ => {
|
||||
ids.some(id => {
|
||||
state.readWaitData[id] = id;
|
||||
})
|
||||
state.readWaitData = ids;
|
||||
}).finally(_ => {
|
||||
state.readLoadNum++
|
||||
//
|
||||
for (let dialog_id in state.readEndMark) {
|
||||
dispatch("dialogMsgMark", {
|
||||
type: 'read',
|
||||
dialog_id,
|
||||
after_msg_id: state.readEndMark[dialog_id],
|
||||
})
|
||||
}
|
||||
state.readEndMark = {}
|
||||
});
|
||||
}, 50);
|
||||
},
|
||||
|
||||
1
resources/assets/js/store/state.js
vendored
1
resources/assets/js/store/state.js
vendored
@ -130,7 +130,6 @@ export default {
|
||||
readLoadNum: 0,
|
||||
readTimeout: null,
|
||||
readWaitData: {},
|
||||
readEndMark: {},
|
||||
|
||||
// 文件
|
||||
fileLists: [],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user