Kizuna
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Contacts Zome ###### tags: `Kizuna-architecture` <img src="https://i.imgur.com/IxrnWIH.png" width=200 align="inline"/> User Stories - * [get a list of all of my blocked contacts](https://beyonder.atlassian.net/browse/KIZUNA-23) * [get a list of all of my contacts](https://beyonder.atlassian.net/browse/KIZUNA-22) * [add another user to contacts](https://beyonder.atlassian.net/browse/KIZUNA-10) * [remove someone from contacts](https://beyonder.atlassian.net/browse/KIZUNA-19) * [block someone from contacts](https://beyonder.atlassian.net/browse/KIZUNA-20) * [unblock someone from contacts](https://beyonder.atlassian.net/browse/KIZUNA-21) * [I don't want to receive messages from contacts that I blocked](https://beyonder.atlassian.net/browse/KIZUNA-294) * [check whether an agent is in my contacts](https://beyonder.atlassian.net/browse/KIZUNA-24) * [check whether an agent is in my blocked list](https://beyonder.atlassian.net/browse/KIZUNA-409) ### Comments - username -> agentpubkey (in ui work with agentpubkey not username) - return error instead - accommodate multiple agents to be operated on ## Entry Structure ```rust= enum ContactType { Add, Remove, Block, Unblock, AddToCategory } struct CategoryWithId { id: String, name: String, } #[hdk_entry(id = "contact", visibility = "private")] pub struct Contacts { // allows multiple agents to be added etc. agent_ids: Vec<AgentPubkey>, created: Timestamp, contact_type: ContactType, category: Option<CategoryWithId> } #[hdk_entry(id = "category", visibility = "private")] pub struct Category { name: String, } #[hdk_entry(id = "alias", visibility = "private")] pub struct Alias { id: AgentPubKey, first_name: Option<String>, last_name: Option<String> } ``` ## Contact Entry Conditionals - This is to show the general pattern of OpType that can be done to a Contact entry ![](https://i.imgur.com/WrHf8bg.png) ## Zome Fn ### `add_contacts` ```rust pub fn add_contacts(agent_ids: AgentPubKeysWrapper) -> ExternResult<AgentPubKeysWrapper> ``` ```mermaid sequenceDiagram participant AUI as Alice_UI participant ACD as Alice_Cell AUI-->>ACD: agent pubkeys ACD-->>ACD: call get_latest_contacts_info() opt same agent was operated as contact before alt added ACD-->>AUI: Err("agent already added") else blocked ACD-->>AUI: Err("agent is blocked") end end ACD-->>ACD: commit Contact entry with ContactType Add ACD-->>AUI: return AgentPubKeysWrapper ``` ### `remove_contacts` ```rust pub fn remove_contacts(agent_ids: AgentPubKeysWrapper) -> ExternResult<AgentPubKeysWrapper> ``` ```mermaid sequenceDiagram participant AUI as Alice_UI participant ACD as Alice_Cell AUI-->>ACD: agent pubkeys ACD-->>ACD: call get_latest_contacts_info() opt same agent was operated as contact before alt removed/unblocked/None ACD-->>AUI: Err("agent is already removed") else blocked ACD-->>AUI: Err("agent is blocked") end end ACD-->>ACD: commit Contact entry with ContactType Remove ACD-->>AUI: return AgentPubKeysWrapper ``` ### `block_contacts` ```rust pub fn block_contacts(agent_ids: AgentPubKeysWrapper) -> ExternResult<AgentPubKeysWrapper> ``` ```mermaid sequenceDiagram participant AUI as Alice_UI participant ACD as Alice_Cell AUI-->>ACD: agent pubkeys ACD-->>ACD: call get_latest_contacts_info() opt same agent was operated as contact before alt blocked ACD-->>AUI: Err("this agent is already blocked") end end ACD-->>ACD: commit Contact entry with ContactType Block ACD-->>AUI: return AgentPubKeysWrapper ``` ### `unblock_contacts` ```rust pub fn unblock_contacts(agent_ids: AgentPubKeysWrapper) -> ExternResult<AgentPubKeysWrapper> ``` ```mermaid sequenceDiagram participant AUI as Alice_UI participant ACD as Alice_Cell AUI-->>ACD: agent pubkeys ACD-->>ACD: call get_latest_contacts_info() opt same agent was operated as contact before alt unblocked/none/removed ACD-->>AUI: Err("agent is already unblocked") else added ACD-->>AUI: Err("agent cannot be unblocked if added") end end ACD-->>ACD: commit Contact entry with ContactType Unblock ACD-->>AUI: AgentPubKeysWrapper ``` ### `list_added_or_blocked` - helper function used for the zome fn `list_added` and `list_blocked` ```rust pub struct AgentPubKeysWrapper(pub Vec<AgentPubkey>) pub fn list_added_or_blocked(filter: ContactType) -> ExternResult<AgentPubKeysWrapper> ``` ```mermaid sequenceDiagram participant AUI as Alice_UI participant ACD as Alice_Cell AUI-->>ACD: call list_added() or list_blocked() ACD-->>ACD: create an empty HashMap<AgentPubKey, Vec<Contact>> ACD-->>ACD: query all Contacts loop for contact in queried contacts alt first Contact for an agent ACD-->>ACD: insert the contact with key being agentpubkey else agent already has another Contact entry ACD-->>ACD: push the contact to Vec<Contact> end end loop for agentpubkey in HashMap ACD-->>ACD: check the latest Contact for the agent with created field alt both filter and latest Contact's Contact Type are ContactType:Add ACD-->>ACD: include the agentpubkey of agent in AgentPubKeysWrapper else both filter and latest Contact's Contact Type are ContactType:Block ACD-->>ACD: include the agentpubkey of agent in AgentPubKeysWrapper else other ContactType ACD-->>ACD: ignore end end ACD-->>AUI: return AgentPubKeysWrapper ``` ### `in_contacts` - needs to check if this function is still needed ```rust pub struct BooleanWrapper(pub bool); pub fn in_contacts(agent_pubkey: AgentPubKey) -> ExternResult<BooleanWrapper> ``` ```mermaid sequenceDiagram participant AUI as Alice_UI participant ACD as Alice_Cell participant LDHT as Lobby_DHT ACD-->>ACD: call list_added() ACD-->>ACD: check if the given AgentPubKey is part of the contacts ACD-->>ACD: return boolean ``` ### `in_blocked` - needs to check if this function is still needed ```rust pub struct BooleanWrapper(pub bool); pub fn in_blocked(agent_pubkey: AgentPubKey) -> ExternResult<BooleanWrapper> ``` ```mermaid sequenceDiagram participant AUI as Alice_UI participant ACD as Alice_Cell participant LDHT as Lobby_DHT ACD-->>ACD: call list_blocked() ACD-->>ACD: check if the given AgentPubKey is part of the blocked contacts ACD-->>ACD: return boolean ``` ### `update_alias` ```rust pub struct AliasInput { id: AgentPubKey, first_name: Option<String>, last_name: Option<String> } pub fn create_alias(input: AliasInput) -> ExternResult<Alias> ``` ### `list_alias` ```rust pub struct AliasInput { id: AgentPubKey, first_name: String, last_name: String }pub fn list_alias(input: AliasInput) -> ExternResult<Vec<Alias>> ``` ## Redux State ```javascript= type ProfileID = string; export interface Profile { id: ProfileID; username: string; first_name?: string; last_name?: stringl } export interface IndexedContacts { [key: string]: Profile[]; } export interface ContactsState { contacts: Profile[]; blocked: Profile[]; indexedContacts: IndexedContacts; } // redux state const initialState: ContactsState = { contacts: [], indexedContacts: {}, blocked: [], }; ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully