Skip to content

Commit

Permalink
Replace follows with TrustAtoms
Browse files Browse the repository at this point in the history
  • Loading branch information
Harlan T Wood committed May 21, 2023
1 parent 9218ad9 commit c5f3885
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 276 deletions.
14 changes: 11 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ path = "dnas/mewsfeed/zomes/coordinator/profiles"
[workspace.dependencies.profiles_integrity]
path = "dnas/mewsfeed/zomes/integrity/profiles"

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

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

Expand Down
4 changes: 3 additions & 1 deletion crates/mews_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ pub struct FeedMew {
pub deleted_timestamp: Option<Timestamp>,
pub author_profile: Option<Profile>,
pub is_pinned: bool,
pub original_mew: Option<EmbedMew>
pub original_mew: Option<EmbedMew>,
pub weight: Option<f32>, // introduced with TrustAtoms
pub topic: Option<String>, // introduced with TrustAtoms
}

#[derive(Serialize, Deserialize, SerializedBytes, Debug, Clone)]
Expand Down
4 changes: 2 additions & 2 deletions dnas/mewsfeed/zomes/coordinator/follows/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ holochain_integrity_types = { workspace = true }
serde = { workspace = true }

follows_integrity = { workspace = true }
trust_atom_types = {git = "https://github.com/trustgraph/trustgraph-holochain.git", package = "trust_atom_types"}
# trust_atom_types = { path= "/Users/knight/code/trustgraph/trustgraph-holochain/zomes/trust_atom_types"}
# trust_atom_types = {git = "https://github.com/trustgraph/trustgraph-holochain.git", package = "trust_atom_types"}
trust_atom_types = { path= "/Users/knight/code/trustgraph/trustgraph-holochain/zomes/trust_atom_types"}
helpers = { workspace = true }
94 changes: 63 additions & 31 deletions dnas/mewsfeed/zomes/coordinator/follows/src/follower_to_creators.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use follows_integrity::*;
use hdk::prelude::*;
use helpers::call_local_zome;
use trust_atom_types::{TrustAtom, TrustAtomInput};
use trust_atom_types::{QueryInput, QueryMineInput, TrustAtom, TrustAtomInput};

#[derive(Debug, Serialize, Deserialize, SerializedBytes)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -44,26 +44,46 @@ pub fn add_creator_for_follower(input: AddCreatorForFollowerInput) -> ExternResu

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

let agents: Vec<AgentPubKey> = links
let creators: Vec<AgentPubKey> = links_from_follower_to_creators
.into_iter()
.map(|link| AgentPubKey::from(EntryHash::from(link.target)))
.map(|link| AgentPubKey::from(EntryHash::from(link.target_hash)))
.collect();

Ok(agents)
Ok(creators)
}

#[hdk_extern]
pub fn get_followers_for_creator(creator: AgentPubKey) -> ExternResult<Vec<AgentPubKey>> {
let links = get_links(creator, LinkTypes::CreatorToFollowers, None)?;
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,
value_starts_with: None,
},
)?;

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

Ok(agents)
Ok(followers)
}

#[derive(Serialize, Deserialize, Debug)]
Expand All @@ -74,37 +94,49 @@ pub struct RemoveCreatorForFollowerInput {

#[hdk_extern]
pub fn remove_creator_for_follower(input: RemoveCreatorForFollowerInput) -> ExternResult<()> {
let links = get_links(
input.base_follower.clone(),
LinkTypes::FollowerToCreators,
None,
)?;

for link in links {
if AgentPubKey::from(EntryHash::from(link.target.clone())).eq(&input.target_creator) {
delete_link(link.create_link_hash)?;
}
}

let links = get_links(
input.target_creator.clone(),
LinkTypes::CreatorToFollowers,
None,
let _deleted_link_count: usize = call_local_zome(
"trust_atom",
"delete_trust_atoms",
AnyLinkableHash::from(input.target_creator),
)?;

for link in links {
if AgentPubKey::from(EntryHash::from(link.target.clone())).eq(&input.base_follower) {
delete_link(link.create_link_hash)?;
}
}
// let links = get_links(
// input.base_follower.clone(),
// LinkTypes::FollowerToCreators,
// None,
// )?;

// for link in links {
// if AgentPubKey::from(EntryHash::from(link.target.clone())).eq(&input.target_creator) {
// delete_link(link.create_link_hash)?;
// }
// }

// let links = get_links(
// input.target_creator.clone(),
// // TODO trust atoms instead
// // LinkTypes::TrustAtom,
// None,
// )?;

// for link in links {
// if AgentPubKey::from(EntryHash::from(link.target.clone())).eq(&input.base_follower) {
// delete_link(link.create_link_hash)?;
// }
// }

Ok(())
}

#[hdk_extern]
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,
base_follower: agent_pubkey,
target_creator: input.agent.clone(),
})?;

Expand Down
10 changes: 5 additions & 5 deletions dnas/mewsfeed/zomes/coordinator/follows/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use hdk::prelude::*;
pub mod follower_to_creators;
use follows_integrity::LinkTypes;
use trust_atom_types::LinkTypes as TrustAtomLinkTypes;

#[hdk_extern]
pub fn init(_: ()) -> ExternResult<InitCallbackResult> {
Expand All @@ -12,11 +12,11 @@ pub fn init(_: ()) -> ExternResult<InitCallbackResult> {
pub enum Signal {
LinkCreated {
action: SignedActionHashed,
link_type: LinkTypes,
link_type: TrustAtomLinkTypes,
},
LinkDeleted {
action: SignedActionHashed,
link_type: LinkTypes,
link_type: TrustAtomLinkTypes,
},
}

Expand All @@ -33,7 +33,7 @@ fn signal_action(action: SignedActionHashed) -> ExternResult<()> {
match action.hashed.content.clone() {
Action::CreateLink(create_link) => {
if let Ok(Some(link_type)) =
LinkTypes::from_type(create_link.zome_index, create_link.link_type)
TrustAtomLinkTypes::from_type(create_link.zome_index, create_link.link_type)
{
emit_signal(Signal::LinkCreated { action, link_type })?;
}
Expand All @@ -47,7 +47,7 @@ fn signal_action(action: SignedActionHashed) -> ExternResult<()> {
match record.action() {
Action::CreateLink(create_link) => {
if let Ok(Some(link_type)) =
LinkTypes::from_type(create_link.zome_index, create_link.link_type)
TrustAtomLinkTypes::from_type(create_link.zome_index, create_link.link_type)
{
emit_signal(Signal::LinkDeleted { action, link_type })?;
}
Expand Down
2 changes: 1 addition & 1 deletion dnas/mewsfeed/zomes/coordinator/mews/src/all_mews.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::hashtag_to_mews::*;
use crate::mew::get_mew_with_context;
// use crate::mew::get_mew_with_context;
use crate::mew_with_context::get_batch_mews_with_context;
use hdk::prelude::*;
use helpers::call_local_zome;
Expand Down
57 changes: 0 additions & 57 deletions dnas/mewsfeed/zomes/coordinator/mews/src/mew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,63 +60,6 @@ pub fn get_mew(original_mew_hash: ActionHash) -> ExternResult<Option<Record>> {
get(original_mew_hash, GetOptions::default())
}

// TODO is this needed?
#[hdk_extern]
pub fn get_mew_with_context(original_mew_hash: ActionHash) -> ExternResult<FeedMew> {
let response = get_details(original_mew_hash.clone(), GetOptions::default())?.ok_or(
wasm_error!(WasmErrorInner::Guest(String::from("Mew not found"))),
)?;

match response {
Details::Record(RecordDetails {
record, deletes, ..
}) => {
let mew: Mew = record
.entry()
.to_app_option()
.map_err(|e| wasm_error!(WasmErrorInner::Guest(e.into())))?
.ok_or(wasm_error!(WasmErrorInner::Guest(String::from(
"Malformed mew"
))))?;

let replies = get_response_hashes_for_mew(GetResponsesForMewInput {
original_mew_hash: original_mew_hash.clone(),
response_type: Some(ResponseType::Reply),
})?;
let quotes = get_response_hashes_for_mew(GetResponsesForMewInput {
original_mew_hash: original_mew_hash.clone(),
response_type: Some(ResponseType::Quote),
})?;
let mewmews = get_response_hashes_for_mew(GetResponsesForMewInput {
original_mew_hash: original_mew_hash.clone(),
response_type: Some(ResponseType::Mewmew),
})?;
let licks = get_lickers_for_mew(original_mew_hash)?;

let deleted_timestamp = deletes
.first()
.map(|first_delete| first_delete.action().timestamp());

let feed_mew_and_context = FeedMew {
mew,
action: record.action().clone(),
action_hash: record.signed_action().as_hash().clone(),
replies,
quotes,
licks,
mewmews,
deleted_timestamp,
weight: None, // TODO is this correct?
topic: None, // TODO is this correct?
};
Ok(feed_mew_and_context)
}
_ => Err(wasm_error!(WasmErrorInner::Guest(
"Expecting get_details to return record, got entry".into()
))),
}
}

#[hdk_extern]
pub fn delete_mew(original_mew_hash: ActionHash) -> ExternResult<ActionHash> {
let maybe_record = get(original_mew_hash.clone(), GetOptions::default())?;
Expand Down
25 changes: 14 additions & 11 deletions dnas/mewsfeed/zomes/coordinator/mews/src/mew_with_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ pub fn get_mew_with_context(original_mew_hash: ActionHash) -> ExternResult<FeedM
deleted_timestamp,
author_profile,
is_pinned,
original_mew: None
original_mew: None,
weight: None, // TODO is this correct?
topic: None, // TODO is this correct?
}),
MewType::Reply(response_to_hash)
| MewType::Quote(response_to_hash)
Expand All @@ -66,7 +68,8 @@ pub fn get_mew_with_context(original_mew_hash: ActionHash) -> ExternResult<FeedM
Details::Record(record_details) => {
let original_mew_author_profile =
get_agent_profile(record_details.record.action().author().clone())?;
let original_mew_deleted_timestamp = record_details.deletes
let original_mew_deleted_timestamp = record_details
.deletes
.first()
.map(|first_delete| first_delete.action().timestamp());

Expand All @@ -90,15 +93,15 @@ pub fn get_mew_with_context(original_mew_hash: ActionHash) -> ExternResult<FeedM
author_profile,
deleted_timestamp,
is_pinned,
original_mew: Some(
EmbedMew {
mew: original_mew,
action: record_details.record.action().clone(),
action_hash: record_details.record.action_hashed().clone().hash,
author_profile: original_mew_author_profile,
deleted_timestamp: original_mew_deleted_timestamp,
}
),
original_mew: Some(EmbedMew {
mew: original_mew,
action: record_details.record.action().clone(),
action_hash: record_details.record.action_hashed().clone().hash,
author_profile: original_mew_author_profile,
deleted_timestamp: original_mew_deleted_timestamp,
}),
weight: None, // TODO we probably need to fetch these for the current agent -- same mew has diff topic/weight when viewed by diff agents
topic: None,
})
}
_ => Err(wasm_error!(WasmErrorInner::Guest(String::from(
Expand Down
Loading

0 comments on commit c5f3885

Please sign in to comment.