mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 12:59:21 +00:00
Handle comments notifications
This commit is contained in:
parent
5250eb59b4
commit
053035f350
@ -84,6 +84,20 @@ class PostsHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get a single post information
|
||||||
|
Future<Post> getSingle(int postID) async {
|
||||||
|
final response = await APIRequest(
|
||||||
|
uri: "posts/get_single",
|
||||||
|
args: {"postID": postID.toString()},
|
||||||
|
needLogin: true,
|
||||||
|
).exec();
|
||||||
|
|
||||||
|
if (!response.isOK)
|
||||||
|
throw Exception("Could not get information about the post!");
|
||||||
|
|
||||||
|
return _apiToPost(response.getObject());
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a new post
|
/// Create a new post
|
||||||
///
|
///
|
||||||
/// This function crash in case of error
|
/// This function crash in case of error
|
||||||
|
62
lib/ui/routes/single_post_route.dart
Normal file
62
lib/ui/routes/single_post_route.dart
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
import 'package:comunic/helpers/posts_helper.dart';
|
||||||
|
import 'package:comunic/lists/posts_list.dart';
|
||||||
|
import 'package:comunic/ui/widgets/posts_list_widget.dart';
|
||||||
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
/// Single post route
|
||||||
|
///
|
||||||
|
/// @author Pierre HUBERT
|
||||||
|
|
||||||
|
class SinglePostRoute extends StatelessWidget {
|
||||||
|
final int postID;
|
||||||
|
|
||||||
|
const SinglePostRoute({
|
||||||
|
Key key,
|
||||||
|
@required this.postID,
|
||||||
|
}) : assert(postID != null),
|
||||||
|
super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text(tr("Post")),
|
||||||
|
),
|
||||||
|
body: _SinglePostRouteBody(postID: postID),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SinglePostRouteBody extends StatefulWidget {
|
||||||
|
final int postID;
|
||||||
|
|
||||||
|
const _SinglePostRouteBody({
|
||||||
|
Key key,
|
||||||
|
@required this.postID,
|
||||||
|
}) : assert(postID != null),
|
||||||
|
super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
__SinglePostRouteBodyState createState() => __SinglePostRouteBodyState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class __SinglePostRouteBodyState extends State<_SinglePostRouteBody> {
|
||||||
|
Future<PostsList> _getPost() async {
|
||||||
|
try {
|
||||||
|
return PostsList()..add(await PostsHelper().getSingle(widget.postID));
|
||||||
|
} on Exception catch (e) {
|
||||||
|
print(e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return PostsListWidget(
|
||||||
|
getPostsList: _getPost,
|
||||||
|
showPostsTarget: true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,7 @@ import 'package:comunic/models/notification.dart' as n;
|
|||||||
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
||||||
import 'package:comunic/utils/date_utils.dart';
|
import 'package:comunic/utils/date_utils.dart';
|
||||||
import 'package:comunic/utils/intl_utils.dart';
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
|
import 'package:comunic/utils/navigation_utils.dart';
|
||||||
import 'package:comunic/utils/ui_utils.dart';
|
import 'package:comunic/utils/ui_utils.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
@ -242,6 +243,7 @@ class _NotificationTile extends StatelessWidget {
|
|||||||
leading: AccountImageWidget(
|
leading: AccountImageWidget(
|
||||||
user: srcUser,
|
user: srcUser,
|
||||||
),
|
),
|
||||||
|
onTap: () => _onTap(context),
|
||||||
title: Text(message),
|
title: Text(message),
|
||||||
subtitle: Text(diffTimeFromNowToStr(notification.timeCreate)),
|
subtitle: Text(diffTimeFromNowToStr(notification.timeCreate)),
|
||||||
trailing: PopupMenuButton<_PopupMenuActions>(
|
trailing: PopupMenuButton<_PopupMenuActions>(
|
||||||
@ -263,4 +265,12 @@ class _NotificationTile extends StatelessWidget {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onTap(BuildContext context) {
|
||||||
|
if (notification.onElemType == n.NotificationElementType.POST) {
|
||||||
|
openPostFullScreen(notification.onElemId, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO : mark the notification as seen
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,9 +76,7 @@ class _PostsListWidgetState extends State<PostsListWidget> {
|
|||||||
|
|
||||||
/// Load the list of posts
|
/// Load the list of posts
|
||||||
Future<void> _loadPostsList({bool getOlder = false}) async {
|
Future<void> _loadPostsList({bool getOlder = false}) async {
|
||||||
|
if (_loading) return;
|
||||||
if(_loading)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_loading = true;
|
_loading = true;
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import 'package:comunic/ui/routes/single_post_route.dart';
|
||||||
import 'package:comunic/ui/routes/user_page_route.dart';
|
import 'package:comunic/ui/routes/user_page_route.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
@ -14,8 +15,14 @@ void openUserPage({@required int userID, @required BuildContext context}) {
|
|||||||
Navigator.of(context).push(
|
Navigator.of(context).push(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (c) => UserPageRoute(
|
builder: (c) => UserPageRoute(
|
||||||
userID: userID,
|
userID: userID,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Open a post in full screen
|
||||||
|
void openPostFullScreen(int postID, BuildContext context) {
|
||||||
|
Navigator.of(context)
|
||||||
|
.push(MaterialPageRoute(builder: (c) => SinglePostRoute(postID: postID)));
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user