Commit 9319222e authored by Julian Sparber's avatar Julian Sparber

backend: restart sync from where fractal was closed

this speeds up the first sync when opening fractal, it stores the
next_batch value from the last sync fractal made before closing, this
way the sync can start from this point.
parent f1fcb00d
......@@ -18,7 +18,7 @@ impl AppOp {
pub fn sync(&mut self) {
if !self.syncing && self.logged_in {
self.syncing = true;
self.backend.send(BKCommand::Sync).unwrap();
self.backend.send(BKCommand::Sync(self.since.clone())).unwrap();
}
}
......
......@@ -179,8 +179,8 @@ impl Backend {
// Sync module
Ok(BKCommand::Sync) => {
let r = sync::sync(self);
Ok(BKCommand::Sync(since)) => {
let r = sync::sync(self, since);
bkerror!(r, tx, BKResponse::SyncError);
}
Ok(BKCommand::SyncForced) => {
......
......@@ -11,19 +11,25 @@ use backend::types::BKResponse;
use backend::types::Backend;
use types::Room;
pub fn sync(bk: &Backend) -> Result<(), Error> {
pub fn sync(bk: &Backend, new_since: Option<String>) -> Result<(), Error> {
let tk = bk.data.lock().unwrap().access_token.clone();
if tk.is_empty() {
return Err(Error::BackendError);
}
let since = bk.data.lock().unwrap().since.clone();
let mut since = bk.data.lock().unwrap().since.clone();
let userid = bk.data.lock().unwrap().user_id.clone();
let mut params: Vec<(&str, String)> = vec![];
params.push(("full_state", String::from("false")));
let timeout;
/* FIXME: since in backend data should be a Option, that would make this simpler */
if since.is_empty() {
if let Some(new_since) = new_since {
since = new_since;
}
}
if since.is_empty() {
let filter = format!("{{
......@@ -155,5 +161,5 @@ pub fn sync(bk: &Backend) -> Result<(), Error> {
pub fn force_sync(bk: &Backend) -> Result<(), Error> {
bk.data.lock().unwrap().since = String::from("");
sync(bk)
sync(bk, None)
}
......@@ -37,7 +37,7 @@ pub enum BKCommand {
AccountDestruction(String, String, bool),
GetAvatar,
SetUserAvatar(String),
Sync,
Sync(Option<String>),
SyncForced,
GetRoomMembers(String),
GetRoomMessages(String),
......
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