Skip to content

Commit f72c8f8

Browse files
grabbing extra sync data from incoming/outgoing sync and passing along to the ui
1 parent 8a24a7b commit f72c8f8

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/sync/incoming.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ use ::util;
2525

2626
const SYNC_IGNORE_KEY: &'static str = "sync:incoming:ignore";
2727

28+
#[derive(Serialize, Deserialize, Debug)]
29+
pub struct SyncResponseExtra {
30+
#[serde(default)]
31+
current_size: Option<i64>,
32+
#[serde(default)]
33+
max_size: Option<i64>,
34+
}
35+
2836
/// Defines a struct for deserializing our incoming sync response
2937
#[derive(Deserialize, Debug)]
3038
struct SyncResponse {
@@ -33,6 +41,9 @@ struct SyncResponse {
3341
#[serde(default)]
3442
#[serde(deserialize_with = "::util::ser::str_i64_converter::deserialize")]
3543
sync_id: i64,
44+
/// extra data returned from the sync system
45+
#[serde(default)]
46+
extra: Option<SyncResponseExtra>,
3647
}
3748

3849
struct Handlers {
@@ -232,7 +243,7 @@ impl SyncIncoming {
232243
if !self.is_enabled() && !force { return Ok(()); }
233244

234245
// destructure our response
235-
let SyncResponse { sync_id, records } = syncdata;
246+
let SyncResponse { sync_id, records, extra } = syncdata;
236247

237248
// grab sync ids we're ignoring
238249
let ignored = self.get_ignored()?;
@@ -284,6 +295,11 @@ impl SyncIncoming {
284295
// syncs and process them
285296
messaging::app_event("sync:incoming", &())?;
286297

298+
// if we have extra sync data, send it off to the ui
299+
if let Some(extra) = extra.as_ref() {
300+
messaging::ui_event("sync:incoming:extra", extra)?;
301+
}
302+
287303
// clear out the sync ignore list
288304
match self.clear_ignored() {
289305
Ok(_) => {},

src/sync/outgoing.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use ::std::sync::{Arc, RwLock, Mutex};
22
use ::error::TResult;
33
use ::sync::{SyncConfig, Syncer};
4-
use ::sync::incoming::SyncIncoming;
4+
use ::sync::incoming::{SyncIncoming, SyncResponseExtra};
55
use ::storage::Storage;
66
use ::api::{Api, ApiReq};
77
use ::messaging;
@@ -18,6 +18,9 @@ struct SyncResponse {
1818
/// records that weren't run because they were blocked by a failure
1919
#[serde(default)]
2020
blocked: Vec<SyncRecord>,
21+
/// extra data returned from the sync system
22+
#[serde(default)]
23+
extra: Option<SyncResponseExtra>,
2124
}
2225

2326
/// Holds the state for data going from turtl -> API (outgoing sync data).
@@ -154,6 +157,11 @@ impl Syncer for SyncOutgoing {
154157
// will want to know this happened.
155158
messaging::ui_event("sync:outgoing:complete", &())?;
156159

160+
// if we have extra sync data, send it off to the ui
161+
if let Some(extra) = sync_result.extra.as_ref() {
162+
messaging::ui_event("sync:outgoing:extra", extra)?;
163+
}
164+
157165
// if we did indeed get an error while deleting our sync records,
158166
// send the first error we got back. obviously there may be more
159167
// than one, but we can only do so much here to maintain resilience.

0 commit comments

Comments
 (0)