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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.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
6 changes: 3 additions & 3 deletions warp/src/raygun/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ pub struct MessageOptions {
keyword: Option<String>,
pinned: bool,
range: Option<Range<usize>>,
limit: Option<i64>,
limit: Option<u8>,
skip: Option<i64>,
}

Expand All @@ -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
}
Expand Down Expand Up @@ -253,7 +253,7 @@ impl MessageOptions {
}

impl MessageOptions {
pub fn limit(&self) -> Option<i64> {
pub fn limit(&self) -> Option<u8> {
self.limit
}

Expand Down