Skip to content

Commit

Permalink
Pre-fill getting_diff_for when loading MessageBox
Browse files Browse the repository at this point in the history
  • Loading branch information
Lonami committed Oct 14, 2024
1 parent 99d9f54 commit 44ee272
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 0 additions & 2 deletions lib/grammers-client/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ pub struct InitParams {
/// Should the client catch-up on updates sent to it while it was offline?
///
/// By default, updates sent while the client was offline are ignored.
// TODO catch up doesn't occur until we get an update that tells us if there was a gap, but
// maybe we should forcibly try to get difference even if we didn't miss anything?
pub catch_up: bool,
/// Server address to connect to. By default, the library will connect to the address stored
/// in the session file (or a default production address if no such address exists). This
Expand Down
18 changes: 17 additions & 1 deletion lib/grammers-session/src/message_box/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,30 @@ impl MessageBox {
trace!("created new message box with state: {:?}", state);
let deadline = next_updates_deadline();
let mut map = HashMap::with_capacity(2 + state.channels.len());
let mut getting_diff_for = HashSet::with_capacity(2 + state.channels.len());

map.insert(
Entry::AccountWide,
State {
pts: state.pts,
deadline,
},
);
if state.pts != NO_PTS {
getting_diff_for.insert(Entry::AccountWide);
}

map.insert(
Entry::SecretChats,
State {
pts: state.qts,
deadline,
},
);
if state.pts != NO_PTS {
getting_diff_for.insert(Entry::SecretChats);
}

map.extend(state.channels.iter().map(|ChannelStateEnum::State(c)| {
(
Entry::Channel(c.channel_id),
Expand All @@ -92,13 +102,19 @@ impl MessageBox {
},
)
}));
getting_diff_for.extend(
state
.channels
.iter()
.map(|ChannelStateEnum::State(c)| (Entry::Channel(c.channel_id))),
);

Self {
map,
date: state.date,
seq: state.seq,
possible_gaps: HashMap::new(),
getting_diff_for: HashSet::new(),
getting_diff_for,
next_deadline: Some(Entry::AccountWide),
tmp_entries: HashSet::new(),
}
Expand Down

0 comments on commit 44ee272

Please sign in to comment.