mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 12:14:11 +00:00 
			
		
		
		
	Can update post content
This commit is contained in:
		@@ -56,6 +56,19 @@ class PostsHelper {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Update a post content
 | 
			
		||||
  Future<bool> updateContent(int id, String newContent) async {
 | 
			
		||||
    return (await APIRequest(
 | 
			
		||||
      uri: "posts/update_content",
 | 
			
		||||
      needLogin: true,
 | 
			
		||||
      args: {
 | 
			
		||||
        "postID": id.toString(),
 | 
			
		||||
        "new_content": newContent,
 | 
			
		||||
      },
 | 
			
		||||
    ).exec())
 | 
			
		||||
        .isOK;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Delete a post
 | 
			
		||||
  Future<bool> delete(int id) async {
 | 
			
		||||
    return (await APIRequest(
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,7 @@ class Post implements LikeElement {
 | 
			
		||||
  final int userPageID;
 | 
			
		||||
  final int groupID;
 | 
			
		||||
  final int timeSent;
 | 
			
		||||
  final String content;
 | 
			
		||||
  String content;
 | 
			
		||||
  final PostVisibilityLevel visibilityLevel;
 | 
			
		||||
  final PostKind kind;
 | 
			
		||||
  final int fileSize;
 | 
			
		||||
@@ -70,6 +70,8 @@ class Post implements LikeElement {
 | 
			
		||||
 | 
			
		||||
  bool get hasComments => comments != null;
 | 
			
		||||
 | 
			
		||||
  bool get canUpdate => access == UserAccessLevels.FULL;
 | 
			
		||||
 | 
			
		||||
  bool get canDelete =>
 | 
			
		||||
      access == UserAccessLevels.FULL ||
 | 
			
		||||
      access == UserAccessLevels.INTERMEDIATE;
 | 
			
		||||
 
 | 
			
		||||
@@ -31,7 +31,7 @@ const TextStyle _userNameStyle = TextStyle(
 | 
			
		||||
    fontSize: 16.0);
 | 
			
		||||
 | 
			
		||||
/// Post actions
 | 
			
		||||
enum _PostActions { DELETE }
 | 
			
		||||
enum _PostActions { DELETE, UPDATE_CONTENT }
 | 
			
		||||
 | 
			
		||||
class PostTile extends StatefulWidget {
 | 
			
		||||
  final Post post;
 | 
			
		||||
@@ -99,6 +99,13 @@ class _PostTileState extends State<PostTile> {
 | 
			
		||||
 | 
			
		||||
        PopupMenuButton<_PostActions>(
 | 
			
		||||
          itemBuilder: (c) => [
 | 
			
		||||
                // Update post content
 | 
			
		||||
                PopupMenuItem(
 | 
			
		||||
                  child: Text(tr("Update content")),
 | 
			
		||||
                  value: _PostActions.UPDATE_CONTENT,
 | 
			
		||||
                  enabled: widget.post.canUpdate,
 | 
			
		||||
                ),
 | 
			
		||||
 | 
			
		||||
                // Delete post
 | 
			
		||||
                PopupMenuItem(
 | 
			
		||||
                  child: Text(tr("Delete")),
 | 
			
		||||
@@ -422,12 +429,38 @@ class _PostTileState extends State<PostTile> {
 | 
			
		||||
  /// Method called each time the user has selected an option
 | 
			
		||||
  void _selectedPostMenuAction(_PostActions value) {
 | 
			
		||||
    switch (value) {
 | 
			
		||||
      // Update post content
 | 
			
		||||
      case _PostActions.UPDATE_CONTENT:
 | 
			
		||||
        updateContent();
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
      // Delete post
 | 
			
		||||
      case _PostActions.DELETE:
 | 
			
		||||
        confirmDelete();
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Update post content
 | 
			
		||||
  Future<void> updateContent() async {
 | 
			
		||||
    final newContent = await askUserString(
 | 
			
		||||
      context: context,
 | 
			
		||||
      title: tr("Update post content"),
 | 
			
		||||
      message: tr("Please enter message content: "),
 | 
			
		||||
      defaultValue: widget.post.content,
 | 
			
		||||
      hint: tr("Post content"),
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    if (newContent == null) return;
 | 
			
		||||
 | 
			
		||||
    if (!await _postsHelper.updateContent(widget.post.id, newContent)) {
 | 
			
		||||
      showSimpleSnack(context, tr("Could not update post content!"));
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    setState(() => widget.post.content = newContent);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Perform the deletion of the post
 | 
			
		||||
  Future<void> confirmDelete() async {
 | 
			
		||||
    // Ask user confirmation
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user