Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(raygun): use MessageOptions.limit when fetching messages #330

Merged
merged 7 commits into from
Oct 4, 2023
19 changes: 12 additions & 7 deletions extensions/warp-ipfs/src/store/conversation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,11 @@ impl ConversationDocument {

let ipfs = ipfs.clone();
let stream = async_stream::stream! {

let mut remaining: Option<i64> = 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
Expand All @@ -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;
}
}
Expand Down