Advertisement
Guest User

Untitled

a guest
Jul 15th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.62 KB | None | 0 0
  1. #[post("/process", format="application/json", data="<sub_searches>")]
  2. fn process(mut cookies: Cookies, sub_searches: Json<SubSearches>,
  3.            search_threads: State<SearchThreads>) -> Result<(), Failure> {
  4.  
  5.     // TODO: test that this logic actually works
  6.     // TODO: start the search threads and add them to the global state
  7.     //grab token from cookies and get the email attached to that token
  8.     // TODO: prevent this from crashing when there is no cookie
  9.     let token = cookies.get_private("push_token").unwrap().to_owned();
  10.     let email = get_email(&token.value());
  11.  
  12.     //delete the previous searches attached to this user and subreddit
  13.     for sub_search in &sub_searches.subs {
  14.         match delete_sub_searches(&email, &sub_search.sub) {
  15.             Ok(_) => (),
  16.             Err(_) => return Err(Failure(Status::NotAcceptable))
  17.         };
  18.         //add all of the new searches
  19.         for search in &sub_search.searches {
  20.             add_search(&email, &sub_search.sub, &search);
  21.             let mut search_threads = search_threads.map.lock().unwrap();
  22.             if search_threads.contains_key(&email) {
  23.                 let conc_thread = search_threads.get(&email).unwrap();
  24.                 //TODO: actually do error checking
  25.                 conc_thread.lock().unwrap().send(true).unwrap();
  26.                 //TODO: move this data to a thread and get a thread working
  27.             }
  28.             let (tx, rx) = mpsc::channel::<bool>();
  29.             let tx = tx.clone();
  30.             let email_clone = email.clone();
  31.             let _result_thread = thread::spawn(move || {
  32.                 check_user_results(email_clone, rx);
  33.             });
  34.             let sender = Mutex::from(tx);
  35.             search_threads.insert(email.clone(), sender);
  36.         }
  37.         println!("{}", sub_search.sub);
  38.         println!("{:#?}", sub_search.searches);
  39.     }  
  40.     Ok(())
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement