mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-03 19:54:12 +00:00 
			
		
		
		
	Display the list of comments
This commit is contained in:
		
							
								
								
									
										21
									
								
								lib/helpers/comments_helper.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								lib/helpers/comments_helper.dart
									
									
									
									
									
										Normal 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"],
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -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,
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user