diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ab3da2..f8c2bbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Released] +## [2.5.2] - 2023-07-25 + +### Fixed + - Fixed time spent calculation for notification feature. Timers currently running was not considered in the total time spent that was used to see if notification should be sent. + ## [2.5.1] - 2023-07-18 ### Changed diff --git a/package.json b/package.json index 1468dbe..90910d7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "activity_timer", - "version": "2.5.1", + "version": "2.5.2", "author": "Dannie Hansen", "license": "MIT", "scripts": { diff --git a/src/capabilities/board-buttons/index.ts b/src/capabilities/board-buttons/index.ts index afc3eef..ebb6e8c 100644 --- a/src/capabilities/board-buttons/index.ts +++ b/src/capabilities/board-buttons/index.ts @@ -107,7 +107,7 @@ export async function getBoardButtons(): Promise< } items.push({ - text: 'Version: 2.5.1' + text: 'Version: 2.5.2' }); await t.popup({ diff --git a/src/components/card.ts b/src/components/card.ts index 357aebd..8c2cd85 100644 --- a/src/components/card.ts +++ b/src/components/card.ts @@ -92,9 +92,19 @@ export class Card { ); } - async getTimeSpent(): Promise { + async getTimeSpent(memberId?: string): Promise { const timers = await this.getTimers(); const ranges = await this.getRanges(); + + if (memberId) { + const memberTimer = timers.getByMemberId(memberId); + const memberRanges = ranges.filter((range) => { + return range.memberId === memberId; + }); + + return memberRanges.timeSpent + (memberTimer?.timeInSecond ?? 0); + } + return timers.timeSpent + ranges.timeSpent; } diff --git a/src/utils/notifications.ts b/src/utils/notifications.ts index 9e75d03..72b0e29 100644 --- a/src/utils/notifications.ts +++ b/src/utils/notifications.ts @@ -73,11 +73,7 @@ export async function canTriggerNotification(t: Trello.PowerUp.IFrame) { const memberId = await getMemberId(); const card = await Card.getFromContext(t); - const ranges = await card.getRanges(); - - const timeSpent = ranges.items - .filter((item) => item.memberId === memberId) - .reduce((a, b) => a + b.diff, 0); + const timeSpent = await card.getTimeSpent(memberId); if (timeSpent === 0) { return false;