From 0334927da089111536e4338efbf0f36d34021e8c Mon Sep 17 00:00:00 2001 From: bobemoe Date: Fri, 28 Feb 2020 10:36:50 +0000 Subject: [PATCH 1/3] stop current stopwatch when another is started --- models/issue_stopwatch.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/models/issue_stopwatch.go b/models/issue_stopwatch.go index ca92141157526..ce81bb84c98a0 100644 --- a/models/issue_stopwatch.go +++ b/models/issue_stopwatch.go @@ -101,6 +101,15 @@ func CreateOrStopIssueStopwatch(user *User, issue *Issue) error { return err } } else { + //if another stopwatch is running: stop it + exists, sw, err := HasUserStopwatch(user.ID) + if exists && err==nil { + issue, err := getIssueByID(x, sw.IssueID) + if err == nil { + CreateOrStopIssueStopwatch(user, issue) + } + } + // Create stopwatch sw = &Stopwatch{ UserID: user.ID, From 308d613427e0e1fe623eccb0f29d1e297cc7876e Mon Sep 17 00:00:00 2001 From: bobemoe Date: Fri, 28 Feb 2020 17:00:24 +0000 Subject: [PATCH 2/3] fix err returning --- models/issue_stopwatch.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/models/issue_stopwatch.go b/models/issue_stopwatch.go index ce81bb84c98a0..85697a9c26ba8 100644 --- a/models/issue_stopwatch.go +++ b/models/issue_stopwatch.go @@ -103,10 +103,16 @@ func CreateOrStopIssueStopwatch(user *User, issue *Issue) error { } else { //if another stopwatch is running: stop it exists, sw, err := HasUserStopwatch(user.ID) - if exists && err==nil { - issue, err := getIssueByID(x, sw.IssueID) - if err == nil { - CreateOrStopIssueStopwatch(user, issue) + 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 } } From 1779036bce858eb249773f3681b1a2ce4e798f2e Mon Sep 17 00:00:00 2001 From: bobemoe Date: Sun, 5 Jul 2020 11:21:44 +0100 Subject: [PATCH 3/3] fix formatting --- models/issue_stopwatch.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/issue_stopwatch.go b/models/issue_stopwatch.go index 85697a9c26ba8..79ce48c4cd1d2 100644 --- a/models/issue_stopwatch.go +++ b/models/issue_stopwatch.go @@ -108,11 +108,11 @@ func CreateOrStopIssueStopwatch(user *User, issue *Issue) error { } if exists { issue, err := getIssueByID(x, sw.IssueID) - if err != nil { + if err != nil { return err } - if err := CreateOrStopIssueStopwatch(user, issue) ; err != nil { - return err + if err := CreateOrStopIssueStopwatch(user, issue); err != nil { + return err } }