---
# System prepended metadata

title: Subreddits zome

---

# Subreddits zome

## User stories
- An agent should be able to create a subreddit
- An agent should be able to update the admins of the subreddit
- A subreddit's admin should be able to update the subreddit's info
- Any agent should be able to subscribe to a subreddit

## Entry structure

This first anchor type is from [holochain_anchors](https://github.com/holochain/holochain_anchors)

```rust
Entry "anchor" {
    struct Anchor {
        anchor_type: String,
        anchor_text: Option<String>
    }
    Links: {
        anchor->post
        agent_id->anchor|subscribed_to|
        anchor->agent_id|subscribers|
    }
}

Entry "subreddit" {
    struct Subreddit {
        name: String,
        admins: Vec<Address>,
        description: String,
        image: String, // base64 encoded
        last_header_address: Option<Address> // To avoid update entry cycles
    }
    Links: {
        anchor->subreddit|last_version|
    }
}
```

Anchors will contain this:

```rust
{
  anchor_type: "subreddit",
  anchor_text: "<SUBREDDIT_NAME>"
}
```

> There is one piece of rivalrous data: the name of the subreddit. We cannot guarantee that only one subreddit entry with the same name will exist in the DHT (think network partitions), and we don't have the specific implementation of the DHT conflict resolution callback mechanism (will only work on updates...?, can also work on attaching links...?).
> So in the future this needs to be updated, maybe to force agents to update an already existing entry that only contains the name, and thus triggering the conflict resolution callback.

## Entry relationship diagram

```mermaid
graph TD
  subgraph postszome
    subgraph anchors
      all_subreddits-->holochain_anchor
      all_subreddits-->ethereum_anchor
    end
    subgraph agents
      alice_id-->|subscribed_to|holochain_anchor
      holochain_anchor-->|subscribers|alice_id
    end
    subgraph subreddits
      ethereum_anchor-->|last_version|ethereum_subredditv1
      ethereum_anchor-->ethereum_subredditv0
      ethereum_subredditv0==>ethereum_subredditv1
      holochain_anchor-->holochain_subredditv0
    end
    subgraph posts
      holochain_anchor-->post1
    end
  end
```

## Validation

### Entries

* `anchors`:
  * Create is always valid
  * Update or Delete is not valid
* `subreddit`:
  * Create or Update is valid if any of the agent_address signing it is contained inside the current administrator vector
  *  Delete not valid

### Links
* `anchor->subreddit`: 
  * AddLink valid if is signed by any of the admins contained in the subreddit target entry
  * RemoveLink not valid
* `agent_id->anchor` & `anchor->agent_id`: only valid if the agent is signing
* `anchor->post` valid always since anyone can post and repost any post to any subreddit