1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-10-23 06:53:23 +00:00

Fix issue: when creating a comment on a list of posts where user never appeared before

This commit is contained in:
Pierre HUBERT 2020-04-16 08:34:39 +02:00
parent f0a23bcb47
commit cf5b1180a9
2 changed files with 31 additions and 18 deletions

View File

@ -31,6 +31,9 @@ class UsersList extends ListBase<User> {
throw "User not found in the list!";
}
/// Check if the user is included in this list or not
bool hasUser(int userID) => any((f) => f.id == userID);
/// Get the list of users ID present in this list
List<int> get usersID => List.generate(length, (i) => this[i].id);
}

View File

@ -4,6 +4,7 @@ import 'package:comunic/enums/post_kind.dart';
import 'package:comunic/enums/post_visibility_level.dart';
import 'package:comunic/helpers/comments_helper.dart';
import 'package:comunic/helpers/posts_helper.dart';
import 'package:comunic/helpers/users_helper.dart';
import 'package:comunic/lists/groups_list.dart';
import 'package:comunic/lists/users_list.dart';
import 'package:comunic/models/comment.dart';
@ -472,6 +473,7 @@ class _PostTileState extends State<PostTile> {
/// Submit comment entered by the user
Future<void> _submitComment() async {
try {
_sendingComment = true;
final commentID = await _commentsHelper.createComment(NewComment(
@ -482,8 +484,7 @@ class _PostTileState extends State<PostTile> {
_sendingComment = false;
if (commentID < 1)
return showSimpleSnack(context, tr("Could not create comment!"));
if (commentID < 1) throw new Exception("Comment ID is inferior to 1!");
clearCommentForm();
@ -494,9 +495,18 @@ class _PostTileState extends State<PostTile> {
return showSimpleSnack(
context, tr("Could not retrieve created comment!"));
// Get information about the user who created the comment (if required)
if (!widget.usersInfo.hasUser(newComment.userID))
widget.usersInfo
.add(await UsersHelper().getSingleWithThrow(newComment.userID));
setState(() {
widget.post.comments.add(newComment);
});
} catch (e) {
print(e);
showSimpleSnack(context, tr("Could not create comment!"));
}
}
/// Update comment content