---
# System prepended metadata

title: Group Roles　(Same DHT)
tags: [Kizuna-architecture]

---

# Group Roles　(Same DHT)
###### tags: `Kizuna-architecture`

## User Story
- [As an admin, I want to remove a member from the group so that I can control members of the group](https://beyonder.atlassian.net/browse/KIZUNA-74)
- [As an admin, I want to add a member to the group so that that user can join in the conversation](https://beyonder.atlassian.net/browse/KIZUNA-71)

## Comments/todo/questions
- this design assumes synchronicity among agents
- no error handling yet
- It's better to use events sourced pattern (change the entry structure)
- We need to achieve idempotency. i.e. even if some agents did not successfully get notified to join the the group should, the invited agent should still be able to join. The other agents should be notified later again.
- How do we update shared keys when a member joins or leave(or do we have pairwise keys with every member?)
- newly joined agents wont probably be able to read the messages sent before

## Entry Definitions
```rust
struct Group {
    uuid: String,
    name: String, 
    created: Timestamp,
    creator: AgentPubKey, // for now this is the only admin
    members: Vec<AgentPubKey>
}
// private entry commited in source chain
pub struct Groups {
    group: Vec<Group>,
    blocked: Vec<Group>
}
```

#### Add Flow
```mermaid
sequenceDiagram
    participant AUI as Alice_UI
    participant ALD as Alice_Lobby_DNA
    participant BUI as Bobby_UI
    participant BLD as Bobby_Lobby_DNA
    participant CUI as Charlie_UI
    participant CLD as Charlie_Lobby_DNA
    participant DUI as Diego_UI
    participant DLD as Diego_Lobby_DNA
    participant LDHT as Lobby_DHT
    
    AUI-->>AUI: invite diego to the group
    AUI-->>ALD: call add_member with agentpubkey of diego and the groupinfo
    alt capgrant available
    par alice to bob
    ALD-->>BLD: call_remote add_member
    BLD-->>BLD: update group and add diego's pubkey to receivers
    BLD-->>ALD: return add sucess
    and alice to charlie
    note right of CLD: same process
    end
    ALD-->>DLD: notify join in a group
    DLD-->>DUI: emit_signal that group was joined
    DUI-->>DUI: show the accept, delete, block banner
    end
```

#### Remove Flow
```mermaid
sequenceDiagram
    participant AUI as Alice_UI
    participant ALD as Alice_Lobby_DNA
    participant BUI as Bobby_UI
    participant BLD as Bobby_Lobby_DNA
    participant CUI as Charlie_UI
    participant CLD as Charlie_Lobby_DNA
    participant DUI as Diego_UI
    participant DLD as Diego_Lobby_DNA
    participant LDHT as Lobby_DHT
    
    AUI-->>AUI: remove diego from the group
    AUI-->>ALD: call remove_member with agentpubkey of diego and the groupinfo
    alt capgrant available
    par alice to bob
    ALD-->>BLD: call_remote remove_member
    BLD-->>BLD: update group and remove diego's pubkey
    BLD-->>ALD: return remove sucess
    and alice to charlie
    note right of CLD: same process
    end
    ALD-->>DLD: call_remote remove_from_group 
    DLD-->>DLD: remove cap_grant of admin for add_member and remove_member and remove_from_group
    DLD-->>DLD: remove group from Groups
    DLD-->>DUI: emit_signal that group was removed
    DUI-->>DUI: disable send chat to that group
    end
```