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