Skip to content

Commit

Permalink
feat(raygun): use MessageOptions.limit when fetching messages (#330)
Browse files Browse the repository at this point in the history
Co-authored-by: Darius Clark <[email protected]>
Co-authored-by: Darius <[email protected]>
  • Loading branch information
3 people authored Oct 4, 2023
1 parent 92e52b2 commit 2ae7f38
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
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

0 comments on commit 2ae7f38

Please sign in to comment.