mirror of
https://github.com/kuaifan/dootask.git
synced 2026-02-08 23:45:35 +00:00
fix: 部分未读和待办信息不显示的情况
This commit is contained in:
parent
f5ff9a3648
commit
65db8b5703
@ -58,29 +58,33 @@ class DialogController extends AbstractController
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/dialog/unread 02. 未读对话列表
|
||||
* @api {get} api/dialog/beyond 02. 列表外对话
|
||||
*
|
||||
* @apiDescription 需要token身份
|
||||
* @apiDescription 需要token身份,列表外的未读对话 和 列表外的待办对话
|
||||
* @apiVersion 1.0.0
|
||||
* @apiGroup dialog
|
||||
* @apiName lists
|
||||
* @apiName beyond
|
||||
*
|
||||
* @apiParam {String} before_at 在这个时间之前未读的数据
|
||||
* @apiParam {String} unread_at 在这个时间之前未读的数据
|
||||
* - 格式1:2021-01-01 00:00:00
|
||||
* - 格式2:1612051200
|
||||
* @apiParam {String} todo_at 在这个时间之前待办的数据
|
||||
*
|
||||
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
||||
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||
* @apiSuccess {Object} data 返回数据
|
||||
*/
|
||||
public function unread()
|
||||
public function beyond()
|
||||
{
|
||||
$user = User::auth();
|
||||
//
|
||||
$beforeAt = Request::input('before_at');
|
||||
if (empty($beforeAt)) {
|
||||
return Base::retError('参数错误');
|
||||
}
|
||||
$unreadAt = Request::input('unread_at');
|
||||
$todoAt = Request::input('todo_at');
|
||||
//
|
||||
$data = WebSocketDialog::getDialogUnread($user->userid, Carbon::parse($beforeAt));
|
||||
$unreadAt = Carbon::parse($unreadAt)->setTimezone(config('app.timezone'));
|
||||
$todoAt = Carbon::parse($todoAt)->setTimezone(config('app.timezone'));
|
||||
//
|
||||
$data = WebSocketDialog::getDialogBeyond($user->userid, $unreadAt, $todoAt);
|
||||
//
|
||||
return Base::retSuccess('success', $data);
|
||||
}
|
||||
|
||||
@ -103,31 +103,70 @@ class WebSocketDialog extends AbstractModel
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取未读对话列表
|
||||
* 列表外的未读对话 和 列表外的待办对话
|
||||
* @param $userid
|
||||
* @param $beforeAt
|
||||
* @param $take
|
||||
* @param $unreadAt
|
||||
* @param $todoAt
|
||||
* @return WebSocketDialog[]
|
||||
*/
|
||||
public static function getDialogUnread($userid, $beforeAt, $take = 20)
|
||||
public static function getDialogBeyond($userid, $unreadAt, $todoAt)
|
||||
{
|
||||
DB::statement("SET SQL_MODE=''");
|
||||
$list = WebSocketDialog::select(['web_socket_dialogs.*', 'u.top_at', 'u.last_at', 'u.mark_unread', 'u.silence', 'u.hide', 'u.color', 'u.updated_at as user_at'])
|
||||
->join('web_socket_dialog_users as u', 'web_socket_dialogs.id', '=', 'u.dialog_id')
|
||||
->join('web_socket_dialog_msg_reads as r', 'web_socket_dialogs.id', '=', 'r.dialog_id')
|
||||
->where('u.userid', $userid)
|
||||
->where('r.userid', $userid)
|
||||
->where('r.silence', 0)
|
||||
->where('r.read_at')
|
||||
->where('u.last_at', '>', $beforeAt)
|
||||
->groupBy('u.dialog_id')
|
||||
->take(min(100, $take))
|
||||
->get();
|
||||
$list->transform(function (WebSocketDialog $item) use ($userid) {
|
||||
return $item->formatData($userid);
|
||||
});
|
||||
//
|
||||
return $list;
|
||||
$ids = [];
|
||||
$array = [];
|
||||
if ($unreadAt) {
|
||||
// 未读对话
|
||||
$list = WebSocketDialog::select(['web_socket_dialogs.*', 'u.top_at', 'u.last_at', 'u.mark_unread', 'u.silence', 'u.hide', 'u.color', 'u.updated_at as user_at'])
|
||||
->join('web_socket_dialog_users as u', 'web_socket_dialogs.id', '=', 'u.dialog_id')
|
||||
->join('web_socket_dialog_msg_reads as r', 'web_socket_dialogs.id', '=', 'r.dialog_id')
|
||||
->where('u.userid', $userid)
|
||||
->where('r.userid', $userid)
|
||||
->where('r.read_at')
|
||||
->where('u.last_at', '<', $unreadAt)
|
||||
->groupBy('u.dialog_id')
|
||||
->take(20)
|
||||
->get();
|
||||
$list->transform(function (WebSocketDialog $item) use ($userid, &$ids, &$array) {
|
||||
if (!in_array($item->id, $ids)) {
|
||||
$ids[] = $item->id;
|
||||
$array[] = $item->formatData($userid);
|
||||
}
|
||||
});
|
||||
// 标记未读会话
|
||||
$list = WebSocketDialog::select(['web_socket_dialogs.*', 'u.top_at', 'u.last_at', 'u.mark_unread', 'u.silence', 'u.hide', 'u.color', 'u.updated_at as user_at'])
|
||||
->join('web_socket_dialog_users as u', 'web_socket_dialogs.id', '=', 'u.dialog_id')
|
||||
->where('u.userid', $userid)
|
||||
->where('u.mark_unread', 1)
|
||||
->where('u.last_at', '<', $unreadAt)
|
||||
->take(20)
|
||||
->get();
|
||||
$list->transform(function (WebSocketDialog $item) use ($userid, &$ids, &$array) {
|
||||
if (!in_array($item->id, $ids)) {
|
||||
$ids[] = $item->id;
|
||||
$array[] = $item->formatData($userid);
|
||||
}
|
||||
});
|
||||
}
|
||||
if ($todoAt) {
|
||||
// 待办会话
|
||||
$list = WebSocketDialog::select(['web_socket_dialogs.*', 'u.top_at', 'u.last_at', 'u.mark_unread', 'u.silence', 'u.hide', 'u.color', 'u.updated_at as user_at'])
|
||||
->join('web_socket_dialog_users as u', 'web_socket_dialogs.id', '=', 'u.dialog_id')
|
||||
->join('web_socket_dialog_msg_todos as t', 'web_socket_dialogs.id', '=', 't.dialog_id')
|
||||
->where('u.userid', $userid)
|
||||
->where('t.userid', $userid)
|
||||
->where('t.done_at')
|
||||
->where('u.last_at', '<', $todoAt)
|
||||
->groupBy('u.dialog_id')
|
||||
->take(20)
|
||||
->get();
|
||||
$list->transform(function (WebSocketDialog $item) use ($userid, &$ids, &$array) {
|
||||
if (!in_array($item->id, $ids)) {
|
||||
$ids[] = $item->id;
|
||||
$array[] = $item->formatData($userid);
|
||||
}
|
||||
});
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
|
||||
56
resources/assets/js/store/actions.js
vendored
56
resources/assets/js/store/actions.js
vendored
@ -2544,7 +2544,7 @@ export default {
|
||||
dispatch("getDialogs", requestData).then(resolve).catch(reject)
|
||||
} else {
|
||||
resolve()
|
||||
dispatch("getDialogUnreads").catch(() => {})
|
||||
dispatch("getDialogBeyonds")
|
||||
}
|
||||
}).catch(e => {
|
||||
console.warn(e);
|
||||
@ -2559,30 +2559,38 @@ export default {
|
||||
* @param dispatch
|
||||
* @returns {Promise<unknown>}
|
||||
*/
|
||||
getDialogUnreads({state, dispatch}) {
|
||||
return new Promise(async resolve => {
|
||||
const key = await $A.IDBString("dialogUnread")
|
||||
const val = "v2:" + $A.formatDate("Y-m-d")
|
||||
if (key == val) {
|
||||
return // 一天取一次
|
||||
async getDialogBeyonds({state, dispatch}) {
|
||||
const key = await $A.IDBString("dialogBeyond")
|
||||
const val = $A.formatDate("Y-m-d H")
|
||||
if (key == val) {
|
||||
return // 一小时取一次
|
||||
}
|
||||
await $A.IDBSet("dialogBeyond", val)
|
||||
//
|
||||
const filter = (func) => {
|
||||
return state.cacheDialogs
|
||||
.filter(func)
|
||||
.sort((a, b) => {
|
||||
return $A.Date(a.last_at) - $A.Date(b.last_at);
|
||||
})
|
||||
.find(({id}) => id > 0)
|
||||
}
|
||||
const unreadDialog = filter(({unread, last_at}) => {
|
||||
return unread > 0 && last_at
|
||||
});
|
||||
const todoDialog = filter(({todo_num, last_at}) => {
|
||||
return todo_num > 0 && last_at
|
||||
});
|
||||
//
|
||||
dispatch("call", {
|
||||
url: 'dialog/beyond',
|
||||
data: {
|
||||
unread_at: unreadDialog ? unreadDialog.last_at : $A.Time(),
|
||||
todo_at: todoDialog ? todoDialog.last_at : $A.Time()
|
||||
}
|
||||
await $A.IDBSet("dialogUnread", val)
|
||||
//
|
||||
const dialog = $A.cloneJSON(state.cacheDialogs).filter(({last_at}) => last_at).sort((a, b) => {
|
||||
return $A.Date(a.last_at) - $A.Date(b.last_at);
|
||||
}).find(({id}) => id > 0);
|
||||
if (dialog) {
|
||||
dispatch("call", {
|
||||
url: 'dialog/unread',
|
||||
data: {
|
||||
before_at: dialog.last_at,
|
||||
}
|
||||
}).then(({data}) => {
|
||||
dispatch("saveDialog", data);
|
||||
});
|
||||
}
|
||||
resolve()
|
||||
})
|
||||
}).then(({data}) => {
|
||||
dispatch("saveDialog", data);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user