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:
ProofOfConcept 2026-04-03 20:42:36 -04:00
parent e104a16f61
commit 53a2dbac37
3 changed files with 22 additions and 5 deletions

View file

@ -544,7 +544,10 @@ impl channel_server::Server for ChannelServerImpl {
} else { } else {
format!("[PM:{}] {}", target, message) format!("[PM:{}] {}", target, message)
}; };
state.borrow_mut().push_message(log_line, 0, &channel); state.borrow_mut().channel_logs
.entry(channel.clone())
.or_insert_with(ChannelLog::new)
.push_own(log_line);
Ok(()) Ok(())
}) })

View file

@ -260,9 +260,13 @@ impl channel_server::Server for ChannelServerImpl {
let ts = now() as u64; let ts = now() as u64;
append_history(&format!("{ts} [agent] {message}")); append_history(&format!("{ts} [agent] {message}"));
state.borrow_mut().push_message( {
format!("[agent] {}", message), 0, "telegram.agent" let channel = "telegram.agent".to_string();
); state.borrow_mut().channel_logs
.entry(channel)
.or_insert_with(ChannelLog::new)
.push_own(format!("[agent] {}", message));
}
Ok(()) Ok(())
}) })
} }

View file

@ -12,6 +12,8 @@ pub struct ChannelLog {
messages: VecDeque<String>, messages: VecDeque<String>,
consumed: usize, consumed: usize,
total: usize, total: usize,
/// Messages we sent (don't count as unread)
own: usize,
} }
impl ChannelLog { impl ChannelLog {
@ -20,6 +22,7 @@ impl ChannelLog {
messages: VecDeque::with_capacity(DEFAULT_CAPACITY), messages: VecDeque::with_capacity(DEFAULT_CAPACITY),
consumed: 0, consumed: 0,
total: 0, total: 0,
own: 0,
} }
} }
@ -35,7 +38,13 @@ impl ChannelLog {
} }
pub fn unread(&self) -> u32 { 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 /// Return all unconsumed messages (marks consumed), plus scrollback
@ -58,6 +67,7 @@ impl ChannelLog {
.collect(); .collect();
self.consumed = self.total; self.consumed = self.total;
self.own = 0;
let mut result = scrollback; let mut result = scrollback;
result.extend(new_msgs); result.extend(new_msgs);