Differences From
Artifact [a0814e5c61]:
1 1 -- vim: ft=terra
2 -local m = {}
3 -
4 -local backend = {
5 - pgsql = {
2 +local m = {
3 + timepoint = uint64;
4 + scope = lib.enum {
5 + 'public', 'private', 'local';
6 + 'personal', 'direct', 'circle';
7 + };
8 + notiftype = lib.enum {
9 + 'mention', 'like', 'rt', 'react'
10 + };
11 + relation = lib.enum {
12 + 'follow', 'mute', 'block'
6 13 };
7 14 }
8 15
9 -struct m.user {
10 - uid: rawstring
11 - nym: rawstring
12 - handle: rawstring
16 +local str = lib.mem.ptr(int8)
17 +str:complete()
18 +
19 +struct m.source
20 +
21 +struct m.rights {
22 + rank: uint16 -- lower = more powerful except 0 = regular user
23 + -- creating staff automatically assigns rank immediately below you
24 + quota: uint32 -- # of allowed tweets per day; 0 = no limit
25 +
26 + -- user powers -- default on
27 + login: bool
28 + visible: bool
29 + post: bool
30 + shout: bool
31 + propagate: bool
32 + upload: bool
33 +
34 + -- admin powers -- default off
35 + ban: bool
36 + config: bool
37 + censor: bool
38 + suspend: bool
39 + rebrand: bool -- modify site's brand identity
40 +}
41 +
42 +terra m.rights_default()
43 + return m.rights {
44 + rank = 0, quota = 1000;
45 +
46 + login = true, visible = true, post = true;
47 + shout = true, propagate = true, upload = true;
48 +
49 + ban = false, config = false, censor = false;
50 + suspend = false, rebrand = false;
51 + }
52 +end
53 +
54 +struct m.actor {
55 + id: uint64
56 + nym: str
57 + handle: str
58 + origin: uint64
59 + bio: str
60 + rights: m.rights
61 + key: str
62 +
63 + source: &m.source
64 +}
65 +terra m.actor:free()
66 + self.nym:free()
67 + self.handle:free()
68 + self.bio:free()
69 + self.key:free()
70 +end
71 +
72 +struct m.range {
73 + time: bool
74 + union {
75 + from_time: m.timepoint
76 + from_idx: uint64
77 + }
78 + union {
79 + to_time: m.timepoint
80 + to_idx: uint64
81 + }
82 +}
83 +
84 +struct m.post {
85 + id: uint64
86 + author: uint64
87 + subject: str
88 + body: str
89 + posted: m.timepoint
90 + discovered: m.timepoint
91 + scope: m.scope.t
92 + mentions: lib.mem.ptr(uint64)
93 + circles: lib.mem.ptr(uint64) --only meaningful if scope is set to circle
94 + convo: uint64
95 + parent: uint64
96 +
97 + source: &m.source
98 +}
99 +
100 +local cnf = terralib.memoize(function(ty,rty)
101 + rty = rty or ty
102 + return struct {
103 + enum: {&opaque, uint64, rawstring} -> intptr
104 + get: {&opaque, uint64, rawstring} -> rty
105 + set: {&opaque, uint64, rawstring, ty} -> {}
106 + reset: {&opaque, uint64, rawstring} -> {}
107 + }
108 +end)
109 +
110 +struct m.notif {
111 + kind: m.notiftype.t
112 + when: uint64
113 + union {
114 + post: uint64
115 + reaction: int8[8]
116 + }
117 +}
118 +
119 +-- backends only handle content on the local server
120 +struct m.backend { id: rawstring
121 + open: &m.source -> &opaque
122 + close: &m.source -> {}
123 +
124 + conf_get: {&m.source, rawstring} -> lib.mem.ptr(int8)
125 + conf_set: {&m.source, rawstring, rawstring} -> {}
126 + conf_reset: {&m.source, rawstring} -> {}
127 +
128 + actor_save: {&m.source, m.actor} -> bool
129 + actor_create: {&m.source, m.actor} -> bool
130 + actor_fetch_xid: {&m.source, rawstring} -> lib.stat(m.actor)
131 + actor_fetch_uid: {&m.source, uint64} -> lib.stat(m.actor)
132 + actor_notif_fetch_uid: {&m.source, uint64} -> lib.mem.ptr(m.notif)
133 + actor_auth: {&m.source, rawstring, rawstring} -> lib.stat(m.actor)
134 + actor_enum: {&m.source} -> lib.mem.ptr(m.actor)
135 + actor_enum_local: {&m.source} -> lib.mem.ptr(m.actor)
136 +
137 + actor_conf_str: cnf(rawstring, lib.mem.ptr(int8))
138 + actor_conf_int: cnf(intptr, lib.stat(intptr))
139 +
140 + post_save: {&m.source, &m.post} -> bool
141 + post_create: {&m.source, &m.post} -> bool
142 + actor_post_fetch_uid: {&m.source, uint64, m.range} -> lib.mem.ptr(m.post)
143 + convo_fetch_xid: {&m.source,rawstring} -> lib.mem.ptr(m.post)
144 + convo_fetch_uid: {&m.source,uint64} -> lib.mem.ptr(m.post)
145 +
146 + actor_timeline_fetch_uid: {&m.source, uint64, m.range} -> lib.mem.ptr(m.post)
147 + instance_timeline_fetch: {&m.source, m.range} -> lib.mem.ptr(m.post)
148 +}
13 149
14 - localuser: bool
150 +struct m.source {
151 + backend: &m.backend
152 + id: lib.mem.ptr(int8)
153 + handle: &opaque
154 + string: lib.mem.ptr(int8)
15 155 }
156 +terra m.source:free()
157 + self.id:free()
158 + self.string:free()
159 +end
160 +m.source.metamethods.__methodmissing = macro(function(meth, obj, ...)
161 + local q = {...}
162 + -- syntax sugar to forward unrecognized calls onto the backend
163 + return `obj.backend.[meth](&obj, [q])
164 +end)
165 +
166 +return m