mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 21:09:21 +00:00
Can update post content
This commit is contained in:
parent
1fbe59c83c
commit
0bf85b478a
@ -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
|
/// Delete a post
|
||||||
Future<bool> delete(int id) async {
|
Future<bool> delete(int id) async {
|
||||||
return (await APIRequest(
|
return (await APIRequest(
|
||||||
|
@ -15,7 +15,7 @@ class Post implements LikeElement {
|
|||||||
final int userPageID;
|
final int userPageID;
|
||||||
final int groupID;
|
final int groupID;
|
||||||
final int timeSent;
|
final int timeSent;
|
||||||
final String content;
|
String content;
|
||||||
final PostVisibilityLevel visibilityLevel;
|
final PostVisibilityLevel visibilityLevel;
|
||||||
final PostKind kind;
|
final PostKind kind;
|
||||||
final int fileSize;
|
final int fileSize;
|
||||||
@ -70,6 +70,8 @@ class Post implements LikeElement {
|
|||||||
|
|
||||||
bool get hasComments => comments != null;
|
bool get hasComments => comments != null;
|
||||||
|
|
||||||
|
bool get canUpdate => access == UserAccessLevels.FULL;
|
||||||
|
|
||||||
bool get canDelete =>
|
bool get canDelete =>
|
||||||
access == UserAccessLevels.FULL ||
|
access == UserAccessLevels.FULL ||
|
||||||
access == UserAccessLevels.INTERMEDIATE;
|
access == UserAccessLevels.INTERMEDIATE;
|
||||||
|
@ -31,7 +31,7 @@ const TextStyle _userNameStyle = TextStyle(
|
|||||||
fontSize: 16.0);
|
fontSize: 16.0);
|
||||||
|
|
||||||
/// Post actions
|
/// Post actions
|
||||||
enum _PostActions { DELETE }
|
enum _PostActions { DELETE, UPDATE_CONTENT }
|
||||||
|
|
||||||
class PostTile extends StatefulWidget {
|
class PostTile extends StatefulWidget {
|
||||||
final Post post;
|
final Post post;
|
||||||
@ -99,6 +99,13 @@ class _PostTileState extends State<PostTile> {
|
|||||||
|
|
||||||
PopupMenuButton<_PostActions>(
|
PopupMenuButton<_PostActions>(
|
||||||
itemBuilder: (c) => [
|
itemBuilder: (c) => [
|
||||||
|
// Update post content
|
||||||
|
PopupMenuItem(
|
||||||
|
child: Text(tr("Update content")),
|
||||||
|
value: _PostActions.UPDATE_CONTENT,
|
||||||
|
enabled: widget.post.canUpdate,
|
||||||
|
),
|
||||||
|
|
||||||
// Delete post
|
// Delete post
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
child: Text(tr("Delete")),
|
child: Text(tr("Delete")),
|
||||||
@ -422,12 +429,38 @@ class _PostTileState extends State<PostTile> {
|
|||||||
/// Method called each time the user has selected an option
|
/// Method called each time the user has selected an option
|
||||||
void _selectedPostMenuAction(_PostActions value) {
|
void _selectedPostMenuAction(_PostActions value) {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
|
// Update post content
|
||||||
|
case _PostActions.UPDATE_CONTENT:
|
||||||
|
updateContent();
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Delete post
|
||||||
case _PostActions.DELETE:
|
case _PostActions.DELETE:
|
||||||
confirmDelete();
|
confirmDelete();
|
||||||
break;
|
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
|
/// Perform the deletion of the post
|
||||||
Future<void> confirmDelete() async {
|
Future<void> confirmDelete() async {
|
||||||
// Ask user confirmation
|
// Ask user confirmation
|
||||||
|
Loading…
Reference in New Issue
Block a user