mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Can create posts
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import 'package:comunic/enums/post_kind.dart';
|
||||
import 'package:comunic/enums/post_target.dart';
|
||||
import 'package:comunic/enums/post_visibility_level.dart';
|
||||
import 'package:comunic/enums/user_access_levels.dart';
|
||||
import 'package:comunic/helpers/comments_helper.dart';
|
||||
@ -6,6 +7,7 @@ import 'package:comunic/helpers/survey_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/new_post.dart';
|
||||
import 'package:comunic/models/post.dart';
|
||||
|
||||
/// Posts helper
|
||||
@ -37,6 +39,11 @@ const _APIUserAccessMap = {
|
||||
"full": UserAccessLevels.FULL
|
||||
};
|
||||
|
||||
const _APIPostsTargetKindsMap = {
|
||||
PostTarget.USER_PAGE: "user",
|
||||
PostTarget.GROUP_PAGE: "group"
|
||||
};
|
||||
|
||||
class PostsHelper {
|
||||
/// Get the list of latest posts. Return the list of posts or null in case of
|
||||
/// failure
|
||||
@ -77,6 +84,38 @@ class PostsHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new post
|
||||
///
|
||||
/// This function crash in case of error
|
||||
Future<void> createPost(NewPost post) async {
|
||||
APIRequest request =
|
||||
APIRequest(uri: "posts/create", needLogin: true, args: {
|
||||
"kind-page": _APIPostsTargetKindsMap[post.target],
|
||||
"kind-id": post.targetID.toString(),
|
||||
"visibility": _APIPostsVisibilityLevelMap.map(
|
||||
(s, v) => MapEntry(v, s))[post.visibility],
|
||||
"kind": _APIPostsKindsMap.map((s, k) => MapEntry(k, s))[post.kind],
|
||||
"content": post.content
|
||||
});
|
||||
|
||||
switch (post.kind) {
|
||||
case PostKind.TEXT:
|
||||
break;
|
||||
|
||||
case PostKind.IMAGE:
|
||||
request.addFile("image", post.image);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw Exception("Unsupported post type :" + post.kind.toString());
|
||||
break;
|
||||
}
|
||||
|
||||
final response = await request.execWithFiles();
|
||||
|
||||
if (!response.isOK) throw Exception("Could not create the post !");
|
||||
}
|
||||
|
||||
/// Update a post content
|
||||
Future<bool> updateContent(int id, String newContent) async {
|
||||
return (await APIRequest(
|
||||
|
@ -155,6 +155,7 @@ class UsersHelper {
|
||||
data["virtualDirectory"] == "" ? null : data["virtualDirectory"],
|
||||
accountImageURL: data["accountImage"],
|
||||
publicNote: data["publicNote"],
|
||||
canPostTexts: data["can_post_texts"],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user