summaryrefslogtreecommitdiffstats
path: root/models/issue_stopwatch.go
diff options
context:
space:
mode:
authorbobemoe <inbox.github@jhodges.co.uk>2020-07-12 11:01:20 +0100
committerGitHub <noreply@github.com>2020-07-12 13:01:20 +0300
commitbac57ab5900672357fb0a36f9433e516088bd21b (patch)
tree2d9030e792e11d784229db305a51d2cb959d7b76 /models/issue_stopwatch.go
parent8188176b588264fe0ff8e3f82a623ea007a1af41 (diff)
downloadgitea-bac57ab5900672357fb0a36f9433e516088bd21b.tar.gz
gitea-bac57ab5900672357fb0a36f9433e516088bd21b.zip
When starting new stopwatch stop previous if it is still running (#10533)
Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'models/issue_stopwatch.go')
-rw-r--r--models/issue_stopwatch.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/models/issue_stopwatch.go b/models/issue_stopwatch.go
index ca92141157..79ce48c4cd 100644
--- a/models/issue_stopwatch.go
+++ b/models/issue_stopwatch.go
@@ -101,6 +101,21 @@ func CreateOrStopIssueStopwatch(user *User, issue *Issue) error {
return err
}
} else {
+ //if another stopwatch is running: stop it
+ exists, sw, err := HasUserStopwatch(user.ID)
+ if err != nil {
+ return err
+ }
+ if exists {
+ issue, err := getIssueByID(x, sw.IssueID)
+ if err != nil {
+ return err
+ }
+ if err := CreateOrStopIssueStopwatch(user, issue); err != nil {
+ return err
+ }
+ }
+
// Create stopwatch
sw = &Stopwatch{
UserID: user.ID,