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();
|
||||
spawn!(async move {
|
||||
loop {
|
||||
// We don't want to hold a strong ref to `obj` on `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 {
|
||||
if !room.timeline().load().await {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -507,9 +507,9 @@ impl Timeline {
|
|||
}
|
||||
}
|
||||
|
||||
/// Load the timeline
|
||||
/// This function should also be called to load more events
|
||||
/// Returns `true` when messages where successfully added
|
||||
/// Load events at the start of the timeline.
|
||||
///
|
||||
/// Returns `true` when no messages were added, but more can be loaded.
|
||||
pub async fn load(&self) -> bool {
|
||||
let priv_ = self.imp();
|
||||
|
||||
|
@ -584,8 +584,7 @@ impl Timeline {
|
|||
}
|
||||
|
||||
self.set_state(TimelineState::Ready);
|
||||
self.prepend(events);
|
||||
true
|
||||
!self.prepend(events)
|
||||
}
|
||||
Ok(None) => {
|
||||
self.remove_loading_spinner();
|
||||
|
@ -784,8 +783,10 @@ impl Timeline {
|
|||
}
|
||||
}
|
||||
|
||||
/// Prepends a batch of events
|
||||
pub fn prepend(&self, batch: Vec<Event>) {
|
||||
/// Prepends a batch of events.
|
||||
///
|
||||
/// Returns `true` if new shown events where added to the timeline.
|
||||
pub fn prepend(&self, batch: Vec<Event>) -> bool {
|
||||
let priv_ = self.imp();
|
||||
let mut added = batch.len();
|
||||
|
||||
|
@ -831,6 +832,7 @@ impl Timeline {
|
|||
}
|
||||
|
||||
self.items_changed(0, 0, added as u32);
|
||||
added > 0
|
||||
}
|
||||
|
||||
fn set_room(&self, room: Option<Room>) {
|
||||
|
|
Loading…
Reference in a new issue