-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from mattyg/feat/signal-short-term-updates
Feat/signal short term updates
- Loading branch information
Showing
29 changed files
with
2,242 additions
and
12,729 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ node_modules | |
.direnv | ||
dist | ||
.cargo | ||
target | ||
target | ||
tsconfig.tsbuildinfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,15 @@ | ||
use hdk::prelude::*; | ||
use hc_zome_yjs_integrity::*; | ||
use hdk::prelude::*; | ||
#[hdk_extern] | ||
pub fn get_all_documents(_: ()) -> ExternResult<Vec<Record>> { | ||
let path = Path::from("all_documents"); | ||
let links = get_links(path.path_entry_hash()?, LinkTypes::AllDocuments, None)?; | ||
let get_input: Vec<GetInput> = links | ||
.into_iter() | ||
.filter_map(|link| AnyDhtHash::try_from(link.target).ok()) | ||
.map(|hash| GetInput::new( | ||
hash, | ||
GetOptions::default(), | ||
)) | ||
.map(|hash| GetInput::new(hash, GetOptions::default())) | ||
.collect(); | ||
let records = HDK.with(|hdk| hdk.borrow().get(get_input))?; | ||
let records: Vec<Record> = records.into_iter().filter_map(|r| r).collect(); | ||
let records: Vec<Record> = records.into_iter().flatten().collect(); | ||
Ok(records) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use hc_zome_yjs_integrity::*; | ||
use hdk::prelude::*; | ||
|
||
#[derive(Serialize, Deserialize, SerializedBytes, Debug, Clone)] | ||
pub struct AddAgentForDocumentInput { | ||
pub base_document_hash: ActionHash, | ||
pub target_agent: AgentPubKey, | ||
} | ||
#[hdk_extern] | ||
pub fn add_agent_for_document(input: AddAgentForDocumentInput) -> ExternResult<()> { | ||
create_link( | ||
input.base_document_hash, | ||
input.target_agent, | ||
LinkTypes::DocumentToAgents, | ||
(), | ||
)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[hdk_extern] | ||
pub fn remove_agent_for_document(input: AddAgentForDocumentInput) -> ExternResult<()> { | ||
let links = get_links(input.base_document_hash, LinkTypes::DocumentToAgents, None)?; | ||
|
||
let agent_links: Vec<Link> = links | ||
.into_iter() | ||
.filter(|link| { | ||
AgentPubKey::try_from(link.target.clone()).ok().unwrap() == input.target_agent | ||
}) | ||
.collect(); | ||
|
||
for link in agent_links { | ||
delete_link(link.create_link_hash)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
#[hdk_extern] | ||
pub fn get_agents_for_document(document_hash: ActionHash) -> ExternResult<Vec<AgentPubKey>> { | ||
let links = get_links(document_hash, LinkTypes::DocumentToAgents, None)?; | ||
|
||
let agents: Vec<AgentPubKey> = links | ||
.into_iter() | ||
.filter_map(|link| AgentPubKey::try_from(link.target).ok()) | ||
.collect(); | ||
|
||
Ok(agents) | ||
} | ||
|
||
#[hdk_extern] | ||
pub fn get_other_agents_for_document(document_hash: ActionHash) -> ExternResult<Vec<AgentPubKey>> { | ||
let mypubkey = agent_info()?.agent_initial_pubkey; | ||
let agents = get_agents_for_document(document_hash)? | ||
.into_iter() | ||
.filter(|agent| agent != &mypubkey) | ||
.collect(); | ||
|
||
Ok(agents) | ||
} | ||
|
||
#[hdk_extern] | ||
pub fn ensure_agent_for_document(input: AddAgentForDocumentInput) -> ExternResult<()> { | ||
let agents = get_agents_for_document(input.clone().base_document_hash)?; | ||
|
||
let has_agent = agents | ||
.into_iter() | ||
.any(|agent| agent == input.clone().target_agent); | ||
|
||
if !has_agent { | ||
add_agent_for_document(input)?; | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.