diff --git a/src/main.rs b/src/main.rs index 5c38640e..39520348 100644 --- a/src/main.rs +++ b/src/main.rs @@ -767,17 +767,16 @@ impl Halloy { ); } data::client::Event::JoinedChannel(channel, server_time) => { - if let Some(command) = dashboard + let command = dashboard .load_metadata( &self.clients, server.clone(), channel.clone(), server_time, ) - .map(|command| command.map(Message::Dashboard)) - { - commands.push(command); - } + .map(Message::Dashboard); + + commands.push(command); } data::client::Event::ChatHistoryAcknowledged(server_time) => { if let Some(command) = dashboard @@ -795,17 +794,16 @@ impl Halloy { target, server_time, ) => { - if let Some(command) = dashboard + let command = dashboard .load_metadata( &self.clients, server.clone(), target.clone(), server_time, ) - .map(|command| command.map(Message::Dashboard)) - { - commands.push(command); - } + .map(Message::Dashboard); + + commands.push(command); } data::client::Event::ChatHistoryTargetsReceived( server_time, diff --git a/src/screen/dashboard.rs b/src/screen/dashboard.rs index 40d389b9..bfe18e0e 100644 --- a/src/screen/dashboard.rs +++ b/src/screen/dashboard.rs @@ -1488,14 +1488,21 @@ impl Dashboard { &message_reference_types, ); - clients.send_chathistory_request( - server, + let subcommand = if matches!(first_can_reference, MessageReference::None) { + ChatHistorySubcommand::Latest( + target.clone(), + first_can_reference, + clients.get_server_chathistory_limit(server), + ) + } else { ChatHistorySubcommand::Before( target.clone(), first_can_reference, clients.get_server_chathistory_limit(server), - ), - ); + ) + }; + + clients.send_chathistory_request(server, subcommand); } } } @@ -1533,21 +1540,19 @@ impl Dashboard { server: Server, channel: String, server_time: DateTime, - ) -> Option> { + ) -> Task { let command = self .history .load_metadata(server.clone(), channel.clone()) - .map(|task| Task::perform(task, Message::History)); + .map_or(Task::none(), |task| Task::perform(task, Message::History)); - command.map(|command| { - if clients.get_server_supports_chathistory(&server) { - command.chain(Task::done(Message::Client( - data::client::Message::RequestNewerChatHistory(server, channel, server_time), - ))) - } else { - command - } - }) + if clients.get_server_supports_chathistory(&server) { + command.chain(Task::done(Message::Client( + data::client::Message::RequestNewerChatHistory(server, channel, server_time), + ))) + } else { + command + } } pub fn load_chathistory_targets_timestamp(