Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions commet/lib/client/client_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:commet/client/matrix/matrix_client.dart';
import 'package:commet/client/stale_info.dart';
import 'package:commet/client/tasks/client_connection_status_task.dart';
import 'package:commet/main.dart';
import 'package:commet/client/sidebar/sidebar_manager.dart';
import 'package:commet/utils/notifying_list.dart';

class ClientManager {
Expand All @@ -22,10 +23,12 @@ class ClientManager {
late CallManager callManager;

late final DirectMessagesAggregator directMessages;
late final SidebarManager sidebarManager;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think this needs to exist in ClientManager, maybe in the state of SideNavigationBar makes more sense?


ClientManager() {
directMessages = DirectMessagesAggregator(this);
callManager = CallManager(this);
sidebarManager = SidebarManager(this);
}

List<Room> get rooms => _rooms;
Expand Down Expand Up @@ -99,6 +102,8 @@ class ClientManager {
isBackgroundService: isBackgroundService),
]);

newClientManager.sidebarManager.init();

return newClientManager;
}

Expand Down Expand Up @@ -229,6 +234,7 @@ class ClientManager {
}

Future<void> close() async {
sidebarManager.dispose();
for (var client in _clients.values) {
client.close();
}
Expand Down
24 changes: 24 additions & 0 deletions commet/lib/client/sidebar/resolved_sidebar_item.dart
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move these into new SidebarLayoutComponent

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:commet/client/client.dart';

sealed class ResolvedSidebarItem {
const ResolvedSidebarItem();
}

class ResolvedSpace extends ResolvedSidebarItem {
final Space space;
const ResolvedSpace(this.space);
}

class ResolvedFolder extends ResolvedSidebarItem {
final String id;
final String name;
final List<Space> spaces;
final bool isExpanded;

const ResolvedFolder({
required this.id,
required this.name,
required this.spaces,
this.isExpanded = false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UI state probably shouldn't be stored here, at the moment for subspaces we store expanded state just in the widget itself, which I think is preferable

});
}
61 changes: 61 additions & 0 deletions commet/lib/client/sidebar/sidebar_data.dart
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be implemented as a Client Component, with an abstract SidebarLayoutComponent which doesn't implement any matrix-specific functionality, just the bare layout api, and MatrixSidebarLayoutComponent which implements the specifics of how its stored

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:commet/client/sidebar/sidebar_model.dart';

class SidebarData {
static const String accountDataType = 'im.commet.space_sidebar';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use chat.commet.sidebar_layout instead

static const int currentVersion = 1;

final int version;
final List<SidebarItem> items;

const SidebarData({this.version = currentVersion, this.items = const []});

factory SidebarData.fromJson(Map<String, dynamic> json) {
final version = json['version'] as int? ?? currentVersion;
final rawItems = json['items'] as List<dynamic>? ?? [];

final items = <SidebarItem>[];
for (final raw in rawItems) {
if (raw is! Map<String, dynamic>) continue;

final type = raw['type'] as String?;
switch (type) {
case 'space':
final id = raw['id'] as String?;
if (id != null) items.add(SidebarSpace(id));
break;
case 'folder':
final id = raw['id'] as String?;
final name = raw['name'] as String? ?? '';
final children = (raw['children'] as List<dynamic>?)
?.whereType<String>()
.toList() ??
[];
if (id != null && children.isNotEmpty) {
items.add(SidebarFolder(id: id, name: name, children: children));
}
break;
}
}

return SidebarData(version: version, items: items);
}

Map<String, dynamic> toJson() {
return {
'version': version,
'items': items.map((item) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a list, store in a Map, and sort by order string

return switch (item) {
SidebarSpace s => {'type': 'space', 'id': s.spaceId},
SidebarFolder f => {
'type': 'folder',
'id': f.id,
'name': f.name,
'children': f.children,
},
};
}).toList(),
};
}

static SidebarData empty() => const SidebarData();
}
Loading