-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
71 lines (61 loc) · 1.2 KB
/
user.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
package nonota
type User struct {
CurrentWorks []*Work
}
func (u *User) StopWork(work *Work) error {
workIdx := -1
for i, w := range u.CurrentWorks {
if w == work {
workIdx = i
break
}
}
if workIdx != -1 {
u.CurrentWorks = append(u.CurrentWorks[:workIdx], u.CurrentWorks[workIdx+1:]...)
}
return work.StopWork()
}
func (u *User) ExcludeWork(work *Work) {
workIdx := -1
for i, w := range u.CurrentWorks {
if w == work {
workIdx = i
break
}
}
if workIdx != -1 {
u.CurrentWorks = append(u.CurrentWorks[:workIdx], u.CurrentWorks[workIdx+1:]...)
}
}
// ToggleWorkOnTask either resumes (or starts) working on the given task or
// pauses it (if already working).
func (u *User) ToggleWorkOnTask(task *Task) *Work {
var work *Work
for _, w := range u.CurrentWorks {
if w.Task == task {
if w.paused {
w.ResumeWork()
} else {
w.PauseWork()
}
work = w
} else {
w.PauseWork()
}
}
if work == nil {
work = StartWork(task)
u.CurrentWorks = append(u.CurrentWorks, work)
} else if work.paused {
return nil
}
return work
}
func (u *User) WorkForTask(task *Task) *Work {
for _, w := range u.CurrentWorks {
if w.Task == task {
return w
}
}
return nil
}