mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Register to post events
This commit is contained in:
@ -591,7 +591,8 @@ class _PostTileState extends State<PostTile> {
|
||||
context: context,
|
||||
title: tr("Update post content"),
|
||||
message: tr("Please enter message content: "),
|
||||
defaultValue: widget.post.content.isNull == null ? "" : widget.post.content.content,
|
||||
defaultValue:
|
||||
widget.post.content.isNull == null ? "" : widget.post.content.content,
|
||||
hint: tr("Post content"),
|
||||
);
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'package:comunic/helpers/groups_helper.dart';
|
||||
import 'package:comunic/helpers/posts_helper.dart';
|
||||
import 'package:comunic/helpers/users_helper.dart';
|
||||
import 'package:comunic/lists/groups_list.dart';
|
||||
import 'package:comunic/lists/posts_list.dart';
|
||||
@ -6,6 +7,7 @@ import 'package:comunic/lists/users_list.dart';
|
||||
import 'package:comunic/models/post.dart';
|
||||
import 'package:comunic/ui/screens/conversation_screen.dart';
|
||||
import 'package:comunic/ui/tiles/post_tile.dart';
|
||||
import 'package:comunic/ui/widgets/safe_state.dart';
|
||||
import 'package:comunic/ui/widgets/scroll_watcher.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/ui_utils.dart';
|
||||
@ -41,7 +43,7 @@ class PostsListWidget extends StatefulWidget {
|
||||
State<StatefulWidget> createState() => PostsListWidgetState();
|
||||
}
|
||||
|
||||
class PostsListWidgetState extends State<PostsListWidget> {
|
||||
class PostsListWidgetState extends SafeState<PostsListWidget> {
|
||||
// Helpers
|
||||
final UsersHelper _usersHelper = UsersHelper();
|
||||
final GroupsHelper _groupsHelper = GroupsHelper();
|
||||
@ -54,6 +56,8 @@ class PostsListWidgetState extends State<PostsListWidget> {
|
||||
ErrorLevel _error = ErrorLevel.NONE;
|
||||
bool _loading = false;
|
||||
|
||||
final _registeredPosts = Set<int>();
|
||||
|
||||
set error(ErrorLevel err) => setState(() => _error = err);
|
||||
|
||||
@override
|
||||
@ -63,6 +67,22 @@ class PostsListWidgetState extends State<PostsListWidget> {
|
||||
_scrollController = ScrollWatcher(onReachBottom: reachedPostsBottom);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
|
||||
_unregisterAllPosts();
|
||||
}
|
||||
|
||||
@override
|
||||
void setState(fn) {
|
||||
if (!mounted) return;
|
||||
super.setState(fn);
|
||||
|
||||
// Register for posts update
|
||||
_registerRequiredPosts();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
@ -111,6 +131,37 @@ class PostsListWidgetState extends State<PostsListWidget> {
|
||||
_loading = false;
|
||||
}
|
||||
|
||||
/// Register for potential new posts
|
||||
void _registerRequiredPosts() async {
|
||||
if (_list == null) return;
|
||||
|
||||
final missing = _list
|
||||
.where((f) => !_registeredPosts.contains(f.id))
|
||||
.map((f) => f.id)
|
||||
.toSet();
|
||||
|
||||
_registeredPosts.addAll(missing);
|
||||
|
||||
for (final postID in missing) {
|
||||
await PostsHelper().registerPostEvents(postID);
|
||||
}
|
||||
}
|
||||
|
||||
/// Unregister from all posts
|
||||
///
|
||||
/// This method should be called only once
|
||||
void _unregisterAllPosts() async {
|
||||
for (final postID in _registeredPosts) {
|
||||
// We put the try - catch here because we must absolutely unregister ALL
|
||||
// POSTS event if one post fails to remove
|
||||
try {
|
||||
await PostsHelper().unregisterPostEvents(postID);
|
||||
} catch (e, stack) {
|
||||
print("Could not unregister post! $e $stack");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildErrorCard() {
|
||||
return buildErrorCard(tr("Could not get the list of posts !"));
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import 'package:comunic/models/displayed_content.dart';
|
||||
import 'package:comunic/utils/bbcode_parser.dart';
|
||||
import 'package:comunic/utils/input_utils.dart';
|
||||
import 'package:comunic/utils/navigation_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -37,11 +36,11 @@ class TextWidget extends StatelessWidget {
|
||||
var content = this.content.parsedString;
|
||||
|
||||
// Parse BBcode
|
||||
if (parseBBcode)
|
||||
/*if (parseBBcode)
|
||||
return BBCodeParsedWidget(
|
||||
text: content,
|
||||
parseCallback: (style, text) => _parseLinks(context, text, style),
|
||||
);
|
||||
);*/
|
||||
|
||||
// Just parse link
|
||||
return RichText(
|
||||
|
Reference in New Issue
Block a user