refactor: Make via fields not nullable
This commit is contained in:
parent
96fd74497b
commit
849bd7ca9b
|
|
@ -516,8 +516,8 @@ class FamedlySdkHiveDatabase extends DatabaseApi with ZoneTransactionMixin {
|
||||||
Future<List<OlmSession>> getOlmSessions(
|
Future<List<OlmSession>> getOlmSessions(
|
||||||
String identityKey, String userId) async {
|
String identityKey, String userId) async {
|
||||||
final rawSessions =
|
final rawSessions =
|
||||||
await _olmSessionsBox.get(identityKey.toHiveKey) as Map?;
|
await _olmSessionsBox.get(identityKey.toHiveKey) as Map? ?? {};
|
||||||
if (rawSessions == null || rawSessions.isEmpty) return <OlmSession>[];
|
|
||||||
return rawSessions.values
|
return rawSessions.values
|
||||||
.map((json) => OlmSession.fromJson(convertToJson(json), userId))
|
.map((json) => OlmSession.fromJson(convertToJson(json), userId))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
|
||||||
|
|
@ -2233,7 +2233,7 @@ class Room {
|
||||||
states[EventTypes.spaceParent]
|
states[EventTypes.spaceParent]
|
||||||
?.values
|
?.values
|
||||||
.map((state) => SpaceParent.fromState(state))
|
.map((state) => SpaceParent.fromState(state))
|
||||||
.where((child) => child.via?.isNotEmpty ?? false)
|
.where((child) => child.via.isNotEmpty)
|
||||||
.toList() ??
|
.toList() ??
|
||||||
[];
|
[];
|
||||||
|
|
||||||
|
|
@ -2246,7 +2246,7 @@ class Room {
|
||||||
: (states[EventTypes.spaceChild]
|
: (states[EventTypes.spaceChild]
|
||||||
?.values
|
?.values
|
||||||
.map((state) => SpaceChild.fromState(state))
|
.map((state) => SpaceChild.fromState(state))
|
||||||
.where((child) => child.via?.isNotEmpty ?? false)
|
.where((child) => child.via.isNotEmpty)
|
||||||
.toList() ??
|
.toList() ??
|
||||||
[])
|
[])
|
||||||
..sort((a, b) => a.order.isEmpty || b.order.isEmpty
|
..sort((a, b) => a.order.isEmpty || b.order.isEmpty
|
||||||
|
|
|
||||||
|
|
@ -21,26 +21,26 @@ import 'package:matrix/src/event.dart';
|
||||||
|
|
||||||
class SpaceChild {
|
class SpaceChild {
|
||||||
final String? roomId;
|
final String? roomId;
|
||||||
final List<String>? via;
|
final List<String> via;
|
||||||
final String order;
|
final String order;
|
||||||
final bool? suggested;
|
final bool? suggested;
|
||||||
|
|
||||||
SpaceChild.fromState(Event state)
|
SpaceChild.fromState(Event state)
|
||||||
: assert(state.type == EventTypes.spaceChild),
|
: assert(state.type == EventTypes.spaceChild),
|
||||||
roomId = state.stateKey,
|
roomId = state.stateKey,
|
||||||
via = state.content.tryGetList<String>('via'),
|
via = state.content.tryGetList<String>('via') ?? [],
|
||||||
order = state.content.tryGet<String>('order') ?? '',
|
order = state.content.tryGet<String>('order') ?? '',
|
||||||
suggested = state.content.tryGet<bool>('suggested');
|
suggested = state.content.tryGet<bool>('suggested');
|
||||||
}
|
}
|
||||||
|
|
||||||
class SpaceParent {
|
class SpaceParent {
|
||||||
final String? roomId;
|
final String? roomId;
|
||||||
final List<String>? via;
|
final List<String> via;
|
||||||
final bool? canonical;
|
final bool? canonical;
|
||||||
|
|
||||||
SpaceParent.fromState(Event state)
|
SpaceParent.fromState(Event state)
|
||||||
: assert(state.type == EventTypes.spaceParent),
|
: assert(state.type == EventTypes.spaceParent),
|
||||||
roomId = state.stateKey,
|
roomId = state.stateKey,
|
||||||
via = state.content.tryGetList<String>('via'),
|
via = state.content.tryGetList<String>('via') ?? [],
|
||||||
canonical = state.content.tryGet<bool>('canonical');
|
canonical = state.content.tryGet<bool>('canonical');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue