fix unread count: sent messages don't count as unread
Track outgoing messages separately (own counter) so they appear in the log but don't inflate unread counts. Reset on recv. Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
e104a16f61
commit
53a2dbac37
3 changed files with 22 additions and 5 deletions
|
|
@ -12,6 +12,8 @@ pub struct ChannelLog {
|
|||
messages: VecDeque<String>,
|
||||
consumed: usize,
|
||||
total: usize,
|
||||
/// Messages we sent (don't count as unread)
|
||||
own: usize,
|
||||
}
|
||||
|
||||
impl ChannelLog {
|
||||
|
|
@ -20,6 +22,7 @@ impl ChannelLog {
|
|||
messages: VecDeque::with_capacity(DEFAULT_CAPACITY),
|
||||
consumed: 0,
|
||||
total: 0,
|
||||
own: 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -35,7 +38,13 @@ impl ChannelLog {
|
|||
}
|
||||
|
||||
pub fn unread(&self) -> u32 {
|
||||
(self.total - self.consumed) as u32
|
||||
(self.total - self.consumed - self.own) as u32
|
||||
}
|
||||
|
||||
/// Push a message that we sent (doesn't count as unread).
|
||||
pub fn push_own(&mut self, line: String) {
|
||||
self.push(line);
|
||||
self.own += 1;
|
||||
}
|
||||
|
||||
/// Return all unconsumed messages (marks consumed), plus scrollback
|
||||
|
|
@ -58,6 +67,7 @@ impl ChannelLog {
|
|||
.collect();
|
||||
|
||||
self.consumed = self.total;
|
||||
self.own = 0;
|
||||
|
||||
let mut result = scrollback;
|
||||
result.extend(new_msgs);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue