|
|
|
@ -14,6 +14,25 @@ export const parseHTMLString = (html, needText = false) => {
|
|
|
|
|
return needText ? { html, bodyContent, bodyText } : bodyContent
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const EMAIL_CHANNEL_NAME = 'mailbox_changes';
|
|
|
|
|
let emailChangesChannel = null;
|
|
|
|
|
export function getEmailChangesChannel() {
|
|
|
|
|
if (!emailChangesChannel) {
|
|
|
|
|
emailChangesChannel = new BroadcastChannel(EMAIL_CHANNEL_NAME)
|
|
|
|
|
}
|
|
|
|
|
return emailChangesChannel
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 通知邮件列表数据更新
|
|
|
|
|
const notifyMailboxUpdate = (payload) => {
|
|
|
|
|
const notificationPayload = payload
|
|
|
|
|
// - 多个tab
|
|
|
|
|
const channel = getEmailChangesChannel()
|
|
|
|
|
channel.postMessage(notificationPayload)
|
|
|
|
|
// - 当前tab
|
|
|
|
|
internalEventEmitter.emit(EMAIL_CHANNEL_NAME, notificationPayload)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取顾问签名
|
|
|
|
|
* @param {object} { opi_sn }
|
|
|
|
@ -178,7 +197,7 @@ export const getEmailDirAction = async (params = { opi_sn: '' }, retOrder=false)
|
|
|
|
|
const orderList = groupBy(result, row => `${row.IsTrue}`)?.['0'] || [];
|
|
|
|
|
return retOrder !== false ? orderList : { [`${params.opi_sn}`]: retTree }
|
|
|
|
|
};
|
|
|
|
|
export const getMailboxCountAction = async (params = { opi_sn: '' }, update = false) => {
|
|
|
|
|
export const getMailboxCountAction = async (params = { opi_sn: '' }, update = true) => {
|
|
|
|
|
const defaultParams = {
|
|
|
|
|
opi_sn: 0,
|
|
|
|
|
// date1: dayjs().subtract(1, 'year').startOf('year').format(DATE_FORMAT),
|
|
|
|
@ -190,7 +209,7 @@ export const getMailboxCountAction = async (params = { opi_sn: '' }, update = fa
|
|
|
|
|
// 更新数量
|
|
|
|
|
if (update !== false) {
|
|
|
|
|
const readCacheDir = await readIndexDB(Number(params.opi_sn), 'dirs', 'mailbox');
|
|
|
|
|
const mailboxDir = isEmpty(readCacheDir) ? [] : readCacheDir.tree.filter(node => node._raw.IsTrue === 1);
|
|
|
|
|
const mailboxDir = isEmpty(readCacheDir) ? [] : readCacheDir.tree.filter(node => node?._raw?.IsTrue === 1);
|
|
|
|
|
const _MapDir = new Map(mailboxDir.map((obj) => [obj.key, obj]))
|
|
|
|
|
Object.keys(result).map(dirKey => {
|
|
|
|
|
_MapDir.set(Number(dirKey), {..._MapDir.get(Number(dirKey)), count: result[dirKey]});
|
|
|
|
@ -202,6 +221,7 @@ export const getMailboxCountAction = async (params = { opi_sn: '' }, update = fa
|
|
|
|
|
})
|
|
|
|
|
const _newRoot = Array.from(_MapRoot.values())
|
|
|
|
|
writeIndexDB([{ key: Number(params.opi_sn), tree: _newRoot }], 'dirs', 'mailbox')
|
|
|
|
|
notifyMailboxUpdate({ type: 'dirs', key: Number(params.opi_sn) })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
@ -315,7 +335,7 @@ export const getRootMailboxDirAction = async ({ opi_sn = 0, userIdStr = '' } = {
|
|
|
|
|
getTodoOrdersAction({ opisn: userIdStr || String(opi_sn), otype: 'today' }),
|
|
|
|
|
...(userIdStr.split(',').map(_opi => getEmailDirAction({ opi_sn: _opi }))),
|
|
|
|
|
])
|
|
|
|
|
const mailBoxCount = await Promise.all(userIdStr.split(',').map(_opi => getMailboxCountAction({ opi_sn: _opi })));
|
|
|
|
|
const mailBoxCount = await Promise.all(userIdStr.split(',').map(_opi => getMailboxCountAction({ opi_sn: _opi }, false)));
|
|
|
|
|
const mailboxDirCountByOPI = mailBoxCount.reduce((a, c) => ({ ...a, ...c, }), {})
|
|
|
|
|
const mailboxDirByOPI = mailboxDir.reduce((a, c) => ({ ...a, ...(Object.keys(c).reduce((a, opi) => ({...a, [opi]: c[`${opi}`].map((dir) => ({ ...dir, count: mailboxDirCountByOPI[opi][`${dir.key}`] })) }), {} )) }), {})
|
|
|
|
|
const rootTree = Object.keys(stickyTree).map((opi) => ({ key: Number(opi), tree: [...stickyTree[opi], ...(mailboxDirByOPI?.[opi] || [])] }))
|
|
|
|
@ -355,15 +375,16 @@ export const queryEmailListAction = async ({ opi_sn = '', pagesize = 10, last_id
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const EMAIL_CHANNEL_NAME = 'mailbox_changes';
|
|
|
|
|
let emailChangesChannel = null;
|
|
|
|
|
export function getEmailChangesChannel() {
|
|
|
|
|
if (!emailChangesChannel) {
|
|
|
|
|
emailChangesChannel = new BroadcastChannel(EMAIL_CHANNEL_NAME)
|
|
|
|
|
const removeFromCurrentList = async (params) => {
|
|
|
|
|
const readRow0 = await readIndexDB(params.mai_sn_list[0], 'listrow', 'mailbox')
|
|
|
|
|
const listKey = readRow0?.data?.listKey || ''
|
|
|
|
|
if (listKey) {
|
|
|
|
|
const readCache = await readIndexDB(listKey, 'maillist', 'mailbox')
|
|
|
|
|
const updatedMailList = readCache.data.filter((mai_sn) => !params.mai_sn_list.includes(mai_sn))
|
|
|
|
|
writeIndexDB([{ key: listKey, data: updatedMailList }], 'maillist', 'mailbox')
|
|
|
|
|
notifyMailboxUpdate({ type: 'listrow', listKey, affectKeys: params.mai_sn_list })
|
|
|
|
|
}
|
|
|
|
|
return emailChangesChannel
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const updateEmailKeyMap = { read: 'MOI_ReadState' };
|
|
|
|
|
const updateEmailKeyFun = {
|
|
|
|
|
read: async (params) => {
|
|
|
|
@ -374,31 +395,13 @@ const updateEmailKeyFun = {
|
|
|
|
|
'listrow',
|
|
|
|
|
'mailbox',
|
|
|
|
|
)
|
|
|
|
|
const listKey = readCache.get(params.mai_sn_list[0])?.data?.listKey || '';
|
|
|
|
|
// 通知邮件列表数据更新
|
|
|
|
|
const listKey = readCache.get(params.mai_sn_list[0])?.data?.listKey || '';
|
|
|
|
|
const notificationPayload = { type: 'listrow', listKey, affectKeys: params.mai_sn_list }
|
|
|
|
|
// - 多个tab
|
|
|
|
|
const channel = getEmailChangesChannel()
|
|
|
|
|
channel.postMessage(notificationPayload)
|
|
|
|
|
// - 当前tab
|
|
|
|
|
internalEventEmitter.emit(EMAIL_CHANNEL_NAME, notificationPayload);
|
|
|
|
|
notifyMailboxUpdate(notificationPayload)
|
|
|
|
|
},
|
|
|
|
|
processed: async (params) => {
|
|
|
|
|
const readRow0 = await readIndexDB(params.mai_sn_list[0], 'listrow', 'mailbox')
|
|
|
|
|
const listKey = readRow0?.data?.listKey || '';
|
|
|
|
|
if (listKey) {
|
|
|
|
|
const readCache = await readIndexDB(listKey, 'maillist', 'mailbox')
|
|
|
|
|
const updatedMailList = readCache.data.filter(mai_sn => !params.mai_sn_list.includes(mai_sn));
|
|
|
|
|
writeIndexDB([{ key: listKey, data: updatedMailList }], 'maillist', 'mailbox')
|
|
|
|
|
// 通知邮件列表数据更新
|
|
|
|
|
const notificationPayload = { type: 'listrow', listKey, affectKeys: params.mai_sn_list }
|
|
|
|
|
// - 多个tab
|
|
|
|
|
const channel = getEmailChangesChannel()
|
|
|
|
|
channel.postMessage(notificationPayload)
|
|
|
|
|
// - 当前tab
|
|
|
|
|
internalEventEmitter.emit(EMAIL_CHANNEL_NAME, notificationPayload);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
processed: removeFromCurrentList,
|
|
|
|
|
delete: removeFromCurrentList
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 更新邮件属性
|
|
|
|
@ -414,6 +417,7 @@ export const updateEmailAction = async (params = { opi_sn: 0, mai_sn_list: [], s
|
|
|
|
|
updateFun(params)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
getMailboxCountAction({ opi_sn: params.opi_sn });
|
|
|
|
|
return errcode === 0 ? result : {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|