ente/lib/models/sessions.dart

143 lines
2.8 KiB
Dart
Raw Normal View History

// @dart=2.9
2021-11-23 19:40:22 +00:00
import 'dart:convert';
import 'package:flutter/foundation.dart';
class Sessions {
final List<Session> sessions;
Sessions(
this.sessions,
);
Sessions copyWith({
List<Session> sessions,
}) {
return Sessions(
sessions ?? this.sessions,
);
}
Map<String, dynamic> toMap() {
return {
'sessions': sessions?.map((x) => x.toMap())?.toList(),
};
}
factory Sessions.fromMap(Map<String, dynamic> map) {
return Sessions(
List<Session>.from(map['sessions']?.map((x) => Session.fromMap(x))),
);
}
String toJson() => json.encode(toMap());
factory Sessions.fromJson(String source) =>
Sessions.fromMap(json.decode(source));
@override
String toString() => 'Sessions(sessions: $sessions)';
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is Sessions && listEquals(other.sessions, sessions);
}
@override
int get hashCode => sessions.hashCode;
}
class Session {
final String token;
final int creationTime;
final String ip;
2021-11-24 05:40:07 +00:00
final String ua;
final String prettyUA;
2021-11-23 19:40:22 +00:00
final int lastUsedTime;
2021-11-24 05:40:07 +00:00
Session(
this.token,
this.creationTime,
this.ip,
this.ua,
this.prettyUA,
this.lastUsedTime,
);
2021-11-23 19:40:22 +00:00
Session copyWith({
String token,
int creationTime,
String ip,
2021-11-24 05:40:07 +00:00
String ua,
String prettyUA,
2021-11-23 19:40:22 +00:00
int lastUsedTime,
}) {
return Session(
token ?? this.token,
creationTime ?? this.creationTime,
ip ?? this.ip,
2021-11-24 05:40:07 +00:00
ua ?? this.ua,
prettyUA ?? this.prettyUA,
2021-11-23 19:40:22 +00:00
lastUsedTime ?? this.lastUsedTime,
);
}
Map<String, dynamic> toMap() {
return {
'token': token,
'creationTime': creationTime,
'ip': ip,
2021-11-24 05:40:07 +00:00
'ua': ua,
'prettyUA': prettyUA,
2021-11-23 19:40:22 +00:00
'lastUsedTime': lastUsedTime,
};
}
factory Session.fromMap(Map<String, dynamic> map) {
return Session(
map['token'],
map['creationTime'],
map['ip'],
2021-11-24 05:40:07 +00:00
map['ua'],
map['prettyUA'],
2021-11-23 19:40:22 +00:00
map['lastUsedTime'],
);
}
String toJson() => json.encode(toMap());
factory Session.fromJson(String source) =>
Session.fromMap(json.decode(source));
@override
String toString() {
2021-11-24 05:40:07 +00:00
return 'Session(token: $token, creationTime: $creationTime, ip: $ip, ua: $ua, prettyUA: $prettyUA, lastUsedTime: $lastUsedTime)';
2021-11-23 19:40:22 +00:00
}
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is Session &&
other.token == token &&
other.creationTime == creationTime &&
other.ip == ip &&
2021-11-24 05:40:07 +00:00
other.ua == ua &&
other.prettyUA == prettyUA &&
2021-11-23 19:40:22 +00:00
other.lastUsedTime == lastUsedTime;
}
@override
int get hashCode {
return token.hashCode ^
creationTime.hashCode ^
ip.hashCode ^
2021-11-24 05:40:07 +00:00
ua.hashCode ^
prettyUA.hashCode ^
2021-11-23 19:40:22 +00:00
lastUsedTime.hashCode;
}
}