Extend user and session models
This commit is contained in:
parent
5e267b7ff0
commit
b8b125f359
3 changed files with 58 additions and 7 deletions
|
@ -8,4 +8,6 @@ class Config {
|
||||||
static const String neosHubUrl = "$apiBaseUrl/hub";
|
static const String neosHubUrl = "$apiBaseUrl/hub";
|
||||||
|
|
||||||
static const int messageCacheValiditySeconds = 90;
|
static const int messageCacheValiditySeconds = 90;
|
||||||
|
|
||||||
|
static const String latestCompatHash = "jnnkdwkBqGv5+jlf1u/k7A==";
|
||||||
}
|
}
|
|
@ -118,22 +118,36 @@ enum OnlineStatus {
|
||||||
class UserStatus {
|
class UserStatus {
|
||||||
final OnlineStatus onlineStatus;
|
final OnlineStatus onlineStatus;
|
||||||
final DateTime lastStatusChange;
|
final DateTime lastStatusChange;
|
||||||
|
final int currentSessionAccessLevel;
|
||||||
|
final bool currentSessionHidden;
|
||||||
|
final bool currentHosting;
|
||||||
final Session currentSession;
|
final Session currentSession;
|
||||||
final List<Session> activeSessions;
|
final List<Session> activeSessions;
|
||||||
final String neosVersion;
|
final String neosVersion;
|
||||||
|
final String outputDevice;
|
||||||
|
final bool isMobile;
|
||||||
|
final String compatibilityHash;
|
||||||
|
|
||||||
const UserStatus(
|
const UserStatus(
|
||||||
{required this.onlineStatus, required this.lastStatusChange, required this.currentSession, required this.activeSessions,
|
{required this.onlineStatus, required this.lastStatusChange, required this.currentSession,
|
||||||
required this.neosVersion,
|
required this.currentSessionAccessLevel, required this.currentSessionHidden, required this.currentHosting,
|
||||||
|
required this.activeSessions, required this.neosVersion, required this.outputDevice, required this.isMobile,
|
||||||
|
required this.compatibilityHash,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory UserStatus.empty() =>
|
factory UserStatus.empty() =>
|
||||||
UserStatus(
|
UserStatus(
|
||||||
onlineStatus: OnlineStatus.offline,
|
onlineStatus: OnlineStatus.offline,
|
||||||
lastStatusChange: DateTime.now(),
|
lastStatusChange: DateTime.now(),
|
||||||
activeSessions: [],
|
currentSessionAccessLevel: 0,
|
||||||
|
currentSessionHidden: false,
|
||||||
|
currentHosting: false,
|
||||||
currentSession: Session.none(),
|
currentSession: Session.none(),
|
||||||
|
activeSessions: [],
|
||||||
neosVersion: "",
|
neosVersion: "",
|
||||||
|
outputDevice: "Unknown",
|
||||||
|
isMobile: false,
|
||||||
|
compatibilityHash: "",
|
||||||
);
|
);
|
||||||
|
|
||||||
factory UserStatus.fromMap(Map map) {
|
factory UserStatus.fromMap(Map map) {
|
||||||
|
@ -142,9 +156,15 @@ class UserStatus {
|
||||||
return UserStatus(
|
return UserStatus(
|
||||||
onlineStatus: status,
|
onlineStatus: status,
|
||||||
lastStatusChange: DateTime.parse(map["lastStatusChange"]),
|
lastStatusChange: DateTime.parse(map["lastStatusChange"]),
|
||||||
|
currentSessionAccessLevel: map["currentSessionAccessLevel"] ?? 0,
|
||||||
|
currentSessionHidden: map["currentSessionHidden"] ?? false,
|
||||||
|
currentHosting: map["currentHosting"] ?? false,
|
||||||
currentSession: Session.fromMap(map["currentSession"]),
|
currentSession: Session.fromMap(map["currentSession"]),
|
||||||
activeSessions: (map["activeSessions"] as List? ?? []).map((e) => Session.fromMap(e)).toList(),
|
activeSessions: (map["activeSessions"] as List? ?? []).map((e) => Session.fromMap(e)).toList(),
|
||||||
neosVersion: map["neosVersion"] ?? "",
|
neosVersion: map["neosVersion"] ?? "",
|
||||||
|
outputDevice: map["outputDevice"] ?? "Unknown",
|
||||||
|
isMobile: map["isMobile"] ?? false,
|
||||||
|
compatibilityHash: map["compatabilityHash"] ?? ""
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,24 +172,42 @@ class UserStatus {
|
||||||
return {
|
return {
|
||||||
"onlineStatus": onlineStatus.index,
|
"onlineStatus": onlineStatus.index,
|
||||||
"lastStatusChange": lastStatusChange.toIso8601String(),
|
"lastStatusChange": lastStatusChange.toIso8601String(),
|
||||||
|
"currentSessionAccessLevel": currentSessionAccessLevel,
|
||||||
|
"currentSessionHidden": currentSessionHidden,
|
||||||
|
"currentHosting": currentHosting,
|
||||||
"currentSession": currentSession.isNone || shallow ? null : currentSession.toMap(),
|
"currentSession": currentSession.isNone || shallow ? null : currentSession.toMap(),
|
||||||
"activeSessions": shallow ? [] : activeSessions.map((e) => e.toMap(),),
|
"activeSessions": shallow ? [] : activeSessions.map((e) => e.toMap(),).toList(),
|
||||||
"neosVersion": neosVersion,
|
"neosVersion": neosVersion,
|
||||||
|
"outputDevice": outputDevice,
|
||||||
|
"isMobile": isMobile,
|
||||||
|
"compatibilityHash": compatibilityHash,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
UserStatus copyWith({
|
UserStatus copyWith({
|
||||||
OnlineStatus? onlineStatus,
|
OnlineStatus? onlineStatus,
|
||||||
DateTime? lastStatusChange,
|
DateTime? lastStatusChange,
|
||||||
|
int? currentSessionAccessLevel,
|
||||||
|
bool? currentSessionHidden,
|
||||||
|
bool? currentHosting,
|
||||||
Session? currentSession,
|
Session? currentSession,
|
||||||
List<Session>? activeSessions,
|
List<Session>? activeSessions,
|
||||||
String? neosVersion
|
String? neosVersion,
|
||||||
|
String? outputDevice,
|
||||||
|
bool? isMobile,
|
||||||
|
String? compatibilityHash,
|
||||||
}) =>
|
}) =>
|
||||||
UserStatus(
|
UserStatus(
|
||||||
onlineStatus: onlineStatus ?? this.onlineStatus,
|
onlineStatus: onlineStatus ?? this.onlineStatus,
|
||||||
lastStatusChange: lastStatusChange ?? this.lastStatusChange,
|
lastStatusChange: lastStatusChange ?? this.lastStatusChange,
|
||||||
|
currentSessionAccessLevel: currentSessionAccessLevel ?? this.currentSessionAccessLevel,
|
||||||
|
currentSessionHidden: currentSessionHidden ?? this.currentSessionHidden,
|
||||||
|
currentHosting: currentHosting ?? this.currentHosting,
|
||||||
currentSession: currentSession ?? this.currentSession,
|
currentSession: currentSession ?? this.currentSession,
|
||||||
activeSessions: activeSessions ?? this.activeSessions,
|
activeSessions: activeSessions ?? this.activeSessions,
|
||||||
neosVersion: neosVersion ?? this.neosVersion,
|
neosVersion: neosVersion ?? this.neosVersion,
|
||||||
|
outputDevice: outputDevice ?? this.outputDevice,
|
||||||
|
isMobile: isMobile ?? this.isMobile,
|
||||||
|
compatibilityHash: compatibilityHash ?? this.compatibilityHash,
|
||||||
);
|
);
|
||||||
}
|
}
|
|
@ -66,13 +66,13 @@ class Session {
|
||||||
return {
|
return {
|
||||||
"sessionId": id,
|
"sessionId": id,
|
||||||
"name": name,
|
"name": name,
|
||||||
"sessionUsers": shallow ? [] : throw UnimplementedError(),
|
"sessionUsers": shallow ? [] : sessionUsers.map((e) => e.toMap()).toList(),
|
||||||
"thumbnail": thumbnail,
|
"thumbnail": thumbnail,
|
||||||
"maxUsers": maxUsers,
|
"maxUsers": maxUsers,
|
||||||
"hasEnded": hasEnded,
|
"hasEnded": hasEnded,
|
||||||
"isValid": isValid,
|
"isValid": isValid,
|
||||||
"description": description,
|
"description": description,
|
||||||
"tags": shallow ? [] : throw UnimplementedError(),
|
"tags": shallow ? [] : tags,
|
||||||
"headlessHost": headlessHost,
|
"headlessHost": headlessHost,
|
||||||
"hostUserId": hostUserId,
|
"hostUserId": hostUserId,
|
||||||
"hostUsername": hostUsername,
|
"hostUsername": hostUsername,
|
||||||
|
@ -80,6 +80,8 @@ class Session {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool get isLive => !hasEnded && isValid;
|
bool get isLive => !hasEnded && isValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,4 +127,13 @@ class SessionUser {
|
||||||
outputDevice: map["outputDevice"] ?? 0,
|
outputDevice: map["outputDevice"] ?? 0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map toMap() {
|
||||||
|
return {
|
||||||
|
"userID": id,
|
||||||
|
"username": username,
|
||||||
|
"isPresent": isPresent,
|
||||||
|
"outputDevice": outputDevice,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue