mirror of
https://github.com/kuaifan/dootask.git
synced 2026-02-13 10:44:00 +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
|
* @apiVersion 1.0.0
|
||||||
* @apiGroup dialog
|
* @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 {Number} ret 返回状态码(1正确、0错误)
|
||||||
* @apiSuccess {String} msg 返回信息(错误描述)
|
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||||
* @apiSuccess {Object} data 返回数据
|
* @apiSuccess {Object} data 返回数据
|
||||||
*/
|
*/
|
||||||
public function unread()
|
public function beyond()
|
||||||
{
|
{
|
||||||
$user = User::auth();
|
$user = User::auth();
|
||||||
//
|
//
|
||||||
$beforeAt = Request::input('before_at');
|
$unreadAt = Request::input('unread_at');
|
||||||
if (empty($beforeAt)) {
|
$todoAt = Request::input('todo_at');
|
||||||
return Base::retError('参数错误');
|
|
||||||
}
|
|
||||||
//
|
//
|
||||||
$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);
|
return Base::retSuccess('success', $data);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -103,31 +103,70 @@ class WebSocketDialog extends AbstractModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取未读对话列表
|
* 列表外的未读对话 和 列表外的待办对话
|
||||||
* @param $userid
|
* @param $userid
|
||||||
* @param $beforeAt
|
* @param $unreadAt
|
||||||
* @param $take
|
* @param $todoAt
|
||||||
* @return WebSocketDialog[]
|
* @return WebSocketDialog[]
|
||||||
*/
|
*/
|
||||||
public static function getDialogUnread($userid, $beforeAt, $take = 20)
|
public static function getDialogBeyond($userid, $unreadAt, $todoAt)
|
||||||
{
|
{
|
||||||
DB::statement("SET SQL_MODE=''");
|
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'])
|
$ids = [];
|
||||||
->join('web_socket_dialog_users as u', 'web_socket_dialogs.id', '=', 'u.dialog_id')
|
$array = [];
|
||||||
->join('web_socket_dialog_msg_reads as r', 'web_socket_dialogs.id', '=', 'r.dialog_id')
|
if ($unreadAt) {
|
||||||
->where('u.userid', $userid)
|
// 未读对话
|
||||||
->where('r.userid', $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'])
|
||||||
->where('r.silence', 0)
|
->join('web_socket_dialog_users as u', 'web_socket_dialogs.id', '=', 'u.dialog_id')
|
||||||
->where('r.read_at')
|
->join('web_socket_dialog_msg_reads as r', 'web_socket_dialogs.id', '=', 'r.dialog_id')
|
||||||
->where('u.last_at', '>', $beforeAt)
|
->where('u.userid', $userid)
|
||||||
->groupBy('u.dialog_id')
|
->where('r.userid', $userid)
|
||||||
->take(min(100, $take))
|
->where('r.read_at')
|
||||||
->get();
|
->where('u.last_at', '<', $unreadAt)
|
||||||
$list->transform(function (WebSocketDialog $item) use ($userid) {
|
->groupBy('u.dialog_id')
|
||||||
return $item->formatData($userid);
|
->take(20)
|
||||||
});
|
->get();
|
||||||
//
|
$list->transform(function (WebSocketDialog $item) use ($userid, &$ids, &$array) {
|
||||||
return $list;
|
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)
|
dispatch("getDialogs", requestData).then(resolve).catch(reject)
|
||||||
} else {
|
} else {
|
||||||
resolve()
|
resolve()
|
||||||
dispatch("getDialogUnreads").catch(() => {})
|
dispatch("getDialogBeyonds")
|
||||||
}
|
}
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
console.warn(e);
|
console.warn(e);
|
||||||
@ -2559,30 +2559,38 @@ export default {
|
|||||||
* @param dispatch
|
* @param dispatch
|
||||||
* @returns {Promise<unknown>}
|
* @returns {Promise<unknown>}
|
||||||
*/
|
*/
|
||||||
getDialogUnreads({state, dispatch}) {
|
async getDialogBeyonds({state, dispatch}) {
|
||||||
return new Promise(async resolve => {
|
const key = await $A.IDBString("dialogBeyond")
|
||||||
const key = await $A.IDBString("dialogUnread")
|
const val = $A.formatDate("Y-m-d H")
|
||||||
const val = "v2:" + $A.formatDate("Y-m-d")
|
if (key == val) {
|
||||||
if (key == val) {
|
return // 一小时取一次
|
||||||
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)
|
}).then(({data}) => {
|
||||||
//
|
dispatch("saveDialog", data);
|
||||||
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()
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user