Skip to content

Commit bac57ab

Browse files
bobemoezeripathlafriks
authored
When starting new stopwatch stop previous if it is still running (#10533)
Co-authored-by: zeripath <[email protected]> Co-authored-by: Lauris BH <[email protected]>
1 parent 8188176 commit bac57ab

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

models/issue_stopwatch.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,21 @@ func CreateOrStopIssueStopwatch(user *User, issue *Issue) error {
101101
return err
102102
}
103103
} else {
104+
//if another stopwatch is running: stop it
105+
exists, sw, err := HasUserStopwatch(user.ID)
106+
if err != nil {
107+
return err
108+
}
109+
if exists {
110+
issue, err := getIssueByID(x, sw.IssueID)
111+
if err != nil {
112+
return err
113+
}
114+
if err := CreateOrStopIssueStopwatch(user, issue); err != nil {
115+
return err
116+
}
117+
}
118+
104119
// Create stopwatch
105120
sw = &Stopwatch{
106121
UserID: user.ID,

0 commit comments

Comments
 (0)