forked from Nexus/nexus
parent
2041b81141
commit
4b329b4c6f
1 changed files with 1115 additions and 119 deletions
|
|
@ -2,9 +2,7 @@ import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
|||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:nexus/controllers/image_pack_sources.dart";
|
||||
import "package:nexus/controllers/rooms.dart";
|
||||
import "package:nexus/models/content/content.dart";
|
||||
import "package:nexus/models/content/image_pack.dart";
|
||||
import "package:nexus/models/event.dart";
|
||||
import "package:nexus/helpers/extensions/room_image_packs.dart";
|
||||
import "package:nexus/models/image_pack.dart";
|
||||
|
||||
class ImagePacksController(final String roomId)
|
||||
|
|
@ -18,40 +16,13 @@ class ImagePacksController(final String roomId)
|
|||
final packs = ref.watch(
|
||||
RoomsController.provider.select(
|
||||
(rooms) => sources.expand((source) {
|
||||
final room = rooms[source.roomId];
|
||||
if (room == null) return const <ImagePack>[];
|
||||
|
||||
final newPacks = room.state[EventType.imagePack.type];
|
||||
final legacyPacks = room.state[EventType.legacyImagePack.type];
|
||||
final roomName = room.metadata?.name ?? source.roomId;
|
||||
final packs =
|
||||
rooms[source.roomId]?.imagePacks(source.roomId) ?? const .empty();
|
||||
|
||||
return switch (source.stateKey) {
|
||||
final stateKey? => ISet([stateKey]),
|
||||
null => ISet(
|
||||
newPacks?.keys ?? const <String>[],
|
||||
).addAll(legacyPacks?.keys ?? const []),
|
||||
}
|
||||
.map(
|
||||
(stateKey) =>
|
||||
switch (newPacks?[stateKey] ?? legacyPacks?[stateKey]) {
|
||||
final rowId? => switch (room.events[rowId]) {
|
||||
Event(
|
||||
redactedBy: null,
|
||||
content: final ImagePackContent content,
|
||||
) =>
|
||||
ImagePack.fromContent(
|
||||
content,
|
||||
id: "${source.roomId}/$stateKey",
|
||||
fallbackName: stateKey.isEmpty
|
||||
? roomName
|
||||
: "$roomName - $stateKey",
|
||||
),
|
||||
_ => null,
|
||||
},
|
||||
null => null,
|
||||
},
|
||||
)
|
||||
.nonNulls;
|
||||
final stateKey? => [?packs[stateKey]],
|
||||
null => packs.values,
|
||||
};
|
||||
}).toIList(),
|
||||
),
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue