poll_updates still needs to return when there are changes in order to update the UI

This commit is contained in:
Val Lorentz 2024-02-11 09:02:40 +01:00
parent 11bf79e95e
commit e7f3eeb331
3 changed files with 53 additions and 59 deletions

View File

@ -64,7 +64,7 @@ impl Buffer for LogBuffer {
BufferId::Log
}
async fn poll_updates(&mut self) {
async fn poll_updates_once(&mut self) {
let line = self
.receiver
.recv()

View File

@ -134,7 +134,7 @@ pub trait Buffer: Send + Sync + memuse::DynamicUsage {
None
}
/// Returns if there are any updates to apply.
async fn poll_updates(&mut self);
async fn poll_updates_once(&mut self);
fn content<'a>(&'a self) -> Box<dyn ExactSizeIterator<Item = BufferItem<'a>> + 'a>;
/// Called when the user is being showned the oldest items this buffer returned.
///
@ -201,7 +201,7 @@ impl Buffers {
let next_reorder = self.next_reorder;
let mut updates_future = self
.iter_mut()
.map(|buf| buf.poll_updates())
.map(|buf| buf.poll_updates_once())
.collect::<FuturesUnordered<_>>();
let reorder_future = async {
@ -213,7 +213,7 @@ impl Buffers {
select! {
res = updates_future.next() => {
res.expect("poll_updates reached the end of the never-ending stream");
res.expect("poll_updates_once reached the end of the never-ending stream");
false
},
_ = reorder_future => {

View File

@ -639,6 +639,55 @@ impl RoomBuffer {
Ok(())
}
}
#[async_trait]
impl Buffer for RoomBuffer {
fn short_name(&self) -> String {
self
.computed_roominfo
.as_ref()
.and_then(|roominfo| roominfo.display_name.as_ref())
.map(|dn| dn.to_string())
.unwrap_or_else(|| {
self
.buffers
.iter()
.flat_map(|buf| buf.client.get_room(&self.room_id))
.flat_map(|room| room.canonical_alias())
.map(|alias| alias.as_str().to_owned())
.next()
.unwrap_or(self.room_id.as_str().to_owned())
.clone()
})
}
#[inline]
fn id(&self) -> BufferId {
BufferId::Room(self.room_id.clone())
}
fn parent(&self) -> Option<BufferId> {
self
.computed_roominfo
.as_ref()
.and_then(|roominfo| roominfo.parent.as_ref())
.map(|parent| BufferId::Room(parent.clone()))
}
fn children(&self) -> Option<SortedVec<(BufferSortKey, BufferId)>> {
self
.computed_roominfo
.as_ref()
.and_then(|roominfo| roominfo.children.as_ref())
.map(|children: &SortedVec<_>| {
let children = children
.iter()
.map(|(sort_key, room_id)| (sort_key.clone(), BufferId::Room(room_id.clone())))
.collect();
// This is safe because the map above preserves order
unsafe { SortedVec::from_sorted(children) }
})
}
async fn poll_updates_once(&mut self) {
if self.update_roominfo_rx.is_none() && self.computed_roominfo.is_none() {
@ -706,61 +755,6 @@ impl RoomBuffer {
}
}
}
}
#[async_trait]
impl Buffer for RoomBuffer {
fn short_name(&self) -> String {
self
.computed_roominfo
.as_ref()
.and_then(|roominfo| roominfo.display_name.as_ref())
.map(|dn| dn.to_string())
.unwrap_or_else(|| {
self
.buffers
.iter()
.flat_map(|buf| buf.client.get_room(&self.room_id))
.flat_map(|room| room.canonical_alias())
.map(|alias| alias.as_str().to_owned())
.next()
.unwrap_or(self.room_id.as_str().to_owned())
.clone()
})
}
#[inline]
fn id(&self) -> BufferId {
BufferId::Room(self.room_id.clone())
}
fn parent(&self) -> Option<BufferId> {
self
.computed_roominfo
.as_ref()
.and_then(|roominfo| roominfo.parent.as_ref())
.map(|parent| BufferId::Room(parent.clone()))
}
fn children(&self) -> Option<SortedVec<(BufferSortKey, BufferId)>> {
self
.computed_roominfo
.as_ref()
.and_then(|roominfo| roominfo.children.as_ref())
.map(|children: &SortedVec<_>| {
let children = children
.iter()
.map(|(sort_key, room_id)| (sort_key.clone(), BufferId::Room(room_id.clone())))
.collect();
// This is safe because the map above preserves order
unsafe { SortedVec::from_sorted(children) }
})
}
async fn poll_updates(&mut self) {
while !self.buffers.is_empty() {
self.poll_updates_once().await;
}
}
fn content<'a>(&'a self) -> Box<dyn ExactSizeIterator<Item = BufferItem<'a>> + 'a> {
// TODO: merge buffers, etc.