Skip to content

Commit

Permalink
Revert "chore: delete no longer relevant todo comments, commented out…
Browse files Browse the repository at this point in the history
… code"
  • Loading branch information
mattyg authored Oct 27, 2024
1 parent a735a87 commit d8c9612
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 12 deletions.
2 changes: 2 additions & 0 deletions dnas/relay/zomes/coordinator/relay/src/contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ pub fn get_latest_contact(
}
None => original_contact_hash.clone(),
};
//get(latest_contact_hash, GetOptions::default())
// TODO: is this best practice or should we just return the Record?
match get(latest_contact_hash, GetOptions::default())? {
Some(record) => {
Ok(Some(ContactRecord {
Expand Down
1 change: 1 addition & 0 deletions dnas/relay/zomes/coordinator/relay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod contact;
pub mod message;
pub mod config;
pub mod ping;
// pub mod utils;
use hdk::prelude::*;
use relay_integrity::*;

Expand Down
79 changes: 76 additions & 3 deletions dnas/relay/zomes/coordinator/relay/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use hdk::prelude::*;
use relay_integrity::*;

use crate::get_entry_for_action;
// use chrono::{DateTime, Utc, Datelike};
// use crate::utils::*;

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
Expand All @@ -20,7 +22,18 @@ pub fn create_message(input: SendMessageInput) -> ExternResult<Record> {
.to_string())
),
)?;

// let now: DateTime<Utc> = Utc::now();
// let year = now.year();
// let month = now.month();
// let week = now.iso_week().week();
// let formatted_date = format!("{}/{}/{}", year, month, week);
// let path = Path::from(formatted_date);
// create_link_relaxed(
// path.path_entry_hash()?,
// AnyLinkableHash::try_from(record.action_address().clone())?,
// LinkTypes::MessageBlock,
// (),
// )?;
let path = messages_path(input.message.bucket);
debug!("create_message path {:?}", path);
let link = create_link(
Expand All @@ -30,6 +43,7 @@ pub fn create_message(input: SendMessageInput) -> ExternResult<Record> {
(),
)?;

// TODO: handle errors. look for ack, try again on fail
let _ = send_remote_signal(
MessageRecord {
message: Some(input.message),
Expand All @@ -43,6 +57,44 @@ pub fn create_message(input: SendMessageInput) -> ExternResult<Record> {
Ok(record)
}

// pub struct MessageBlock {
// week: String,
// count: u32,
// hashes: SignedActionHashed,
// }

// pub struct GetMessageHashesForWeekInput {
// pub week: String,
// pub message_count_already_loaded: u8,
// }
// #[hdk_extern]
// pub fn get_messages_hashes_for_week(
// input: GetMessageHashesForWeekInput,
// ) -> ExternResult<MessageBlock> {
// let weekString = input.week;
// if (weekString.is_empty()) {
// let now: DateTime<Utc> = Utc::now();
// let year = now.year();
// let month = now.month();
// let week = now.iso_week().week();
// weekString = format!("{}/{}/{}", year, month, week);
// }
// let path = Path::from(weekString);
// //let links = get_links(path.path_entry_hash()?, LinkTypes::MessageBlock, None)?;
// let links = get_links(
// GetLinksInputBuilder::try_new(path.path_entry_hash()?, LinkTypes::MessageBlock)?
// .build(),
// );
// let mut results = Vec::new();
// for l in links {
// let hash = ActionHash::try_from(l.target).map_err(|e| wasm_error!(e))?;
// if let Some(r) = get_latest_message(hash)? {
// results.push(r);
// }
// }
// Ok(results)
// }

#[derive(Serialize, Deserialize, Debug)]
pub struct BucketInput {
pub bucket: u32,
Expand Down Expand Up @@ -97,14 +149,35 @@ pub fn get_message_entries(hashes: Vec<ActionHash>) -> ExternResult<Vec<MessageR
Ok(results)
}

// TODO deprecate
#[hdk_extern]
pub fn get_messages_for_buckets(buckets: Vec<u32>) -> ExternResult<Vec<MessageRecord>> {
let links = get_message_links_for_buckets(buckets)?;
let mut results: Vec<MessageRecord> = Vec::new();
for l in links {
let hash = ActionHash::try_from(l.target).map_err(|e|wasm_error!(e))?;
if let Some(r) = get_latest_message(hash)? {
results.push(r);
// TODO: make a call to the profiles zome to get the agent profile
// TODO: why did i think this was necessary ??
// let call_input = GetAgenProfileInput {
// agent_key: r.signed_action.hashed.author().clone(),
// };
// let agent = call(
// CallTargetCell::Local,
// "profiles",
// "get_agent_profile".into(),
// None,
// call_input,
// );
// if let ZomeCallResponse::Ok(response) = call(CallTargetCell::Local,"profiles",FunctionName::new("get_agent_profile"), None, call_input)? {
// let agent : Record<Profile> = response.decode().map_err(|_e| wasm_error!(WasmErrorInner::Guest(String::from("could not decode agent profile"))))?;
// // let me = agent_info()?.agent_latest_pubkey;
// //let agents = agents.into_iter().filter(|a| a != &me).collect();
// debug!("agent {:?}", agent);
// r.message.unwrap().author_name = agent;
// }

results.push (r);
}
}

Expand Down Expand Up @@ -139,7 +212,7 @@ pub fn get_latest_message(
}
None => original_message_hash.clone(),
};

// get(latest_message_hash, GetOptions::default())
match get(latest_message_hash, GetOptions::default())? {
Some(record) => {
Ok(Some(MessageRecord {
Expand Down
2 changes: 2 additions & 0 deletions dnas/relay/zomes/integrity/relay/src/contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ pub fn validate_create_link_all_contacts(
.to_string())
),
)?;
// TODO: add the appropriate validation rules
Ok(ValidateCallbackResult::Valid)
}

Expand All @@ -171,5 +172,6 @@ pub fn validate_delete_link_all_contacts(
_target: AnyLinkableHash,
_tag: LinkTag,
) -> ExternResult<ValidateCallbackResult> {
// TODO: add the appropriate validation rules
Ok(ValidateCallbackResult::Valid)
}
2 changes: 2 additions & 0 deletions dnas/relay/zomes/integrity/relay/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub fn validate_create_link_all_messages(
.to_string())
),
)?;
// TODO: add the appropriate validation rules
Ok(ValidateCallbackResult::Valid)
}
pub fn validate_delete_link_all_messages(
Expand All @@ -133,5 +134,6 @@ pub fn validate_delete_link_all_messages(
_target: AnyLinkableHash,
_tag: LinkTag,
) -> ExternResult<ValidateCallbackResult> {
// TODO: add the appropriate validation rules
Ok(ValidateCallbackResult::Valid)
}
3 changes: 2 additions & 1 deletion ui/src/lib/LightboxImage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
items: [
{
// Because we don't know the original image dimensions,
// we scale by 10x and let bigger-picture handle constraining within window
// we scale by 10x and let bigger-picture handle constaining within window
// TODO: use the original image dimensions either by publishing to DHT or determining after downloading image
width: targetImg.width * 10,
height: targetImg.height * 10,
img: src,
Expand Down
12 changes: 5 additions & 7 deletions ui/src/routes/conversations/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@
})
}
const checkForData = () => {
checkForAgents()
checkForConfig()
checkForMessages()
}
function handleResize() {
if (scrollAtBottom) {
scrollToBottom();
Expand All @@ -102,7 +96,10 @@
// messages = c.messages;
numMembers = Object.values(agentProfiles).length;
});
checkForData();
// TODO: do this check in one call of checkForStuff
checkForAgents()
checkForConfig()
checkForMessages()
conversationContainer.addEventListener('scroll', handleScroll);
window.addEventListener('resize', debouncedHandleResize);
newMessageInput.focus();
Expand Down Expand Up @@ -133,6 +130,7 @@
messages.forEach(message => {
// Don't display message if we don't have a profile from the author yet.
// TODO: could wait until all profiles have been synced first?
if (!agentProfiles[message.authorKey]) {
return;
}
Expand Down
2 changes: 2 additions & 0 deletions ui/src/routes/conversations/[id]/invite/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
}
async function addContactsToConversation() {
// TODO: update config.title?
if (conversation) {
conversation.addContacts($selectedContacts)
goto(`/conversations/${conversation.id}/details`)
Expand Down
4 changes: 3 additions & 1 deletion ui/src/store/ConversationStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class ConversationStore {
}

const invitation: Invitation = {
created: this.created,
created: this.created, // TODO: put in data
progenitor: this.data.progenitor,
privacy: this.data.privacy,
proof,
Expand Down Expand Up @@ -220,6 +220,7 @@ export class ConversationStore {
}

get title() {
// TODO: when invited contacts is stored in HC this can go back to invitedContactKeys
const numInvited = this.allMembers.length
if (this.data?.privacy === Privacy.Public) {
return this.data?.config.title
Expand Down Expand Up @@ -356,6 +357,7 @@ export class ConversationStore {
const id = uuidv4()
const oldMessage: Message = { authorKey, content, hash: id, status: 'pending', timestamp: now, bucket, images}
this.addMessage(oldMessage)
// TODO: upload these images asynchonously and then add to the message when done
const imageStructs = await Promise.all(images.filter(i => !!i.file).map(async (image) => {
const hash = await this.fileStorageClient.uploadFile(image.file!)
return {
Expand Down
1 change: 1 addition & 0 deletions ui/src/store/RelayStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export class RelayStore {

async createContact(contact: Contact) {
if (!this.client) return false
// TODO: if adding contact fails we should remove it from the store
const contactResult = await this.client.createContact(contact)
if (contactResult) {
// Immediately add a conversation with the new contact, unless you already have one with them
Expand Down

0 comments on commit d8c9612

Please sign in to comment.