diff --git a/channels/irc/src/main.rs b/channels/irc/src/main.rs index 44e62df..d9cb83e 100644 --- a/channels/irc/src/main.rs +++ b/channels/irc/src/main.rs @@ -544,7 +544,10 @@ impl channel_server::Server for ChannelServerImpl { } else { 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(()) }) diff --git a/channels/telegram/src/main.rs b/channels/telegram/src/main.rs index 34fb3f8..890053e 100644 --- a/channels/telegram/src/main.rs +++ b/channels/telegram/src/main.rs @@ -260,9 +260,13 @@ impl channel_server::Server for ChannelServerImpl { let ts = now() as u64; 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(()) }) } diff --git a/src/thalamus/channel_log.rs b/src/thalamus/channel_log.rs index 2de1ab7..3eae2e1 100644 --- a/src/thalamus/channel_log.rs +++ b/src/thalamus/channel_log.rs @@ -12,6 +12,8 @@ pub struct ChannelLog { messages: VecDeque, 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);