🐛 Fix chat summary failed when lastMessage is null
This commit is contained in:
		@@ -104,7 +104,7 @@ sealed class SnChatMember with _$SnChatMember {
 | 
			
		||||
sealed class SnChatSummary with _$SnChatSummary {
 | 
			
		||||
  const factory SnChatSummary({
 | 
			
		||||
    required int unreadCount,
 | 
			
		||||
    required SnChatMessage lastMessage,
 | 
			
		||||
    required SnChatMessage? lastMessage,
 | 
			
		||||
  }) = _SnChatSummary;
 | 
			
		||||
 | 
			
		||||
  factory SnChatSummary.fromJson(Map<String, dynamic> json) =>
 | 
			
		||||
 
 | 
			
		||||
@@ -213,15 +213,18 @@ Map<String, dynamic> _$SnChatMemberToJson(_SnChatMember instance) =>
 | 
			
		||||
_SnChatSummary _$SnChatSummaryFromJson(Map<String, dynamic> json) =>
 | 
			
		||||
    _SnChatSummary(
 | 
			
		||||
      unreadCount: (json['unread_count'] as num).toInt(),
 | 
			
		||||
      lastMessage: SnChatMessage.fromJson(
 | 
			
		||||
        json['last_message'] as Map<String, dynamic>,
 | 
			
		||||
      ),
 | 
			
		||||
      lastMessage:
 | 
			
		||||
          json['last_message'] == null
 | 
			
		||||
              ? null
 | 
			
		||||
              : SnChatMessage.fromJson(
 | 
			
		||||
                json['last_message'] as Map<String, dynamic>,
 | 
			
		||||
              ),
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
Map<String, dynamic> _$SnChatSummaryToJson(_SnChatSummary instance) =>
 | 
			
		||||
    <String, dynamic>{
 | 
			
		||||
      'unread_count': instance.unreadCount,
 | 
			
		||||
      'last_message': instance.lastMessage.toJson(),
 | 
			
		||||
      'last_message': instance.lastMessage?.toJson(),
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
_MessageChange _$MessageChangeFromJson(Map<String, dynamic> json) =>
 | 
			
		||||
 
 | 
			
		||||
@@ -79,33 +79,38 @@ class ChatRoomListTile extends HookConsumerWidget {
 | 
			
		||||
                    color: Theme.of(context).colorScheme.primary,
 | 
			
		||||
                  ),
 | 
			
		||||
                ),
 | 
			
		||||
              Row(
 | 
			
		||||
                spacing: 4,
 | 
			
		||||
                children: [
 | 
			
		||||
                  Badge(
 | 
			
		||||
                    label: Text(data.lastMessage.sender.account.nick),
 | 
			
		||||
                    textColor: Theme.of(context).colorScheme.onPrimary,
 | 
			
		||||
                    backgroundColor: Theme.of(context).colorScheme.primary,
 | 
			
		||||
                  ),
 | 
			
		||||
                  Expanded(
 | 
			
		||||
                    child: Text(
 | 
			
		||||
                      (data.lastMessage.content?.isNotEmpty ?? false)
 | 
			
		||||
                          ? data.lastMessage.content!
 | 
			
		||||
                          : 'messageNone'.tr(),
 | 
			
		||||
                      maxLines: 1,
 | 
			
		||||
                      overflow: TextOverflow.ellipsis,
 | 
			
		||||
                      style: Theme.of(context).textTheme.bodySmall,
 | 
			
		||||
              if (data.lastMessage == null)
 | 
			
		||||
                Text(room.description ?? 'descriptionNone'.tr(), maxLines: 1)
 | 
			
		||||
              else
 | 
			
		||||
                Row(
 | 
			
		||||
                  spacing: 4,
 | 
			
		||||
                  children: [
 | 
			
		||||
                    Badge(
 | 
			
		||||
                      label: Text(data.lastMessage!.sender.account.nick),
 | 
			
		||||
                      textColor: Theme.of(context).colorScheme.onPrimary,
 | 
			
		||||
                      backgroundColor: Theme.of(context).colorScheme.primary,
 | 
			
		||||
                    ),
 | 
			
		||||
                  ),
 | 
			
		||||
                  Align(
 | 
			
		||||
                    alignment: Alignment.centerRight,
 | 
			
		||||
                    child: Text(
 | 
			
		||||
                      RelativeTime(context).format(data.lastMessage.createdAt),
 | 
			
		||||
                      style: Theme.of(context).textTheme.bodySmall,
 | 
			
		||||
                    Expanded(
 | 
			
		||||
                      child: Text(
 | 
			
		||||
                        (data.lastMessage!.content?.isNotEmpty ?? false)
 | 
			
		||||
                            ? data.lastMessage!.content!
 | 
			
		||||
                            : 'messageNone'.tr(),
 | 
			
		||||
                        maxLines: 1,
 | 
			
		||||
                        overflow: TextOverflow.ellipsis,
 | 
			
		||||
                        style: Theme.of(context).textTheme.bodySmall,
 | 
			
		||||
                      ),
 | 
			
		||||
                    ),
 | 
			
		||||
                  ),
 | 
			
		||||
                ],
 | 
			
		||||
              ),
 | 
			
		||||
                    Align(
 | 
			
		||||
                      alignment: Alignment.centerRight,
 | 
			
		||||
                      child: Text(
 | 
			
		||||
                        RelativeTime(
 | 
			
		||||
                          context,
 | 
			
		||||
                        ).format(data.lastMessage!.createdAt),
 | 
			
		||||
                        style: Theme.of(context).textTheme.bodySmall,
 | 
			
		||||
                      ),
 | 
			
		||||
                    ),
 | 
			
		||||
                  ],
 | 
			
		||||
                ),
 | 
			
		||||
            ],
 | 
			
		||||
          );
 | 
			
		||||
        },
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user