poll_updates still needs to return when there are changes in order to update the UI
This commit is contained in:
@ -64,7 +64,7 @@ impl Buffer for LogBuffer {
|
|||||||
BufferId::Log
|
BufferId::Log
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn poll_updates(&mut self) {
|
async fn poll_updates_once(&mut self) {
|
||||||
let line = self
|
let line = self
|
||||||
.receiver
|
.receiver
|
||||||
.recv()
|
.recv()
|
||||||
|
@ -134,7 +134,7 @@ pub trait Buffer: Send + Sync + memuse::DynamicUsage {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
/// Returns if there are any updates to apply.
|
/// 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>;
|
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.
|
/// 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 next_reorder = self.next_reorder;
|
||||||
let mut updates_future = self
|
let mut updates_future = self
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.map(|buf| buf.poll_updates())
|
.map(|buf| buf.poll_updates_once())
|
||||||
.collect::<FuturesUnordered<_>>();
|
.collect::<FuturesUnordered<_>>();
|
||||||
|
|
||||||
let reorder_future = async {
|
let reorder_future = async {
|
||||||
@ -213,7 +213,7 @@ impl Buffers {
|
|||||||
|
|
||||||
select! {
|
select! {
|
||||||
res = updates_future.next() => {
|
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
|
false
|
||||||
},
|
},
|
||||||
_ = reorder_future => {
|
_ = reorder_future => {
|
||||||
|
@ -639,6 +639,55 @@ impl RoomBuffer {
|
|||||||
|
|
||||||
Ok(())
|
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) {
|
async fn poll_updates_once(&mut self) {
|
||||||
if self.update_roominfo_rx.is_none() && self.computed_roominfo.is_none() {
|
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> {
|
fn content<'a>(&'a self) -> Box<dyn ExactSizeIterator<Item = BufferItem<'a>> + 'a> {
|
||||||
// TODO: merge buffers, etc.
|
// TODO: merge buffers, etc.
|
||||||
|
Reference in New Issue
Block a user