mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 21:09:21 +00:00
Register to comment udpate events
This commit is contained in:
parent
a60c1ed68c
commit
6b08b62832
@ -31,6 +31,13 @@ class NewCommentEvent {
|
|||||||
NewCommentEvent(this.comment);
|
NewCommentEvent(this.comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Updated comment
|
||||||
|
class UpdatedCommentEvent {
|
||||||
|
final Comment comment;
|
||||||
|
|
||||||
|
UpdatedCommentEvent(this.comment);
|
||||||
|
}
|
||||||
|
|
||||||
class EventsHelper {
|
class EventsHelper {
|
||||||
static EventBus _mgr = EventBus();
|
static EventBus _mgr = EventBus();
|
||||||
|
|
||||||
|
@ -126,6 +126,12 @@ class WebSocketHelper {
|
|||||||
NewCommentEvent(CommentsHelper.apiToComment(msg.data)));
|
NewCommentEvent(CommentsHelper.apiToComment(msg.data)));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// Updated comment
|
||||||
|
case "comment_updated":
|
||||||
|
EventsHelper.emit(
|
||||||
|
UpdatedCommentEvent(CommentsHelper.apiToComment(msg.data)));
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw Exception("Unknown message type: ${msg.title}");
|
throw Exception("Unknown message type: ${msg.title}");
|
||||||
}
|
}
|
||||||
|
@ -510,10 +510,6 @@ class _PostTileState extends State<PostTile> {
|
|||||||
|
|
||||||
if (!(await _commentsHelper.updateContent(comment.id, newContent)))
|
if (!(await _commentsHelper.updateContent(comment.id, newContent)))
|
||||||
return showSimpleSnack(context, tr("Could not update comment content!"));
|
return showSimpleSnack(context, tr("Could not update comment content!"));
|
||||||
|
|
||||||
setState(() {
|
|
||||||
comment.content.content = newContent;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Process the deletion of a user
|
/// Process the deletion of a user
|
||||||
@ -575,7 +571,7 @@ class _PostTileState extends State<PostTile> {
|
|||||||
title: tr("Update post content"),
|
title: tr("Update post content"),
|
||||||
message: tr("Please enter message content: "),
|
message: tr("Please enter message content: "),
|
||||||
defaultValue:
|
defaultValue:
|
||||||
widget.post.content.isNull == null ? "" : widget.post.content.content,
|
widget.post.content.isNull == null ? "" : widget.post.content.content,
|
||||||
hint: tr("Post content"),
|
hint: tr("Post content"),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -70,6 +70,8 @@ class PostsListWidgetState extends SafeState<PostsListWidget> {
|
|||||||
|
|
||||||
// Register to events
|
// Register to events
|
||||||
this.listen<NewCommentEvent>((ev) => this._addComment(ev.comment));
|
this.listen<NewCommentEvent>((ev) => this._addComment(ev.comment));
|
||||||
|
this.listenChangeState<UpdatedCommentEvent>(
|
||||||
|
(ev) => this._updateComment(ev.comment));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -244,4 +246,21 @@ class PostsListWidgetState extends SafeState<PostsListWidget> {
|
|||||||
print("$e\n$stack");
|
print("$e\n$stack");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Update a comment
|
||||||
|
void _updateComment(Comment c) {
|
||||||
|
if (_list == null) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
final p = _list.singleWhere((p) => p.id == c.postID, orElse: () => null);
|
||||||
|
|
||||||
|
if (p == null) return;
|
||||||
|
|
||||||
|
final index = p.comments.indexWhere((d) => d.id == c.id);
|
||||||
|
|
||||||
|
if (index > -1) p.comments[index] = c;
|
||||||
|
} catch (e, stack) {
|
||||||
|
print("$e\n$stack");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user