diff --git a/extensions/warp-ipfs/src/store/conversation.rs b/extensions/warp-ipfs/src/store/conversation.rs index caa0ff4cc..e59292bc1 100644 --- a/extensions/warp-ipfs/src/store/conversation.rs +++ b/extensions/warp-ipfs/src/store/conversation.rs @@ -376,8 +376,11 @@ impl ConversationDocument { let ipfs = ipfs.clone(); let stream = async_stream::stream! { - + let mut remaining = option.limit(); for (index, document) in messages.iter().enumerate() { + if remaining.as_ref().map(|x| *x == 0).unwrap_or_default() { + break; + } if let Some(range) = option.range() { if range.start > index || range.end < index { continue @@ -388,20 +391,22 @@ impl ConversationDocument { continue } } - if let Ok(message) = document.resolve(&ipfs, &did, keystore.as_ref()).await { if option.pinned() && !message.pinned() { continue; } - if let Some(keyword) = option.keyword() { - if message + let should_yield = if let Some(keyword) = option.keyword() { + message .value() .iter() .any(|line| line.to_lowercase().contains(&keyword.to_lowercase())) - { - yield message; - } } else { + true + }; + if should_yield { + if let Some(remaining) = remaining.as_mut() { + *remaining = remaining.saturating_sub(1); + } yield message; } } diff --git a/warp/src/raygun/mod.rs b/warp/src/raygun/mod.rs index 5c638fdcc..f872ab01e 100644 --- a/warp/src/raygun/mod.rs +++ b/warp/src/raygun/mod.rs @@ -189,7 +189,7 @@ pub struct MessageOptions { keyword: Option, pinned: bool, range: Option>, - limit: Option, + limit: Option, skip: Option, } @@ -204,7 +204,7 @@ impl MessageOptions { self } - pub fn set_limit(mut self, limit: i64) -> MessageOptions { + pub fn set_limit(mut self, limit: u8) -> MessageOptions { self.limit = Some(limit); self } @@ -253,7 +253,7 @@ impl MessageOptions { } impl MessageOptions { - pub fn limit(&self) -> Option { + pub fn limit(&self) -> Option { self.limit }