mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +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> {
|
||||
if let Some(author_id) = self.author_lookup.get(author) {
|
||||
match self
|
||||
.posts
|
||||
.binary_search_by(|x| x.timestamp().cmp(×tamp))
|
||||
{
|
||||
Ok(index) => {
|
||||
// matched timestamp but maybe duplicates by different authors
|
||||
for (id, post) in self.posts[..index].iter().rev().enumerate() {
|
||||
if post.timestamp() != timestamp {
|
||||
break;
|
||||
}
|
||||
let i = self.posts.partition_point(|p| p.timestamp() < timestamp);
|
||||
let last = self.posts.len()-1;
|
||||
for n in i..last {
|
||||
if let Some(post) = self.posts.get(n) {
|
||||
if post.timestamp() == timestamp {
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue