From bac57ab5900672357fb0a36f9433e516088bd21b Mon Sep 17 00:00:00 2001 From: bobemoe Date: Sun, 12 Jul 2020 11:01:20 +0100 Subject: [PATCH] When starting new stopwatch stop previous if it is still running (#10533) Co-authored-by: zeripath Co-authored-by: Lauris BH --- models/issue_stopwatch.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/models/issue_stopwatch.go b/models/issue_stopwatch.go index ca9214115..79ce48c4c 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,