1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2025-06-19 08:15:16 +00:00

Display the list of comments

This commit is contained in:
2019-05-16 14:52:22 +02:00
parent be53a73d9f
commit 28de22f427
8 changed files with 198 additions and 10 deletions

View File

@ -0,0 +1,21 @@
import 'package:comunic/models/comment.dart';
/// Comments helper
///
/// @author Pierre HUBERT
class CommentsHelper {
/// Turn an API entry into a [Comment] object
static Comment apiToComment(Map<String, dynamic> entry) {
return Comment(
id: entry["ID"],
userID: entry["userID"],
postID: entry["postID"],
timeSent: entry["time_sent"],
content: entry["content"],
imageURL: entry["img_url"],
likes: entry["likes"],
userLike: entry["userlike"],
);
}
}

View File

@ -1,6 +1,8 @@
import 'package:comunic/enums/post_kind.dart';
import 'package:comunic/enums/post_visibility_level.dart';
import 'package:comunic/enums/user_access_levels.dart';
import 'package:comunic/helpers/comments_helper.dart';
import 'package:comunic/lists/comments_list.dart';
import 'package:comunic/lists/posts_list.dart';
import 'package:comunic/models/api_request.dart';
import 'package:comunic/models/post.dart';
@ -56,6 +58,14 @@ class PostsHelper {
/// Turn an API entry into a [Post] object
Post _apiToPost(Map<String, dynamic> map) {
// Parse comments
CommentsList comments;
if (map["comments"] != null) {
comments = CommentsList();
map["comments"]
.forEach((v) => comments.add(CommentsHelper.apiToComment(v)));
}
return Post(
id: map["ID"],
userID: map["userID"],
@ -77,6 +87,7 @@ class PostsHelper {
likes: map["likes"],
userLikes: map["userlike"],
access: _APIUserAccessMap[map["user_access"]],
comments: comments,
);
}
}