Skip to content

Commit

Permalink
Fixed notification feature time spent calculation not taking running …
Browse files Browse the repository at this point in the history
…timers into account
  • Loading branch information
danniehansen committed Jul 25, 2023
1 parent dce1a24 commit f7ac908
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "activity_timer",
"version": "2.5.1",
"version": "2.5.2",
"author": "Dannie Hansen",
"license": "MIT",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/capabilities/board-buttons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export async function getBoardButtons(): Promise<
}

items.push({
text: 'Version: 2.5.1'
text: 'Version: 2.5.2'
});

await t.popup({
Expand Down
12 changes: 11 additions & 1 deletion src/components/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,19 @@ export class Card {
);
}

async getTimeSpent(): Promise<number> {
async getTimeSpent(memberId?: string): Promise<number> {
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;
}

Expand Down
6 changes: 1 addition & 5 deletions src/utils/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f7ac908

Please sign in to comment.