Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[post("/process", format="application/json", data="<sub_searches>")]
- fn process(mut cookies: Cookies, sub_searches: Json<SubSearches>,
- search_threads: State<SearchThreads>) -> Result<(), Failure> {
- // TODO: test that this logic actually works
- // TODO: start the search threads and add them to the global state
- //grab token from cookies and get the email attached to that token
- // TODO: prevent this from crashing when there is no cookie
- let token = cookies.get_private("push_token").unwrap().to_owned();
- let email = get_email(&token.value());
- //delete the previous searches attached to this user and subreddit
- for sub_search in &sub_searches.subs {
- match delete_sub_searches(&email, &sub_search.sub) {
- Ok(_) => (),
- Err(_) => return Err(Failure(Status::NotAcceptable))
- };
- //add all of the new searches
- for search in &sub_search.searches {
- add_search(&email, &sub_search.sub, &search);
- let mut search_threads = search_threads.map.lock().unwrap();
- if search_threads.contains_key(&email) {
- let conc_thread = search_threads.get(&email).unwrap();
- //TODO: actually do error checking
- conc_thread.lock().unwrap().send(true).unwrap();
- //TODO: move this data to a thread and get a thread working
- }
- let (tx, rx) = mpsc::channel::<bool>();
- let tx = tx.clone();
- let email_clone = email.clone();
- let _result_thread = thread::spawn(move || {
- check_user_results(email_clone, rx);
- });
- let sender = Mutex::from(tx);
- search_threads.insert(email.clone(), sender);
- }
- println!("{}", sub_search.sub);
- println!("{:#?}", sub_search.searches);
- }
- Ok(())
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement