Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. async function get_more(timestamp) {
  2.     return await $.get('/convo/' + timestamp.toISOString());
  3. }
  4.  
  5. async function get_all_convos() {
  6.     convos = [];
  7.     ts = (new Date());
  8.     x = await get_more(ts);
  9.     convos = convos.concat(x);
  10.     while (true) {
  11.         console.log(convos);
  12.         last = x[x.length-1]
  13.         if (!last) {
  14.             return convos;
  15.         }
  16.         oldest_ts = new Date(last.message[last.message.length-1].sent);
  17.         x = await get_more(oldest_ts);
  18.         convos = convos.concat(x);
  19.     }
  20.     return convos;
  21. }
  22.  
  23. // exclude can be a list of usernames (['user1', 'user2'], etc.)
  24. function exclude_from_clear(c, exclude=[]) {
  25.     for (user of exclude) {
  26.             if (c.participants.includes(user)) {return false;}
  27.         }
  28.     return true;
  29. }
  30.  
  31.  
  32. all_convos = await get_all_convos();
  33. convos_to_clear = all_convos.filter(c => exclude_from_clear(c));
  34. for (c of convos_to_clear) {
  35.     console.log('Clearing ', c);
  36.     $.post('/convo/clear', {id: c._id});
  37. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement