2020-02-19 13:26:38 +00:00
|
|
|
import '../client.dart';
|
|
|
|
|
|
|
|
/// Registered device for this user.
|
|
|
|
class UserDevice {
|
|
|
|
/// Identifier of this device.
|
|
|
|
final String deviceId;
|
|
|
|
|
|
|
|
/// Display name set by the user for this device. Absent if no name has been set.
|
|
|
|
final String displayName;
|
|
|
|
|
|
|
|
/// The IP address where this device was last seen. (May be a few minutes out of date, for efficiency reasons).
|
|
|
|
final String lastSeenIp;
|
|
|
|
|
|
|
|
/// The time when this devices was last seen. (May be a few minutes out of date, for efficiency reasons).
|
|
|
|
final DateTime lastSeenTs;
|
|
|
|
|
|
|
|
final Client _client;
|
|
|
|
|
|
|
|
/// Updates the metadata on the given device.
|
|
|
|
Future<void> updateMetaData(String newName) async {
|
|
|
|
await _client.jsonRequest(
|
|
|
|
type: HTTPType.PUT,
|
2020-03-30 09:08:38 +00:00
|
|
|
action: '/client/r0/devices/$deviceId',
|
|
|
|
data: {'display_name': newName},
|
2020-02-19 13:26:38 +00:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Deletes the given device, and invalidates any access token associated with it.
|
|
|
|
Future<void> deleteDevice(Map<String, dynamic> auth) async {
|
|
|
|
await _client.jsonRequest(
|
|
|
|
type: HTTPType.DELETE,
|
2020-03-30 09:08:38 +00:00
|
|
|
action: '/client/r0/devices/$deviceId',
|
|
|
|
data: auth != null ? {'auth': auth} : null,
|
2020-02-19 13:26:38 +00:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
UserDevice(
|
|
|
|
this._client, {
|
|
|
|
this.deviceId,
|
|
|
|
this.displayName,
|
|
|
|
this.lastSeenIp,
|
|
|
|
this.lastSeenTs,
|
|
|
|
});
|
|
|
|
|
|
|
|
UserDevice.fromJson(Map<String, dynamic> json, Client client)
|
|
|
|
: deviceId = json['device_id'],
|
|
|
|
displayName = json['display_name'],
|
|
|
|
lastSeenIp = json['last_seen_ip'],
|
|
|
|
lastSeenTs =
|
|
|
|
DateTime.fromMillisecondsSinceEpoch(json['last_seen_ts'] ?? 0),
|
|
|
|
_client = client;
|
|
|
|
}
|