mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 22:39:22 +00:00
Handles comment deletion events
This commit is contained in:
parent
6b08b62832
commit
dab4e7bde1
@ -38,6 +38,14 @@ class UpdatedCommentEvent {
|
|||||||
UpdatedCommentEvent(this.comment);
|
UpdatedCommentEvent(this.comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Deleted comment
|
||||||
|
class DeletedCommentEvent {
|
||||||
|
final int commentID;
|
||||||
|
|
||||||
|
DeletedCommentEvent(this.commentID);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class EventsHelper {
|
class EventsHelper {
|
||||||
static EventBus _mgr = EventBus();
|
static EventBus _mgr = EventBus();
|
||||||
|
|
||||||
|
@ -132,6 +132,11 @@ class WebSocketHelper {
|
|||||||
UpdatedCommentEvent(CommentsHelper.apiToComment(msg.data)));
|
UpdatedCommentEvent(CommentsHelper.apiToComment(msg.data)));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// Deleted comment
|
||||||
|
case "comment_deleted":
|
||||||
|
EventsHelper.emit(DeletedCommentEvent(msg.data));
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw Exception("Unknown message type: ${msg.title}");
|
throw Exception("Unknown message type: ${msg.title}");
|
||||||
}
|
}
|
||||||
|
@ -523,11 +523,6 @@ class _PostTileState extends State<PostTile> {
|
|||||||
showSimpleSnack(context, tr("Could not delete the comment!"));
|
showSimpleSnack(context, tr("Could not delete the comment!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the comment from the list
|
|
||||||
setState(() {
|
|
||||||
widget.post.comments.remove(comment);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Method called each time the user has selected an option
|
/// Method called each time the user has selected an option
|
||||||
|
@ -72,6 +72,8 @@ class PostsListWidgetState extends SafeState<PostsListWidget> {
|
|||||||
this.listen<NewCommentEvent>((ev) => this._addComment(ev.comment));
|
this.listen<NewCommentEvent>((ev) => this._addComment(ev.comment));
|
||||||
this.listenChangeState<UpdatedCommentEvent>(
|
this.listenChangeState<UpdatedCommentEvent>(
|
||||||
(ev) => this._updateComment(ev.comment));
|
(ev) => this._updateComment(ev.comment));
|
||||||
|
this.listenChangeState<DeletedCommentEvent>(
|
||||||
|
(ev) => this._removeComment(ev.commentID));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -263,4 +265,11 @@ class PostsListWidgetState extends SafeState<PostsListWidget> {
|
|||||||
print("$e\n$stack");
|
print("$e\n$stack");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Remove a comment from the list
|
||||||
|
void _removeComment(int commentID) {
|
||||||
|
if (_list == null) return;
|
||||||
|
|
||||||
|
_list.forEach((p) => p.comments.removeWhere((c) => c.id == commentID));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user