mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
refine Chat::Dialogue.post_find()
This commit is contained in:
parent
dc8102c627
commit
0ef1d79725
1 changed files with 11 additions and 24 deletions
|
|
@ -95,33 +95,20 @@ impl Dialogue {
|
||||||
|
|
||||||
pub fn post_find(&self, author: &str, timestamp: u64) -> Option<usize> {
|
pub fn post_find(&self, author: &str, timestamp: u64) -> Option<usize> {
|
||||||
if let Some(author_id) = self.author_lookup.get(author) {
|
if let Some(author_id) = self.author_lookup.get(author) {
|
||||||
match self
|
let i = self.posts.partition_point(|p| p.timestamp() < timestamp);
|
||||||
.posts
|
let last = self.posts.len()-1;
|
||||||
.binary_search_by(|x| x.timestamp().cmp(×tamp))
|
for n in i..last {
|
||||||
{
|
if let Some(post) = self.posts.get(n) {
|
||||||
Ok(index) => {
|
if post.timestamp() == timestamp {
|
||||||
// matched timestamp but maybe duplicates by different authors
|
|
||||||
for (id, post) in self.posts[..index].iter().rev().enumerate() {
|
|
||||||
if post.timestamp() != timestamp {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if post.author_id() == *author_id {
|
if post.author_id() == *author_id {
|
||||||
return Some(id);
|
return Some(n);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
for (id, post) in self.posts[index..].iter().enumerate() {
|
|
||||||
if post.timestamp() != timestamp {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if post.author_id() == *author_id {
|
|
||||||
return Some(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return None;
|
|
||||||
}
|
}
|
||||||
Err(_) => None::<usize>,
|
}
|
||||||
};
|
}
|
||||||
};
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue