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

Can send comments

This commit is contained in:
2019-05-18 14:58:35 +02:00
parent c267940ce6
commit 1f899f7594
3 changed files with 82 additions and 8 deletions

View File

@ -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(