@@ -103,6 +103,8 @@ class MatrixSdkDatabase extends DatabaseApi with DatabaseFileStorage {
103103
104104 late Box <String > _seenDeviceKeysBox;
105105
106+ late Box <Map > _spacesHierarchyBox;
107+
106108 @override
107109 final int maxFileSize;
108110
@@ -159,6 +161,8 @@ class MatrixSdkDatabase extends DatabaseApi with DatabaseFileStorage {
159161
160162 static const String _seenDeviceKeysBoxName = 'box_seen_device_keys' ;
161163
164+ static const String _spacesHierarchyBoxName = 'box_spaces_hierarchy' ;
165+
162166 Database ? database;
163167
164168 /// Custom IdbFactory used to create the indexedDB. On IO platforms it would
@@ -214,6 +218,7 @@ class MatrixSdkDatabase extends DatabaseApi with DatabaseFileStorage {
214218 _eventsBoxName,
215219 _seenDeviceIdsBoxName,
216220 _seenDeviceKeysBoxName,
221+ _spacesHierarchyBoxName,
217222 },
218223 sqfliteDatabase: database,
219224 sqfliteFactory: sqfliteFactory,
@@ -283,6 +288,9 @@ class MatrixSdkDatabase extends DatabaseApi with DatabaseFileStorage {
283288 _seenDeviceKeysBox = _collection.openBox (
284289 _seenDeviceKeysBoxName,
285290 );
291+ _spacesHierarchyBox = _collection.openBox (
292+ _spacesHierarchyBoxName,
293+ );
286294
287295 // Check version and check if we need a migration
288296 final currentVersion = int .tryParse (await _clientBox.get ('version' ) ?? '' );
@@ -341,6 +349,7 @@ class MatrixSdkDatabase extends DatabaseApi with DatabaseFileStorage {
341349 await _outboundGroupSessionsBox.clear ();
342350 await _presencesBox.clear ();
343351 await _clientBox.delete ('prev_batch' );
352+ await _spacesHierarchyBox.clear ();
344353 });
345354
346355 @override
@@ -389,6 +398,11 @@ class MatrixSdkDatabase extends DatabaseApi with DatabaseFileStorage {
389398 if (multiKey.parts.first != roomId) continue ;
390399 await _roomAccountDataBox.delete (key);
391400 }
401+ final spaceHierarchyKeys = await _spacesHierarchyBox.getAllKeys ();
402+ for (final key in spaceHierarchyKeys) {
403+ if (key != roomId) continue ;
404+ await _spacesHierarchyBox.delete (key);
405+ }
392406 await _roomsBox.delete (roomId);
393407 }
394408
@@ -1477,6 +1491,7 @@ class MatrixSdkDatabase extends DatabaseApi with DatabaseFileStorage {
14771491 _eventsBoxName: await _eventsBox.getAllValues (),
14781492 _seenDeviceIdsBoxName: await _seenDeviceIdsBox.getAllValues (),
14791493 _seenDeviceKeysBoxName: await _seenDeviceKeysBox.getAllValues (),
1494+ _spacesHierarchyBoxName: await _spacesHierarchyBox.getAllValues (),
14801495 };
14811496 final json = jsonEncode (dataMap);
14821497 await clear ();
@@ -1557,6 +1572,9 @@ class MatrixSdkDatabase extends DatabaseApi with DatabaseFileStorage {
15571572 for (final key in json[_seenDeviceKeysBoxName]! .keys) {
15581573 await _seenDeviceKeysBox.put (key, json[_seenDeviceKeysBoxName]! [key]);
15591574 }
1575+ for (final key in json[_spacesHierarchyBoxName]! .keys) {
1576+ await _spacesHierarchyBox.put (key, json[_spacesHierarchyBoxName]! [key]);
1577+ }
15601578 return true ;
15611579 } catch (e, s) {
15621580 Logs ().e ('Database import error: ' , e, s);
@@ -1613,6 +1631,22 @@ class MatrixSdkDatabase extends DatabaseApi with DatabaseFileStorage {
16131631 return CachedPresence .fromJson (copyMap (rawPresence));
16141632 }
16151633
1634+ @override
1635+ Future <GetSpaceHierarchyResponse ?> getSpaceHierarchy (String spaceId) async {
1636+ final raw_space_hierarchy = await _spacesHierarchyBox.get (spaceId);
1637+ if (raw_space_hierarchy == null ) return null ;
1638+ return GetSpaceHierarchyResponse .fromJson (copyMap (raw_space_hierarchy));
1639+ }
1640+
1641+ @override
1642+ Future <void > storeSpaceHierarchy (
1643+ String spaceId, GetSpaceHierarchyResponse hierarchy) =>
1644+ _spacesHierarchyBox.put (spaceId, hierarchy.toJson ());
1645+
1646+ @override
1647+ Future <void > removeSpaceHierarchy (String spaceId) =>
1648+ _spacesHierarchyBox.delete (spaceId);
1649+
16161650 @override
16171651 Future <void > delete () => BoxCollection .delete (
16181652 name,
0 commit comments