-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost-types.ts
55 lines (43 loc) · 1.61 KB
/
post-types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { Address } from '@dao-xyz/peerbit-store';
import { variant, field, vec, option } from '@dao-xyz/borsh'
import { StaticContent } from './content.js';
import { Program } from '@dao-xyz/peerbit-program';
import { DString } from '@dao-xyz/peerbit-string';
import { DynamicAccessController } from '@dao-xyz/peerbit-dynamic-access-controller';
import { v4 as uuid } from 'uuid';
@variant([2, 0])
export class NetworkPost extends StaticContent {
@field({ type: Address })
network: Address
@field({ type: vec('string') })
addresses: string[]
@field({ type: 'string' })
info: string
constructor(properties?: { network: Address, addresses: string[], info: string }) {
super();
if (properties) {
this.network = properties.network;
this.addresses = properties.addresses;
this.info = properties.info;
}
}
}
@variant([2, 0])
export class CollaborativeText extends Program {
@field({ type: DString })
text: DString // distributed string
@field({ type: option(DynamicAccessController) })
acl?: DynamicAccessController
constructor(properties?: { acl?: DynamicAccessController, text?: DString }) {
super({ id: uuid() })
this.text = properties?.text || new DString({ id: this.id })
this.acl = properties?.acl
}
async setup() {
await this.acl?.setup()
await this.text.setup({
canAppend: (entry) => (this.acl?.canAppend || (() => Promise.resolve(true)))(entry),
canRead: (identity) => (this.acl?.canRead || (() => Promise.resolve(true)))(identity)
})
}
}