`;
const sortedPMs: { [userid: string]: ReceivedPM[] } = {};
for (const curPM of all) {
if (!sortedPMs[curPM.sender]) sortedPMs[curPM.sender] = [];
sortedPMs[curPM.sender].push(curPM);
}
for (const k in sortedPMs) {
Utils.sortBy(sortedPMs[k], pm => -pm.time);
}
buf += `
`;
for (const pair of Utils.sortBy(Object.entries(sortedPMs), ([id]) => id)) {
const [sender, messages] = pair;
const group = Users.globalAuth.get(toID(sender));
const name = Users.getExact(sender)?.name || sender;
const id = toID(name);
buf += Utils.html`
`;
buf += Utils.html`
${group}${name}
`;
buf += `
`;
buf += `
`;
}
buf += `
`;
return buf;
}
clearOffline() {
return PM.run(statements.clearDated, [Date.now(), EXPIRY_TIME]);
}
destroy() {
void PM.destroy();
}
};
if (Config.usesqlite) {
if (!process.send) {
PM.spawn(Config.pmprocesses || 1);
// clear super old pms on startup
void PM.run(statements.clearDated, [Date.now(), EXPIRY_TIME]);
} else if (process.send && process.mainModule === module) {
global.Monitor = {
crashlog(error: Error, source = 'A private message child process', details: AnyObject | null = null) {
const repr = JSON.stringify([error.name, error.message, source, details]);
process.send!(`THROW\n@!!@${repr}\n${error.stack}`);
},
};
process.on('uncaughtException', err => {
Monitor.crashlog(err, 'A private message database process');
});
process.on('unhandledRejection', err => {
Monitor.crashlog(err as Error, 'A private message database process');
});
}
}