⚡ Optimize chat list and attachment loading
This commit is contained in:
		@@ -59,6 +59,7 @@
 | 
				
			|||||||
      ignoresPersistentStateOnLaunch = "NO"
 | 
					      ignoresPersistentStateOnLaunch = "NO"
 | 
				
			||||||
      debugDocumentVersioning = "YES"
 | 
					      debugDocumentVersioning = "YES"
 | 
				
			||||||
      debugServiceExtension = "internal"
 | 
					      debugServiceExtension = "internal"
 | 
				
			||||||
 | 
					      showGraphicsOverview = "Yes"
 | 
				
			||||||
      allowLocationSimulation = "YES">
 | 
					      allowLocationSimulation = "YES">
 | 
				
			||||||
      <BuildableProductRunnable
 | 
					      <BuildableProductRunnable
 | 
				
			||||||
         runnableDebuggingMode = "0">
 | 
					         runnableDebuggingMode = "0">
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,6 +23,21 @@ class AttachmentProvider extends GetConnect {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  final Map<String, Attachment> _cachedResponses = {};
 | 
					  final Map<String, Attachment> _cachedResponses = {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  List<Attachment?> listMetadataFromCache(List<String> rid) {
 | 
				
			||||||
 | 
					    if (rid.isEmpty) return List.empty();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    List<Attachment?> result = List.filled(rid.length, null);
 | 
				
			||||||
 | 
					    for (var idx = 0; idx < rid.length; idx++) {
 | 
				
			||||||
 | 
					      if (_cachedResponses.containsKey(rid[idx])) {
 | 
				
			||||||
 | 
					        result[idx] = _cachedResponses[rid[idx]];
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
 | 
					        result[idx] = null;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return result;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Future<List<Attachment?>> listMetadata(
 | 
					  Future<List<Attachment?>> listMetadata(
 | 
				
			||||||
    List<String> rid, {
 | 
					    List<String> rid, {
 | 
				
			||||||
    noCache = false,
 | 
					    noCache = false,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -529,7 +529,7 @@ class _DashboardScreenState extends State<DashboardScreen> {
 | 
				
			|||||||
                style: TextStyle(color: _unFocusColor, fontSize: 12),
 | 
					                style: TextStyle(color: _unFocusColor, fontSize: 12),
 | 
				
			||||||
              )
 | 
					              )
 | 
				
			||||||
            ],
 | 
					            ],
 | 
				
			||||||
          ).paddingAll(8),
 | 
					          ).paddingOnly(left: 8, right: 8, top: 8, bottom: 50),
 | 
				
			||||||
        ],
 | 
					        ],
 | 
				
			||||||
      ),
 | 
					      ),
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -134,7 +134,17 @@ class _AttachmentListState extends State<AttachmentList> {
 | 
				
			|||||||
    super.initState();
 | 
					    super.initState();
 | 
				
			||||||
    assert(widget.attachmentIds != null || widget.attachments != null);
 | 
					    assert(widget.attachmentIds != null || widget.attachments != null);
 | 
				
			||||||
    if (widget.attachments == null) {
 | 
					    if (widget.attachments == null) {
 | 
				
			||||||
 | 
					      final AttachmentProvider attach = Get.find();
 | 
				
			||||||
 | 
					      final cachedResult = attach.listMetadataFromCache(widget.attachmentIds!);
 | 
				
			||||||
 | 
					      if (cachedResult.every((x) => x != null)) {
 | 
				
			||||||
 | 
					        setState(() {
 | 
				
			||||||
 | 
					          _attachments = cachedResult;
 | 
				
			||||||
 | 
					          _isLoading = false;
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					        _calculateAspectRatio();
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
        _getMetadataList();
 | 
					        _getMetadataList();
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      setState(() {
 | 
					      setState(() {
 | 
				
			||||||
        _attachments = widget.attachments!;
 | 
					        _attachments = widget.attachments!;
 | 
				
			||||||
@@ -176,7 +186,10 @@ class _AttachmentListState extends State<AttachmentList> {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if (widget.isFullWidth && _attachments.length == 1) {
 | 
					    if (widget.isFullWidth && _attachments.length == 1) {
 | 
				
			||||||
      final element = _attachments.first;
 | 
					      final element = _attachments.first;
 | 
				
			||||||
      double ratio = element!.metadata?['ratio']?.toDouble() ?? 16 / 9;
 | 
					      double ratio = math.max(
 | 
				
			||||||
 | 
					        element!.metadata?['ratio']?.toDouble() ?? 16 / 9,
 | 
				
			||||||
 | 
					        0.5,
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
      return Container(
 | 
					      return Container(
 | 
				
			||||||
        width: MediaQuery.of(context).size.width,
 | 
					        width: MediaQuery.of(context).size.width,
 | 
				
			||||||
        constraints: BoxConstraints(
 | 
					        constraints: BoxConstraints(
 | 
				
			||||||
@@ -243,7 +256,10 @@ class _AttachmentListState extends State<AttachmentList> {
 | 
				
			|||||||
          final element = _attachments[idx];
 | 
					          final element = _attachments[idx];
 | 
				
			||||||
          idx++;
 | 
					          idx++;
 | 
				
			||||||
          if (element == null) return const SizedBox.shrink();
 | 
					          if (element == null) return const SizedBox.shrink();
 | 
				
			||||||
          double ratio = element.metadata?['ratio']?.toDouble() ?? 16 / 9;
 | 
					          double ratio = math.max(
 | 
				
			||||||
 | 
					            element.metadata?['ratio']?.toDouble() ?? 16 / 9,
 | 
				
			||||||
 | 
					            0.5,
 | 
				
			||||||
 | 
					          );
 | 
				
			||||||
          return Container(
 | 
					          return Container(
 | 
				
			||||||
            constraints: BoxConstraints(
 | 
					            constraints: BoxConstraints(
 | 
				
			||||||
              maxWidth: widget.columnMaxWidth,
 | 
					              maxWidth: widget.columnMaxWidth,
 | 
				
			||||||
@@ -282,7 +298,10 @@ class _AttachmentListState extends State<AttachmentList> {
 | 
				
			|||||||
        itemBuilder: (context, idx) {
 | 
					        itemBuilder: (context, idx) {
 | 
				
			||||||
          final element = _attachments[idx];
 | 
					          final element = _attachments[idx];
 | 
				
			||||||
          if (element == null) const SizedBox.shrink();
 | 
					          if (element == null) const SizedBox.shrink();
 | 
				
			||||||
          final ratio = element!.metadata?['ratio']?.toDouble() ?? 16 / 9;
 | 
					          double ratio = math.max(
 | 
				
			||||||
 | 
					            element!.metadata?['ratio']?.toDouble() ?? 16 / 9,
 | 
				
			||||||
 | 
					            0.5,
 | 
				
			||||||
 | 
					          );
 | 
				
			||||||
          return Container(
 | 
					          return Container(
 | 
				
			||||||
            constraints: BoxConstraints(
 | 
					            constraints: BoxConstraints(
 | 
				
			||||||
              maxWidth: math.min(
 | 
					              maxWidth: math.min(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -37,6 +37,7 @@ class ChatEventList extends StatelessWidget {
 | 
				
			|||||||
  @override
 | 
					  @override
 | 
				
			||||||
  Widget build(BuildContext context) {
 | 
					  Widget build(BuildContext context) {
 | 
				
			||||||
    return CustomScrollView(
 | 
					    return CustomScrollView(
 | 
				
			||||||
 | 
					      cacheExtent: 100,
 | 
				
			||||||
      reverse: true,
 | 
					      reverse: true,
 | 
				
			||||||
      slivers: [
 | 
					      slivers: [
 | 
				
			||||||
        Obx(() {
 | 
					        Obx(() {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user