Skip to content

Commit ac22517

Browse files
authored
Active column now uses timestamp from latest message (#56)
1 parent 93e1889 commit ac22517

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/app/applications/iot-devices/iot-devices-table/iot-devices-table.component.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Component, Input, ViewChild, AfterViewInit, OnInit } from '@angular/core';
1+
import {
2+
Component,
3+
Input,
4+
ViewChild,
5+
AfterViewInit,
6+
OnInit,
7+
} from '@angular/core';
28
import { merge, Observable, of as observableOf } from 'rxjs';
39
import { TranslateService } from '@ngx-translate/core';
410
import { RestService } from 'src/app/shared/services/rest.service';
@@ -59,7 +65,7 @@ export class IotDevicesTableComponent implements AfterViewInit, OnInit {
5965
}
6066

6167
ngOnInit() {
62-
this.canEdit = this.meService.canWriteInTargetOrganization()
68+
this.canEdit = this.meService.canWriteInTargetOrganization();
6369
}
6470

6571
ngAfterViewInit() {
@@ -114,15 +120,9 @@ export class IotDevicesTableComponent implements AfterViewInit, OnInit {
114120
}
115121

116122
public lastActive(device: IotDevice) {
117-
const arr = device?.receivedMessagesMetadata;
118-
if (!arr || arr.length === 0) {
119-
return this.translate.instant('ACTIVITY.NEVER');
120-
} else {
121-
const lastActive = Math.max(
122-
...arr.map((x: ReceivedMessageMetadata) => Date.parse(x.sentTime))
123-
);
124-
return moment(lastActive).fromNow();
125-
}
123+
return device.latestReceivedMessage
124+
? moment(device.latestReceivedMessage.sentTime).fromNow()
125+
: this.translate.instant('ACTIVITY.NEVER');
126126
}
127127

128128
clickDelete(element: any) {

0 commit comments

Comments
 (0)