Skip to content

Commit fdc23ca

Browse files
properly refresh timelines with no WS streaming support, closes #77
1 parent a733c91 commit fdc23ca

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/commands.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ pub enum UiCommand {
144144
AppClosing,
145145
ExitApp,
146146
RecoverDraft,
147+
PollNonStreaming,
147148
}
148149

149150
/// Refreshes the current timeline by re-fetching from the network.
@@ -162,6 +163,19 @@ pub fn refresh_timeline(state: &AppState, live_region: &crate::ui::timeline_list
162163
}
163164
}
164165

166+
pub fn poll_non_streaming_timelines(state: &AppState) {
167+
let Some(handle) = &state.network_handle else { return };
168+
for timeline in state.timeline_manager.timelines() {
169+
if timeline.stream_handle.is_none() && timeline.timeline_type.stream_params().is_some() {
170+
handle.send(NetworkCommand::FetchTimeline {
171+
timeline_type: timeline.timeline_type.clone(),
172+
limit: Some(40),
173+
max_id: None,
174+
});
175+
}
176+
}
177+
}
178+
165179
/// Handles a UI command, updating state and UI as needed.
166180
pub struct UiCommandContext<'a> {
167181
pub state: &'a mut AppState,
@@ -524,6 +538,9 @@ pub fn handle_ui_command(cmd: UiCommand, ctx: &mut UiCommandContext<'_>) {
524538
UiCommand::Refresh => {
525539
refresh_timeline(state, live_region);
526540
}
541+
UiCommand::PollNonStreaming => {
542+
poll_non_streaming_timelines(state);
543+
}
527544
UiCommand::OpenTimeline(timeline_type) => {
528545
open_timeline(
529546
state,

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,9 @@ fn main() {
338338
});
339339

340340
let refresh_timer = Rc::new(Timer::new(&frame));
341-
let refresh_waker = ui_waker.clone();
341+
let ui_tx_timer_poll = ui_tx.clone();
342342
refresh_timer.on_tick(move |_| {
343-
refresh_waker.wake();
343+
let _ = ui_tx_timer_poll.send(UiCommand::PollNonStreaming);
344344
});
345345
refresh_timer.start(60_000, false);
346346
let refresh_timer_keepalive = refresh_timer;

src/timeline.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,10 @@ impl TimelineManager {
468468
self.timelines.iter().position(|t| t.timeline_type == *timeline_type)
469469
}
470470

471+
pub fn timelines(&self) -> &[Timeline] {
472+
&self.timelines
473+
}
474+
471475
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut Timeline> {
472476
self.timelines.iter_mut()
473477
}

0 commit comments

Comments
 (0)