Documentation / Build / Teams inside a community
Teams inside a community
A team is a smaller body inside a community that decides some things on its own. This page starts a community with 1 team and lets the team change a page.
The examples use the option teams in Copy.start and the body { type: 'team', id } for a decision of a team.
1Name the team when you start
A team has an id, a name, a list of member ids, the pages it keeps and its powers. memberId turns the public signing key of a member into that member's id.
The team Boat crews below has 3 of the 5 members and keeps the Boat rota page. Its power keep-pages lets it change that page.
import { ready, newKeyPair, publicOf, memberId } from 'protocol0'
import { syncDirect, Copy, type KeyPair } from 'protocol0'
await ready()
const [ann, bob, cat, dan, eve] = [1, 2, 3, 4, 5].map(() => newKeyPair())
const id = (key: KeyPair) => memberId(publicOf(key).sign)
const relief = Copy.start({
key: ann,
me: { name: 'Ann' },
name: 'Flood Relief Network',
founders: [
{ name: 'Bob', key: publicOf(bob) },
{ name: 'Cat', key: publicOf(cat) },
{ name: 'Dan', key: publicOf(dan) },
{ name: 'Eve', key: publicOf(eve) },
],
pages: [{ id: 'rota', name: 'Boat rota', content: 'Crew 1 takes the boat on Monday.' }],
teams: [
{
id: 'boats',
name: 'Boat crews',
members: [id(ann), id(bob), id(cat)],
pages: ['rota'],
powers: ['keep-pages'],
},
],
})
const team = relief.view().teams[0]
console.log(team.name + ' has ' + team.members.length + ' of 5 members')2Let the team decide
A proposal names the team as its body. Only members of the team count and the team needs more than half of its own members.
Ann proposes a change of the Boat rota page with the team as body. The team has 3 members so the proposal needs 2 signatures.
const code = relief.propose({
title: 'Boat rota for this week',
change: { type: 'page', page: 'rota', content: 'Crew 2 takes the boat on Monday.' },
body: { type: 'team', id: 'boats' },
})
const open = relief.view().proposals[0]
const signed = open.count + ' of ' + open.size + ' team members signed'
console.log(signed + ' and ' + open.needed + ' are needed')3Read it from outside the team
Bob is in the team and signs while Dan is not in the team and cannot sign but every member of the community can read what a team decides.
const bobsCopy = Copy.load({ key: bob, items: relief.items() })
const dansCopy = Copy.load({ key: dan, items: relief.items() })
bobsCopy.sign(code)
syncDirect(relief, bobsCopy, dansCopy)
const seen = dansCopy.view()
const rota = seen.pages.find((p) => p.id === 'rota')
const status = seen.proposals[0].status
console.log('Dan is outside the team and sees the proposal as ' + status)
console.log('Dan reads ' + rota?.content)Boat crews has 3 of 5 members
1 of 3 team members signed and 2 are needed
Dan is outside the team and sees the proposal as decided
Dan reads Crew 2 takes the boat on Monday.The program prints the size of the team, the count of the proposal and what Dan sees once Bob has signed.
4Give a team powers
A decision of the whole community gives a team up to 3 powers.
keep-pageslets the team change the pages it keeps.hide-postlets the team hide a post and every copy then deletes its words.pause-memberlets the team pause the posting of a member for up to 30 days.
A team can hold a team down to 2 levels deep and only the community changes who is in a team.
Something wrong on this page