mirror of
https://github.com/pavlobu/deskreen.git
synced 2025-05-18 16:30:10 -07:00
24 lines
690 B
TypeScript
24 lines
690 B
TypeScript
/*
|
|
* original JS code from darkwire.io
|
|
* translated to typescript for Deskreen app
|
|
* */
|
|
import getStore from './store';
|
|
|
|
export default async function pollForInactiveRooms() {
|
|
const store = getStore();
|
|
const rooms = (await store.getAll('rooms')) || {};
|
|
|
|
Object.keys(rooms).forEach(async (roomId) => {
|
|
const room = JSON.parse(rooms[roomId]);
|
|
const timeSinceUpdatedInSeconds = (Date.now() - room.updatedAt) / 1000;
|
|
const timeSinceUpdatedInDays = Math.round(
|
|
timeSinceUpdatedInSeconds / 60 / 60 / 24
|
|
);
|
|
if (timeSinceUpdatedInDays > 7) {
|
|
await store.del('rooms', roomId);
|
|
}
|
|
});
|
|
|
|
setTimeout(pollForInactiveRooms, 1000 * 60 * 60); // every hour
|
|
}
|