Commit 477324de authored by Daniel García Moreno's avatar Daniel García Moreno

Long polling instead of sync loop

parent 2ca943db
......@@ -20,10 +20,7 @@ pub fn sync(bk: &Backend) -> Result<(), Error> {
let userid = bk.data.lock().unwrap().user_id.clone();
let mut params: Vec<(&str, String)> = vec![];
let timeout = 120;
params.push(("full_state", strn!("false")));
params.push(("timeout", strn!("30000")));
if since.is_empty() {
let filter = format!("{{
......@@ -43,8 +40,10 @@ pub fn sync(bk: &Backend) -> Result<(), Error> {
}}", globals::PAGE_LIMIT);
params.push(("filter", strn!(filter)));
params.push(("timeout", strn!("0")));
} else {
params.push(("since", since.clone()));
params.push(("timeout", strn!("30000")));
}
let baseu = bk.get_base_url()?;
......@@ -56,7 +55,7 @@ pub fn sync(bk: &Backend) -> Result<(), Error> {
let attrs = json!(null);
thread::spawn(move || {
match json_q("get", &url, &attrs, timeout) {
match json_q("get", &url, &attrs, 0) {
Ok(r) => {
let next_batch = String::from(r["next_batch"].as_str().unwrap_or(""));
if since.is_empty() {
......
......@@ -236,10 +236,6 @@ impl AppOp {
self.roomlist.set_bold(r, false);
}
pub fn sync_error(&mut self) {
self.syncing = false;
}
pub fn set_state(&mut self, state: AppState) {
self.state = state;
......@@ -589,6 +585,12 @@ impl AppOp {
pub fn synced(&mut self, since: Option<String>) {
self.syncing = false;
self.since = since;
self.sync();
}
pub fn sync_error(&mut self) {
self.syncing = false;
self.sync();
}
pub fn set_rooms(&mut self, rooms: &Vec<Room>, def: Option<Room>) {
......@@ -1773,7 +1775,6 @@ impl App {
OP = Some(op.clone());
}
sync_loop(op.clone());
backend_loop(rx);
appop_loop(irx);
......@@ -2219,14 +2220,6 @@ impl App {
}
}
fn sync_loop(op: Arc<Mutex<AppOp>>) {
// Sync loop every 3 seconds
gtk::timeout_add(1000, move || {
op.lock().unwrap().sync();
gtk::Continue(true)
});
}
fn backend_loop(rx: Receiver<BKResponse>) {
thread::spawn(move || {
loop {
......@@ -2236,6 +2229,9 @@ fn backend_loop(rx: Receiver<BKResponse>) {
Err(RecvError) => { break; }
Ok(BKResponse::Token(uid, _)) => {
APPOP!(bk_login, (uid));
// after login
APPOP!(sync);
}
Ok(BKResponse::Logout) => {
APPOP!(bk_logout);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment