room-history: Don't loop when new messages are added
The scrollbar has not been updated when the `load()` method returns, so wait until we get notified of the change if new messages are added.
This commit is contained in:
parent
f0e5d97684
commit
b0274eaaf2
2 changed files with 10 additions and 23 deletions
|
@ -842,22 +842,7 @@ impl RoomHistory {
|
||||||
let obj_weak = self.downgrade();
|
let obj_weak = self.downgrade();
|
||||||
spawn!(async move {
|
spawn!(async move {
|
||||||
loop {
|
loop {
|
||||||
// We don't want to hold a strong ref to `obj` on `await`
|
if !room.timeline().load().await {
|
||||||
let need = if let Some(obj) = obj_weak.upgrade() {
|
|
||||||
if obj.room().as_ref() == Some(&room) {
|
|
||||||
obj.need_messages() || room.timeline().is_empty()
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
if need {
|
|
||||||
if !room.timeline().load().await {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -507,9 +507,9 @@ impl Timeline {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load the timeline
|
/// Load events at the start of the timeline.
|
||||||
/// This function should also be called to load more events
|
///
|
||||||
/// Returns `true` when messages where successfully added
|
/// Returns `true` when no messages were added, but more can be loaded.
|
||||||
pub async fn load(&self) -> bool {
|
pub async fn load(&self) -> bool {
|
||||||
let priv_ = self.imp();
|
let priv_ = self.imp();
|
||||||
|
|
||||||
|
@ -584,8 +584,7 @@ impl Timeline {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.set_state(TimelineState::Ready);
|
self.set_state(TimelineState::Ready);
|
||||||
self.prepend(events);
|
!self.prepend(events)
|
||||||
true
|
|
||||||
}
|
}
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
self.remove_loading_spinner();
|
self.remove_loading_spinner();
|
||||||
|
@ -784,8 +783,10 @@ impl Timeline {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prepends a batch of events
|
/// Prepends a batch of events.
|
||||||
pub fn prepend(&self, batch: Vec<Event>) {
|
///
|
||||||
|
/// Returns `true` if new shown events where added to the timeline.
|
||||||
|
pub fn prepend(&self, batch: Vec<Event>) -> bool {
|
||||||
let priv_ = self.imp();
|
let priv_ = self.imp();
|
||||||
let mut added = batch.len();
|
let mut added = batch.len();
|
||||||
|
|
||||||
|
@ -831,6 +832,7 @@ impl Timeline {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.items_changed(0, 0, added as u32);
|
self.items_changed(0, 0, added as u32);
|
||||||
|
added > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_room(&self, room: Option<Room>) {
|
fn set_room(&self, room: Option<Room>) {
|
||||||
|
|
Loading…
Reference in a new issue