Skip to content

Commit

Permalink
Clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hwood-fg committed Apr 14, 2023
1 parent 0989a0b commit 9a32832
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 38 deletions.
67 changes: 30 additions & 37 deletions dnas/clutter/coordinator_zomes/mews/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,7 @@ pub fn mews_feed(_options: FeedOptions) -> ExternResult<Vec<FeedMew>> {

#[hdk_extern]
pub fn recommended(input: RecommendedInput) -> ExternResult<Vec<FeedMew>> {
let oldest_mew_seconds = match input.oldest_mew_seconds {
Some(oldest_mew_seconds) => oldest_mew_seconds,
None => 60 * 60 * 24 * 7 * 2, // 2 weeks
};
let oldest_mew_seconds = input.oldest_mew_seconds.unwrap_or(60 * 60 * 24 * 7 * 2);

// get all TrustAtoms -- topic/author combos "rated" by this agent
let topics_by_author: Vec<TrustAtom> = call_local_zome(
Expand All @@ -283,29 +280,29 @@ pub fn recommended(input: RecommendedInput) -> ExternResult<Vec<FeedMew>> {
)?;

// filter for those TrustAtoms above a weight threshold (>= 0)
let recomended_topics_by_author: Vec<TrustAtom> = topics_by_author
.into_iter()
.filter_map(|atom| match atom.value.clone() {
Some(value_string) => {
let value_float: Result<f32, _> = value_string.parse();
match value_float {
Ok(value_float) => {
if value_float >= 0f32 {
Some(atom)
} else {
None
let recomended_topics_by_author =
topics_by_author
.into_iter()
.filter_map(|atom| match atom.value.clone() {
Some(value_string) => {
let value_float: Result<f32, _> = value_string.parse();
match value_float {
Ok(value_float) => {
if value_float >= 0f32 {
Some(atom)
} else {
None
}
}
_ => None,
}
_ => None,
}
}
None => Some(atom), // trust atoms with no value typically mean "yup" without a specific "percent/weight"
})
.collect();
None => Some(atom), // trust atoms with no value typically mean "yup" without a specific "percent/weight"
});
// .collect();

let mut feed_mews: Vec<FeedMew> = recomended_topics_by_author
.into_iter()
.map(|atom| {
.flat_map(|atom| {
let followed_author = atom.target_hash;
match atom.content {
None => vec![], // TODO get all mews by this author
Expand All @@ -322,7 +319,6 @@ pub fn recommended(input: RecommendedInput) -> ExternResult<Vec<FeedMew>> {
}
}
})
.flatten()
.collect();

// TODO should we get other types: mewmews, quotes, etc
Expand Down Expand Up @@ -418,7 +414,7 @@ pub fn unlick_mew(action_hash: ActionHash) -> ExternResult<()> {
#[hdk_extern]
pub fn follow(input: FollowInput) -> ExternResult<()> {
let me_target: EntryHash = agent_info()?.agent_latest_pubkey.into();
let them_target: EntryHash = AgentPubKey::from(input.agent.clone()).into();
let them_target: EntryHash = input.agent.clone().into();

if me_target == them_target {
return Err(wasm_error!(WasmErrorInner::Guest(String::from(
Expand Down Expand Up @@ -519,7 +515,7 @@ fn get_mews_with_hashtag_by_author(
) -> ExternResult<Vec<FeedMew>> {
// debug!("search -- hashtags.{}", hashtag);
let path = Path::from(format!("hashtags.{}", hashtag));
Ok(get_mews_from_path_by_author(path, author)?)
get_mews_from_path_by_author(path, author)
}

#[hdk_extern]
Expand All @@ -535,7 +531,7 @@ pub fn get_mews_with_mention(agent_pub_key: AgentPubKey) -> ExternResult<Vec<Fee
}

fn get_mews_from_path_by_author(path: Path, author: AgentPubKey) -> ExternResult<Vec<FeedMew>> {
let mut full_path = path.clone();
let mut full_path = path;
full_path.append_component(hdk::hash_path::path::Component::from("by".to_string()));
full_path.append_component(hdk::hash_path::path::Component::from(author.to_string()));

Expand Down Expand Up @@ -574,18 +570,15 @@ pub fn parse_mew_text(mew_content: MewContent, mew_hash: ActionHash) -> ExternRe
for mat in hashtag_regex.find_iter(&mew_content.text) {
create_mew_tag_links("hashtags", mat.as_str(), mew_hash.clone())?;
}
for mat in cashtag_regex.find_iter(&mew_content.text.clone()) {
for mat in cashtag_regex.find_iter(&mew_content.text) {
create_mew_tag_links("cashtags", mat.as_str(), mew_hash.clone())?;
}
if let Some(links) = mew_content.links {
for link in links {
match link {
LinkTarget::Mention(mention) => {
let path = Path::from(format!("mentions.{}", mention));
let path_hash = path.path_entry_hash()?;
let _link_ah = create_link(path_hash, mew_hash.clone(), LinkTypes::Tag, ())?;
}
_ => (),
if let LinkTarget::Mention(mention) = link {
let path = Path::from(format!("mentions.{}", mention));
let path_hash = path.path_entry_hash()?;
let _link_ah = create_link(path_hash, mew_hash.clone(), LinkTypes::Tag, ())?;
}
}
}
Expand Down Expand Up @@ -629,14 +622,14 @@ fn create_mew_tag_links(path_stem: &str, content: &str, mew_hash: ActionHash) ->
let path = Path::from(format!("{}.{}", path_stem, content));
let path_hash = path.path_entry_hash()?;
path.typed(LinkTypes::Tag)?.ensure()?;
create_link(path_hash.clone(), mew_hash.clone(), LinkTypes::Tag, ())?;
create_link(path_hash, mew_hash.clone(), LinkTypes::Tag, ())?;

let me = agent_info()?.agent_latest_pubkey;
// debug!("path --- {}.{}.by.{}", path_stem, content, me);
let path = Path::from(format!("{}.{}.by.{}", path_stem, content, me));
let path_hash = path.path_entry_hash()?;
path.typed(LinkTypes::Tag)?.ensure()?;
create_link(path_hash.clone(), mew_hash.clone(), LinkTypes::Tag, ())?;
create_link(path_hash.clone(), mew_hash, LinkTypes::Tag, ())?;

// Create Path for sliced hashtag (first 3 characters) under hashtags_search.myt
// Link from Path hashtags.myt -> hashtags.mytag Path
Expand All @@ -649,7 +642,7 @@ fn create_mew_tag_links(path_stem: &str, content: &str, mew_hash: ActionHash) ->
search_path.typed(LinkTypes::TagPrefix)?.ensure()?;
create_link(
search_path_hash,
path_hash.clone(),
path_hash,
LinkTypes::TagPrefix,
word.as_bytes().to_vec(),
)?;
Expand Down
3 changes: 2 additions & 1 deletion dnas/clutter/coordinator_zomes/mews/tests/mews_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ pub struct Agent<'a> {
}

impl Agent<'_> {
pub async fn follow(&self, input: FollowInput) -> () {
pub async fn follow(&self, input: FollowInput) {
self.conductor.call(&self.zome, "follow", input).await
}

Expand All @@ -275,6 +275,7 @@ pub struct AgentGroup {
}

impl AgentGroup {
#[allow(clippy::needless_lifetimes)]
pub async fn create_agents<'a>(&'a mut self) -> Vec<Agent<'a>> {
let dna_path = std::env::current_dir().unwrap().join(DNA_FILEPATH);
let dna = SweetDnaFile::from_bundle(&dna_path).await.unwrap();
Expand Down

0 comments on commit 9a32832

Please sign in to comment.