38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { mailInit, setMails, GMMail } from '../gmData/gmMail';
|
|
import { nowSeconds } from '../timeUtil';
|
|
const ALL_SERVER = 0;
|
|
export let gmData:any = {};
|
|
export async function init() {
|
|
gmData.mails = await mailInit();
|
|
}
|
|
|
|
export function getGmMails(updatedMailAt: number, serverId: number) {
|
|
let list = [];
|
|
let serverIds = [serverId, ALL_SERVER];
|
|
for (let serverId of serverIds) {
|
|
if (!gmData.mails.get(serverId))
|
|
continue;
|
|
gmData.mails.get(serverId).map(({updatedAt, sendTime, endTime, id, sendRoles, goods, content, gmMailType})=>{
|
|
if (updatedAt >= updatedMailAt || sendTime > updatedMailAt || endTime < nowSeconds() )
|
|
list.push({updatedAt, sendTime, endTime, id, sendRoles, goods, content, gmMailType});
|
|
});
|
|
}
|
|
return list;
|
|
}
|
|
|
|
export function getGmMailById(id: string, serverId: number) {
|
|
let gmMail;
|
|
if (!!gmData.mails.get(serverId)) {
|
|
gmMail = gmData.mails.get(serverId).get(id);
|
|
}
|
|
if (!gmMail) {
|
|
if (!!gmData.mails.get(ALL_SERVER)) {
|
|
gmMail = gmData.mails.get(ALL_SERVER).get(id);
|
|
}
|
|
}
|
|
return gmMail;
|
|
}
|
|
|
|
export function setGmMails(mails: GMMail[]) {
|
|
setMails(mails, gmData.mails);
|
|
} |