Skip to content

Commit

Permalink
GS-9945 handle empty post in chats (#2234)
Browse files Browse the repository at this point in the history
  • Loading branch information
nkhoudor authored and github-actions[bot] committed Aug 3, 2023
1 parent 6a9e4c0 commit 7416515
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lib/features/chat/data/model/gql_chat_component_post_json.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
import 'package:picnic_app/core/data/graphql/model/gql_post.dart';
import 'package:picnic_app/core/data/utils/safe_convert.dart';
import 'package:picnic_app/core/domain/stores/user_store.dart';
import 'package:picnic_app/core/helpers.dart';
import 'package:picnic_app/dependency_injection/app_component.dart';
import 'package:picnic_app/features/chat/domain/model/chat_message_post_payload.dart';
import 'package:picnic_app/features/chat/domain/model/id.dart';
import 'package:picnic_app/features/posts/domain/model/posts/post.dart';

class GqlChatComponentPostJson {
const GqlChatComponentPostJson({
required this.postId,
required this.post,
});

factory GqlChatComponentPostJson.fromJson(Map<String, dynamic>? json) => GqlChatComponentPostJson(
postId: asT<String>(json, 'postId'),
post: GqlPost.fromJson(json!['post'] as Map<String, dynamic>),
);
factory GqlChatComponentPostJson.fromJson(Map<String, dynamic>? json) {
GqlPost? _post;
try {
_post = GqlPost.fromJson(json!['post'] as Map<String, dynamic>);
} catch (e) {
doNothing();
}
return GqlChatComponentPostJson(
postId: asT<String>(json, 'postId'),
post: _post,
);
}

final String postId;
final GqlPost post;
final GqlPost? post;

/// This is a workaround to get the userStore from the global injector.
/// It seems impossible to pass userStore here through all other Gql classes. Too much dependencies.
Expand All @@ -26,6 +36,6 @@ class GqlChatComponentPostJson {

ChatMessagePostPayload toDomain() => ChatMessagePostPayload(
postId: Id(postId),
post: post.toDomain(userStore),
post: post?.toDomain(userStore) ?? const Post.empty(),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:picnic_app/features/posts/domain/model/post_contents/video_post_
import 'package:picnic_app/features/posts/domain/model/post_type.dart';
import 'package:picnic_app/features/posts/domain/model/posts/post.dart';
import 'package:picnic_app/features/posts/link_post/widgets/link_placeholder.dart';
import 'package:picnic_app/localization/app_localizations_utils.dart';
import 'package:picnic_app/resources/assets.gen.dart';
import 'package:picnic_app/ui/widgets/picnic_image.dart';
import 'package:picnic_app/ui/widgets/picnic_image_source.dart';
Expand Down Expand Up @@ -55,6 +56,24 @@ class ChatMessageContentPost extends StatelessWidget {

Widget postContentWidget = const SizedBox();

if (post == const Post.empty()) {
return Container(
decoration: BoxDecoration(
borderRadius: _containerBorderRadius,
border: Border.all(
color: borderColor,
),
),
child: Padding(
padding: _contentPadding,
child: Text(
appLocalizations.postNotAvailable,
style: contentTextStyle,
),
),
);
}

switch (post.type) {
case PostType.text:
postContentWidget = Text(
Expand Down
1 change: 1 addition & 0 deletions lib/localization/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,7 @@
"shareThisWithYourFriends": "share this with your friends!",
"sendToFriends": "send to friends",
"inviteCircle": "invite to circle",
"postNotAvailable": "Sorry, this post is no longer available",
"sharePost": "share post",
"sharePostMessageHint": "write a message",
"inviteFriend": "invite friend",
Expand Down

0 comments on commit 7416515

Please sign in to comment.