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/trustgraph integration #261

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
836 changes: 604 additions & 232 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ resolver = "2"
[workspace.dependencies]
hdi = "=0.4.2"
hdk = "=0.3.2"
# holochain_integrity_types = "=0.2.2"
serde = "1.0"
paste = "1.0"
rand = "0.8.5"
hc_prefix_index = "0.12.0"
regex = "1.10.3"
trust_atom_types = { git = "https://github.com/trustgraph/trustgraph-holochain.git", package = "trust_atom_types", branch = "chore/hdk-0.3.2-using-builder" }

[workspace.dependencies.agent_pins]
path = "dnas/mewsfeed/zomes/coordinator/agent_pins"
Expand Down Expand Up @@ -55,3 +57,9 @@ path = "crates/hc_call_utils"

[workspace.dependencies.hc_link_pagination]
path = "crates/hc_link_pagination"

[workspace.dependencies.trust_atom]
path = "dnas/mewsfeed/zomes/coordinator/trust_atom"

[workspace.dependencies.trust_atom_integrity]
path = "dnas/mewsfeed/zomes/integrity/trust_atom_integrity"
19 changes: 19 additions & 0 deletions crates/follows_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,22 @@ pub struct RemoveCreatorForFollowerInput {
pub base_follower: AgentPubKey,
pub target_creator: AgentPubKey,
}

#[derive(Serialize, Deserialize, SerializedBytes, Debug)]
pub struct FollowInput {
pub agent: AgentPubKey,
pub follow_topics: Vec<FollowTopicInput>,
}

#[derive(Serialize, Deserialize, SerializedBytes, Debug)]
pub struct FollowTopicInput {
pub topic: String,
pub weight: String,
}

#[derive(Serialize, Deserialize, SerializedBytes, Debug)]
pub struct TrustedFeedInput {
pub agent: AgentPubKey,
pub topic: String,
pub weight: String,
}
6 changes: 6 additions & 0 deletions crates/mews_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use hc_link_pagination::Timestamped;
use hdk::prelude::*;
use std::collections::BTreeMap;

pub const FOLLOW_TOPIC: &str = "__DEFAULT__";

#[derive(Serialize, Deserialize, SerializedBytes, Debug, Clone, PartialEq, Eq)]
pub enum LinkTarget {
Mention(AgentPubKey),
Expand Down Expand Up @@ -42,6 +44,7 @@ pub struct Profile {

#[derive(Serialize, Deserialize, SerializedBytes, Debug, Clone)]
pub struct FeedMew {
// Mew with context
pub mew: Mew,
pub action: Action,
pub action_hash: ActionHash,
Expand All @@ -57,6 +60,9 @@ pub struct FeedMew {
pub is_replied: bool,
pub is_quoted: bool,
pub original_mew: Option<EmbedMew>,
// introduced with TrustAtoms
pub weight: Option<String>,
pub topic: Option<String>,
}

#[derive(Serialize, Deserialize, SerializedBytes, Debug, Clone)]
Expand Down
9 changes: 9 additions & 0 deletions dnas/mewsfeed/workdir/dna.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ integrity:
hash: ~
bundled: "../../../target/wasm32-unknown-unknown/release/agent_pins_integrity.wasm"
dependencies: ~
- name: trust_atom_integrity
hash: ~
bundled: "../../../target/wasm32-unknown-unknown/release/trust_atom_integrity.wasm"
dependencies: ~
coordinator:
zomes:
- name: profiles
Expand Down Expand Up @@ -60,3 +64,8 @@ coordinator:
hash: ~
bundled: "../../../target/wasm32-unknown-unknown/release/ping.wasm"
dependencies: []
- name: trust_atom
hash: ~
bundled: "../../../target/wasm32-unknown-unknown/release/trust_atom.wasm"
dependencies:
- name: trust_atom_integrity
7 changes: 5 additions & 2 deletions dnas/mewsfeed/zomes/coordinator/follows/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ crate-type = ["cdylib", "rlib"]
name = "follows"

[dependencies]
hc_call_utils = { workspace = true }
hc_link_pagination = { workspace = true }
hdk = { workspace = true }
serde = { workspace = true }
follows_integrity = { workspace = true }
hc_link_pagination = { workspace = true }
follows_types = { workspace = true }
mews_types ={ workspace = true}
serde = { workspace = true }
trust_atom_types ={ workspace = true}
141 changes: 74 additions & 67 deletions dnas/mewsfeed/zomes/coordinator/follows/src/follower_to_creators.rs
Original file line number Diff line number Diff line change
@@ -1,62 +1,76 @@
use follows_integrity::*;
use follows_integrity::LinkTypes;
// use follows_integrity::*;
use follows_types::*;
use hc_call_utils::call_local_zome;
use hc_link_pagination::paginate_by_agentpubkey;
// use hc_link_pagination::paginate_by_agentpubkey;
use hdk::prelude::*;

use mews_types::FOLLOW_TOPIC;
use trust_atom_types::{DeleteReport, QueryInput, TrustAtom, TrustAtomInput};

#[hdk_extern]
pub fn add_creator_for_follower(input: AddCreatorForFollowerInput) -> ExternResult<()> {
create_link(
input.base_follower.clone(),
input.target_creator.clone(),
LinkTypes::FollowerToCreators,
(),
)?;
create_link(
input.target_creator,
input.base_follower,
LinkTypes::CreatorToFollowers,
(),
)?;

Ok(())
call_local_zome(
"trust_atom",
"create_trust_atom",
TrustAtomInput {
target: AnyLinkableHash::from(input.target_creator),
content: Some(String::from(FOLLOW_TOPIC)),
value: None,
extra: None,
},
)
}

#[hdk_extern]
pub fn get_creators_for_follower(
input: GetCreatorsForFollowerInput,
) -> ExternResult<Vec<AgentPubKey>> {
let links = get_links(
GetLinksInputBuilder::try_new(
input.follower.clone(),
LinkTypes::FollowerToCreators.try_into_filter()?,
)?
.build(),
let links_from_follower_to_creators: Vec<TrustAtom> = call_local_zome(
"trust_atom",
"query",
QueryInput {
source: Some(AnyLinkableHash::from(input.follower)),
target: None,
content_full: Some(String::from(FOLLOW_TOPIC)),
content_starts_with: None,
content_not_starts_with: None,
value_starts_with: None,
},
)?;

let links_page = paginate_by_agentpubkey(links, input.page)?;

let agents: Vec<AgentPubKey> = links_page
let creators: Vec<AgentPubKey> = links_from_follower_to_creators
.into_iter()
.filter_map(|link| EntryHash::try_from(link.target).ok())
.filter_map(|link| link.target_hash.into_entry_hash())
.map(AgentPubKey::from)
.collect();

Ok(agents)
Ok(creators)
}

#[hdk_extern]
pub fn get_followers_for_creator(
input: GetFollowersForCreatorInput,
) -> ExternResult<Vec<AgentPubKey>> {
let links = get_follower_links_for_creator(input)?;
pub fn get_followers_for_creator(creator: AgentPubKey) -> ExternResult<Vec<AgentPubKey>> {
let links_from_followers_to_creator: Vec<TrustAtom> = call_local_zome(
"trust_atom",
"query",
QueryInput {
source: None,
target: Some(AnyLinkableHash::from(creator)),
content_full: Some(String::from(FOLLOW_TOPIC)),
content_starts_with: None,
content_not_starts_with: None,
value_starts_with: None,
},
)?;

let agents: Vec<AgentPubKey> = links
let followers: Vec<AgentPubKey> = links_from_followers_to_creator
.into_iter()
.filter_map(|link| EntryHash::try_from(link.target).ok())
.filter_map(|link| link.source_hash.into_entry_hash())
.map(AgentPubKey::from)
.collect();

Ok(agents)
Ok(followers)
}

#[hdk_extern]
Expand Down Expand Up @@ -107,47 +121,40 @@ pub fn get_follower_link_details_for_creator(creator: AgentPubKey) -> ExternResu

#[hdk_extern]
pub fn remove_creator_for_follower(input: RemoveCreatorForFollowerInput) -> ExternResult<()> {
let links = get_links(
GetLinksInputBuilder::try_new(
input.base_follower.clone(),
LinkTypes::FollowerToCreators.try_into_filter()?,
)?
.build(),
let _deleted_link_count: DeleteReport = call_local_zome(
"trust_atom",
"delete_trust_atoms",
AnyLinkableHash::from(input.target_creator),
)?;

for link in links {
let entry_hash =
EntryHash::try_from(link.target.clone()).map_err(|err| wasm_error!(err))?;
if AgentPubKey::from(entry_hash).eq(&input.target_creator) {
delete_link(link.create_link_hash)?;
}
}

let links = get_links(
GetLinksInputBuilder::try_new(
input.target_creator.clone(),
LinkTypes::CreatorToFollowers.try_into_filter()?,
)?
.build(),
)?;

for link in links {
let entry_hash =
EntryHash::try_from(link.target.clone()).map_err(|err| wasm_error!(err))?;
if AgentPubKey::from(entry_hash).eq(&input.base_follower) {
delete_link(link.create_link_hash)?;
}
}

Ok(())
}

#[hdk_extern]
pub fn follow(agent: AgentPubKey) -> ExternResult<()> {
pub fn follow(input: FollowInput) -> ExternResult<()> {
let agent_pubkey = agent_info()?.agent_initial_pubkey;
if input.agent == agent_pubkey {
return Err(wasm_error!("You cannot follow yourself"));
}

add_creator_for_follower(AddCreatorForFollowerInput {
base_follower: agent_info()?.agent_initial_pubkey,
target_creator: agent,
})
base_follower: agent_pubkey,
target_creator: input.agent.clone(),
})?;

for follow_topic in input.follow_topics {
let _: TrustAtom = call_local_zome(
"trust_atom",
"create_trust_atom",
TrustAtomInput {
target: AnyLinkableHash::from(input.agent.clone()),
content: Some(follow_topic.topic),
value: Some(follow_topic.weight),
extra: None,
},
)?;
}
Ok(())
}

#[hdk_extern]
Expand Down
1 change: 1 addition & 0 deletions dnas/mewsfeed/zomes/coordinator/follows/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use hdk::prelude::*;
pub mod follower_to_creators;
pub use follower_to_creators::*;

#[hdk_extern]
pub fn init(_: ()) -> ExternResult<InitCallbackResult> {
Expand Down
2 changes: 2 additions & 0 deletions dnas/mewsfeed/zomes/coordinator/mews/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ rand = { workspace = true }
hc_call_utils = { workspace = true }
hc_link_pagination = { workspace = true }
follows_types = { workspace = true }
trust_atom = { workspace = true }
trust_atom_types = { workspace = true }
Loading
Loading