Skip to content

Commit

Permalink
Hook up new history tasks to all code-paths
Browse files Browse the repository at this point in the history
  • Loading branch information
tarkah committed Sep 23, 2024
1 parent 0fbcafe commit b164212
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 232 deletions.
9 changes: 5 additions & 4 deletions data/src/history/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl Manager {
broadcast: Broadcast,
config: &Config,
sent_time: DateTime<Utc>,
) {
) -> Vec<impl Future<Output = Message>> {
let map = self.data.map.entry(server.clone()).or_default();

let channels = map
Expand Down Expand Up @@ -410,9 +410,10 @@ impl Manager {
}
};

messages.into_iter().for_each(|message| {
self.record_message(server, message);
});
messages
.into_iter()
.filter_map(|message| self.record_message(server, message))
.collect()
}

pub fn input<'a>(&'a self, buffer: &Buffer) -> input::Cache<'a> {
Expand Down
5 changes: 4 additions & 1 deletion src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ pub enum Message {
FileTransfers(file_transfers::Message),
}

#[derive(Debug, Clone)]
pub enum Event {
UserContext(user_context::Event),
OpenChannel(String),
History(Task<history::manager::Message>),
}

impl Buffer {
Expand Down Expand Up @@ -73,6 +73,7 @@ impl Buffer {
let event = event.map(|event| match event {
channel::Event::UserContext(event) => Event::UserContext(event),
channel::Event::OpenChannel(channel) => Event::OpenChannel(channel),
channel::Event::History(task) => Event::History(task),
});

(command.map(Message::Channel), event)
Expand All @@ -83,6 +84,7 @@ impl Buffer {
let event = event.map(|event| match event {
server::Event::UserContext(event) => Event::UserContext(event),
server::Event::OpenChannel(channel) => Event::OpenChannel(channel),
server::Event::History(task) => Event::History(task),
});

(command.map(Message::Server), event)
Expand All @@ -93,6 +95,7 @@ impl Buffer {
let event = event.map(|event| match event {
query::Event::UserContext(event) => Event::UserContext(event),
query::Event::OpenChannel(channel) => Event::OpenChannel(channel),
query::Event::History(task) => Event::History(task),
});

(command.map(Message::Query), event)
Expand Down
6 changes: 3 additions & 3 deletions src/buffer/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ pub enum Message {
Topic(topic::Message),
}

#[derive(Debug, Clone)]
pub enum Event {
UserContext(user_context::Event),
OpenChannel(String),
History(Task<history::manager::Message>),
}

pub fn view<'a>(
Expand Down Expand Up @@ -341,13 +341,13 @@ impl Channel {
let command = command.map(Message::InputView);

match event {
Some(input_view::Event::InputSent) => {
Some(input_view::Event::InputSent { history_task }) => {
let command = Task::batch(vec![
command,
self.scroll_view.scroll_to_end().map(Message::ScrollView),
]);

(command, None)
(command, Some(Event::History(history_task)))
}
None => (command, None),
}
Expand Down
15 changes: 12 additions & 3 deletions src/buffer/input_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use crate::widget::{anchored_overlay, key_press, Element};
mod completion;

pub enum Event {
InputSent,
InputSent {
history_task: Task<history::manager::Message>,
},
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -177,6 +179,8 @@ impl State {
clients.send(buffer, encoded);
}

let mut history_task = Task::none();

if let Some(nick) = clients.nickname(buffer.server()) {
let mut user = nick.to_owned().into();
let mut channel_users = &[][..];
Expand All @@ -192,10 +196,15 @@ impl State {
}
}

history.record_input(input, user, channel_users);
history_task = Task::batch(
history
.record_input(input, user, channel_users)
.into_iter()
.map(Task::future),
);
}

(Task::none(), Some(Event::InputSent))
(Task::none(), Some(Event::InputSent { history_task }))
} else {
(Task::none(), None)
}
Expand Down
6 changes: 3 additions & 3 deletions src/buffer/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ pub enum Message {
InputView(input_view::Message),
}

#[derive(Debug, Clone)]
pub enum Event {
UserContext(user_context::Event),
OpenChannel(String),
History(Task<history::manager::Message>),
}

pub fn view<'a>(
Expand Down Expand Up @@ -255,13 +255,13 @@ impl Query {
let command = command.map(Message::InputView);

match event {
Some(input_view::Event::InputSent) => {
Some(input_view::Event::InputSent { history_task }) => {
let command = Task::batch(vec![
command,
self.scroll_view.scroll_to_end().map(Message::ScrollView),
]);

(command, None)
(command, Some(Event::History(history_task)))
}
None => (command, None),
}
Expand Down
21 changes: 11 additions & 10 deletions src/buffer/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ pub enum Message {
InputView(input_view::Message),
}

#[derive(Debug, Clone)]
pub enum Event {
UserContext(user_context::Event),
OpenChannel(String),
History(Task<history::manager::Message>),
}

pub fn view<'a>(
Expand Down Expand Up @@ -143,15 +143,16 @@ impl Server {
.update(message, &self.buffer, clients, history, config);
let command = command.map(Message::InputView);

let task = match event {
Some(input_view::Event::InputSent) => Task::batch(vec![
command,
self.scroll_view.scroll_to_end().map(Message::ScrollView),
]),
None => command,
};

(task, None)
match event {
Some(input_view::Event::InputSent { history_task }) => (
Task::batch(vec![
command,
self.scroll_view.scroll_to_end().map(Message::ScrollView),
]),
Some(Event::History(history_task)),
),
None => (command, None),
}
}
}
}
Expand Down
Loading

0 comments on commit b164212

Please sign in to comment.