-
Notifications
You must be signed in to change notification settings - Fork 4
/
types.go
347 lines (312 loc) · 9.83 KB
/
types.go
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
package thingscloud
//go:generate stringer -type ItemAction,TaskStatus,TaskSchedule
import (
"encoding/json"
"time"
)
// ItemAction describes possible actions on Items
type ItemAction int
const (
// ItemActionCreated is used to indicate a new Item was created
ItemActionCreated ItemAction = iota
// ItemActionModified is used to indicate an existing Item was modified
ItemActionModified ItemAction = 1
// ItemActionDeleted is used as a tombstone for an Item
ItemActionDeleted ItemAction = 2
)
// TaskSchedule describes when a task is scheduled
type TaskSchedule int
const (
// TaskScheduleToday indicates tasks which should be completed today
TaskScheduleToday TaskSchedule = 0
// TaskScheduleAnytime indicates tasks which can be completed anyday
TaskScheduleAnytime TaskSchedule = 1
// TaskScheduleSomeday indicates tasks which might never be completed
TaskScheduleSomeday TaskSchedule = 2
)
// TaskStatus describes if a thing is completed or not
type TaskStatus int
const (
// TaskStatusPending indicates a new task
TaskStatusPending TaskStatus = iota
// TaskStatusCompleted indicates a completed task
TaskStatusCompleted TaskStatus = 3
// TaskStatusCanceled indicates a canceled task
TaskStatusCanceled TaskStatus = 2
)
// ItemKind describes the different types things cloud supports
type ItemKind string
var (
// ItemKindChecklistItem identifies a CheckList
ItemKindChecklistItem ItemKind = "ChecklistItem"
// ItemKindTask identifies a Task or Subtask
ItemKindTask ItemKind = "Task6"
// ItemKindArea identifies an Area
ItemKindArea ItemKind = "Area2"
// ItemKindSettings identifies a setting
ItemKindSettings ItemKind = "Settings3"
// ItemKindTag identifies a Tag
ItemKindTag ItemKind = "Tag3"
)
// Timestamp allows unix epochs represented as float or ints to be unmarshalled
// into time.Time objects
type Timestamp time.Time
// UnmarshalJSON takes a unix epoch from float/ int and creates a time.Time instance
func (t *Timestamp) UnmarshalJSON(bs []byte) error {
var d float64
if err := json.Unmarshal(bs, &d); err != nil {
return err
}
*t = Timestamp(time.Unix(int64(d), 0).UTC())
return nil
}
// MarshalJSON convers a timestamp into unix nano representation
func (t *Timestamp) MarshalJSON() ([]byte, error) {
var tt = time.Time(*t).Unix()
return json.Marshal(tt)
}
// Format returns a textual representation of the time value formatted according to layout
func (t *Timestamp) Format(layout string) string {
return time.Time(*t).Format(layout)
}
// Time returns the underlying time.Time instance
func (t *Timestamp) Time() *time.Time {
tt := time.Time(*t)
return &tt
}
// Boolean allows integers to be parsed into booleans, where 1 means true and 0 means false
type Boolean bool
// UnmarshalJSON takes an int and creates a boolean instance
func (b *Boolean) UnmarshalJSON(bs []byte) error {
var d int
if err := json.Unmarshal(bs, &d); err != nil {
return err
}
*b = Boolean(d == 1)
return nil
}
// MarshalJSON takes a boolean and serializes it as an integer
func (b *Boolean) MarshalJSON() ([]byte, error) {
var d = 0
if *b {
d = 1
}
return json.Marshal(d)
}
// Task describes a Task inside things.
// 0|uuid|TEXT|0||1
// 1|userModificationDate|REAL|0||0
// 2|creationDate|REAL|0||0
// 3|trashed|INTEGER|0||0
// 4|type|INTEGER|0||0
// 5|title|TEXT|0||0
// 6|notes|TEXT|0||0
// 7|dueDate|REAL|0||0
// 8|dueDateOffset|INTEGER|0||0
// 9|status|INTEGER|0||0
// 10|stopDate|REAL|0||0
// 11|start|INTEGER|0||0
// 12|startDate|REAL|0||0
// 13|index|INTEGER|0||0
// 14|todayIndex|INTEGER|0||0
// 15|area|TEXT|0||0
// 16|project|TEXT|0||0
// 17|repeatingTemplate|TEXT|0||0
// 18|delegate|TEXT|0||0
// 19|recurrenceRule|BLOB|0||0
// 20|instanceCreationStartDate|REAL|0||0
// 21|instanceCreationPaused|INTEGER|0||0
// 22|instanceCreationCount|INTEGER|0||0
// 23|afterCompletionReferenceDate|REAL|0||0
// 24|actionGroup|TEXT|0||0
// 25|untrashedLeafActionsCount|INTEGER|0||0
// 26|openUntrashedLeafActionsCount|INTEGER|0||0
// 27|checklistItemsCount|INTEGER|0||0
// 28|openChecklistItemsCount|INTEGER|0||0
// 29|startBucket|INTEGER|0||0
// 30|alarmTimeOffset|REAL|0||0
// 31|lastAlarmInteractionDate|REAL|0||0
// 32|todayIndexReferenceDate|REAL|0||0
// 33|nextInstanceStartDate|REAL|0||0
// 34|dueDateSuppressionDate|REAL|0||0
type Task struct {
UUID string
CreationDate time.Time
ModificationDate *time.Time
Status TaskStatus
Title string
Note string
ScheduledDate *time.Time
CompletionDate *time.Time
DeadlineDate *time.Time
Index int
AreaIDs []string
ParentTaskIDs []string
ActionGroupIDs []string
InTrash bool
Schedule TaskSchedule
IsProject bool
}
// TaskActionItemPayload describes the payload for modifying Tasks, and also Projects,
// as projects are special kind of Tasks
type TaskActionItemPayload struct {
Index *int `json:"ix,omitempty"`
CreationDate *Timestamp `json:"cd,omitempty"`
ModificationDate *Timestamp `json:"md,omitempty"` // ok
ScheduledDate *Timestamp `json:"sr,omitempty"`
CompletionDate *Timestamp `json:"sp,omitempty"`
DeadlineDate *Timestamp `json:"dd,omitempty"` //
TaskIR *Timestamp `json:"tir,omitempty"` // hm, not sure what tir stands for
Status *TaskStatus `json:"ss,omitempty"`
IsProject *Boolean `json:"tp,omitempty"`
Title *string `json:"tt,omitempty"`
Note *string `json:"nt,omitempty"`
AreaIDs *[]string `json:"ar,omitempty"`
ParentTaskIDs *[]string `json:"pr,omitempty"`
TagIDs []string `json:"tg,omitempty"`
InTrash *bool `json:"tr,omitempty"`
TaskIndex *int `json:"ti,omitempty"`
RecurrenceTaskIDs *[]string `json:"rt,omitempty"`
Schedule *TaskSchedule `json:"st,omitempty"`
ActionGroupIDs *[]string `json:"agr,omitempty"`
Repeater *RepeaterConfiguration `json:"rr,omitempty"`
// {
// "acrd": null,
// "ar": [],
// "ato": null,
// "cd": 1495662927.014228,
// "dd": null,
// "dds": null,
// "dl": [],
// "do": 0,
// "icc": 0,
// "icp": false,
// "icsd": null, instance creation start date
// "ix": 0,
// "lai": null,
// "md": 1495662933.606909,
// "nt": "<note xml:space=\"preserve\">test body pm</note>",
// "pr": [],
// "rr": null,
// "rt": [],
// "sb": 0,
// "sp": null,
// "sr": 1495584000,
// "ss": 0,
// "st": 1,
// "tg": [],
// "ti": 0,
// "tir": 1495584000,
// "tp": 0,
// "tr": false,
// "tt": "test"
// },
}
// TaskActionItem describes an event on a Task
type TaskActionItem struct {
Item
P TaskActionItemPayload `json:"p"`
}
// UUID returns the UUID of the modified Task
func (t TaskActionItem) UUID() string {
return t.Item.UUID
}
// Tag describes the aggregated state of an Tag
// 0|uuid|TEXT|0||1
// 1|title|TEXT|0||0
// 2|shortcut|TEXT|0||0
// 3|usedDate|REAL|0||0
// 4|parent|TEXT|0||0
// 5|index|INTEGER|0||0
type Tag struct {
UUID string
Title string
ParentTagIDs []string
ShortHand string
}
// TagActionItemPayload describes the payload for modifying Areas
type TagActionItemPayload struct {
IX *int `json:"ix"`
Title *string `json:"tt"`
ShortHand *string `json:"sh"`
ParentTagIDs *[]string `json:"pn"`
}
// TagActionItem describes an event on a tag
type TagActionItem struct {
Item
P TagActionItemPayload `json:"p"`
}
// UUID returns the UUID of the modified Tag
func (t TagActionItem) UUID() string {
return t.Item.UUID
}
// Setting describes things settings
// 0|uuid|TEXT|0||1
// 1|logInterval|INTEGER|0||0
// 2|manualLogDate|REAL|0||0
// 3|groupTodayByParent|INTEGER|0||0
type Setting struct{}
// Area describes an Area inside things. An Area is a container for tasks
// 0|uuid|TEXT|0||1
// 1|title|TEXT|0||0
// 2|visible|INTEGER|0||0
// 3|index|INTEGER|0||0
type Area struct {
UUID string
Title string
Tags []*Tag
Tasks []*Task
}
// AreaActionItemPayload describes the payload for modifying Areas
type AreaActionItemPayload struct {
IX *int `json:"ix,omitempty"`
Title *string `json:"tt,omitempty"`
TagIDs []string `json:"tg,omitempty"`
}
// AreaActionItem describes an event on an Area
type AreaActionItem struct {
Item
P AreaActionItemPayload `json:"p"`
}
// UUID returns the UUID of the modified Area
func (item AreaActionItem) UUID() string {
return item.Item.UUID
}
// CheckListItem describes a check list item
//0|uuid|TEXT|0||1
//1|userModificationDate|REAL|0||0
//2|creationDate|REAL|0||0
//3|title|TEXT|0||0
//4|status|INTEGER|0||0
//5|stopDate|REAL|0||0
//6|index|INTEGER|0||0
//7|task|TEXT|0||0
type CheckListItem struct {
UUID string
CreationDate time.Time
ModificationDate *time.Time
Status TaskStatus
Title string
Index int
CompletionDate *time.Time
TaskIDs []string
}
// CheckListActionItemPayload describes the payload for modifying CheckListItems
type CheckListActionItemPayload struct {
CreationDate *Timestamp `json:"cd,omitempty"`
ModificationDate *Timestamp `json:"md,omitempty"`
Index *int `json:"ix"`
Status *TaskStatus `json:"ss,omitempty"`
Title *string `json:"tt,omitempty"`
CompletionDate *Timestamp `json:"sp,omitempty"`
TaskIDs *[]string `json:"ts,omitempty"`
}
// CheckListActionItem describes an event on a check list item
type CheckListActionItem struct {
Item
P CheckListActionItemPayload `json:"p"`
}
// UUID returns the UUID of the modified CheckListItem
func (item CheckListActionItem) UUID() string {
return item.Item.UUID
}