Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function get_more(timestamp) {
- return await $.get('/convo/' + timestamp.toISOString());
- }
- async function get_all_convos() {
- convos = [];
- ts = (new Date());
- x = await get_more(ts);
- convos = convos.concat(x);
- while (true) {
- console.log(convos);
- last = x[x.length-1]
- if (!last) {
- return convos;
- }
- oldest_ts = new Date(last.message[last.message.length-1].sent);
- x = await get_more(oldest_ts);
- convos = convos.concat(x);
- }
- return convos;
- }
- // exclude can be a list of usernames (['user1', 'user2'], etc.)
- function exclude_from_clear(c, exclude=[]) {
- for (user of exclude) {
- if (c.participants.includes(user)) {return false;}
- }
- return true;
- }
- all_convos = await get_all_convos();
- convos_to_clear = all_convos.filter(c => exclude_from_clear(c));
- for (c of convos_to_clear) {
- console.log('Clearing ', c);
- $.post('/convo/clear', {id: c._id});
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement