mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-03 19:54:12 +00:00 
			
		
		
		
	Can send comments
This commit is contained in:
		@@ -1,10 +1,30 @@
 | 
			
		||||
import 'package:comunic/models/api_request.dart';
 | 
			
		||||
import 'package:comunic/models/comment.dart';
 | 
			
		||||
import 'package:comunic/models/new_comment.dart';
 | 
			
		||||
 | 
			
		||||
/// Comments helper
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre HUBERT
 | 
			
		||||
 | 
			
		||||
class CommentsHelper {
 | 
			
		||||
  /// Send a new comment
 | 
			
		||||
  ///
 | 
			
		||||
  /// Returns 0 or below in case of failure, the ID of the comment else
 | 
			
		||||
  Future<int> createComment(NewComment comment) async {
 | 
			
		||||
    final request = APIRequest(uri: "comments/create", needLogin: true, args: {
 | 
			
		||||
      "postID": comment.postID.toString(),
 | 
			
		||||
      "content": comment.hasContent ? comment.content : "",
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    if (comment.hasImage) request.addFile("image", comment.image);
 | 
			
		||||
 | 
			
		||||
    final response = await request.execWithFiles();
 | 
			
		||||
 | 
			
		||||
    if (response.code != 200) return -1;
 | 
			
		||||
 | 
			
		||||
    return response.getObject()["commentID"];
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Turn an API entry into a [Comment] object
 | 
			
		||||
  static Comment apiToComment(Map<String, dynamic> entry) {
 | 
			
		||||
    return Comment(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user