mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
fix Chat::Dialogue.post_add() duplication
This commit is contained in:
parent
0ef1d79725
commit
3392b30794
1 changed files with 6 additions and 3 deletions
|
|
@ -64,23 +64,26 @@ impl Dialogue {
|
|||
let new_ts = new.timestamp();
|
||||
let first_ts = self.posts.first().map_or(0, |p| p.timestamp());
|
||||
let last_ts = self.posts.last().map_or(0, |p| p.timestamp());
|
||||
if new_ts >= last_ts {
|
||||
if new_ts > last_ts {
|
||||
log::info!("insert new post at end");
|
||||
self.posts.push(new);
|
||||
} else if new_ts < first_ts {
|
||||
log::info!("insert new post at start");
|
||||
self.posts.insert(0, new);
|
||||
} else {
|
||||
log::info!("{:?}", new);
|
||||
let i = self.posts.partition_point(|p| p.timestamp() < new_ts);
|
||||
let last = self.posts.len()-1;
|
||||
for n in i..last {
|
||||
if let Some(old) = self.posts.get(n) {
|
||||
if old.timestamp() == new_ts {
|
||||
if old.author_id() == author_id {
|
||||
// replace matching post
|
||||
log::info!("replace matching post at {n}");
|
||||
self.posts[i] = new;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// insert new post
|
||||
log::info!("insert new post at {n}");
|
||||
self.posts.insert(n, new);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue