1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 21:09:21 +00:00

Can update following status of a group

This commit is contained in:
Pierre HUBERT 2020-04-15 18:39:07 +02:00
parent 566f205dc9
commit add1712b7d
5 changed files with 79 additions and 6 deletions

View File

@ -148,6 +148,14 @@ class GroupsHelper {
"accept": accept ? "true" : "false", "accept": accept ? "true" : "false",
}); });
/// Update group following status
Future<bool> setFollowing(int groupID, bool follow) async =>
(await (APIRequest(uri: "groups/set_following", needLogin: true)
..addInt("groupID", groupID)
..addBool("follow", follow))
.exec())
.isOK;
/// Get advanced information about the user /// Get advanced information about the user
Future<GetAdvancedInfoResult> getAdvancedInfo(int groupID) async { Future<GetAdvancedInfoResult> getAdvancedInfo(int groupID) async {
// Get advanced information about the user // Get advanced information about the user

View File

@ -29,7 +29,7 @@ class Group {
final GroupRegistrationLevel registrationLevel; final GroupRegistrationLevel registrationLevel;
final GroupPostCreationLevel postCreationLevel; final GroupPostCreationLevel postCreationLevel;
final String virtualDirectory; final String virtualDirectory;
final bool following; bool following;
Group({ Group({
@required this.id, @required this.id,
@ -54,7 +54,7 @@ class Group {
get displayName => this.name; get displayName => this.name;
bool get getIsAtLeastMember => bool get isAtLeastMember =>
membershipLevel == GroupMembershipLevel.ADMINISTRATOR || membershipLevel == GroupMembershipLevel.ADMINISTRATOR ||
membershipLevel == GroupMembershipLevel.MODERATOR || membershipLevel == GroupMembershipLevel.MODERATOR ||
membershipLevel == GroupMembershipLevel.MEMBER; membershipLevel == GroupMembershipLevel.MEMBER;

View File

@ -1,4 +1,5 @@
import 'package:comunic/models/advanced_group_info.dart'; import 'package:comunic/models/advanced_group_info.dart';
import 'package:comunic/ui/widgets/group_following_widget.dart';
import 'package:comunic/ui/widgets/group_icon_widget.dart'; import 'package:comunic/ui/widgets/group_icon_widget.dart';
import 'package:comunic/ui/widgets/group_membership_widget.dart'; import 'package:comunic/ui/widgets/group_membership_widget.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -50,9 +51,18 @@ class _AuthorizedGroupPageScreenState extends State<AuthorizedGroupPageScreen> {
style: TextStyle(fontSize: 20), style: TextStyle(fontSize: 20),
), ),
Spacer(), Spacer(),
Column(
children: <Widget>[
GroupMembershipWidget( GroupMembershipWidget(
group: _group, group: _group,
onUpdated: () => widget.needRefresh(), onUpdated: () => widget.needRefresh(),
),
Container(height: 10,),
GroupFollowingWidget(
group: _group,
onUpdated: () => widget.needRefresh(),
),
],
) )
], ],
), ),

View File

@ -95,7 +95,7 @@ class _GroupAccessDeniedScreenState extends SafeState<GroupAccessDeniedScreen> {
// Get information about a single group // Get information about a single group
final group = await GroupsHelper().getSingle(widget.groupID, force: true); final group = await GroupsHelper().getSingle(widget.groupID, force: true);
if (group.getIsAtLeastMember) widget.onMembershipAcquired(); if (group.isAtLeastMember) widget.onMembershipAcquired();
setState(() => _group = group); setState(() => _group = group);
} catch (e) { } catch (e) {

View File

@ -0,0 +1,55 @@
import 'package:comunic/helpers/groups_helper.dart';
import 'package:comunic/models/group.dart';
import 'package:comunic/ui/widgets/safe_state.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart';
/// Group following status widget
///
/// @author Pierre Hubert
class GroupFollowingWidget extends StatefulWidget {
final Group group;
final Function() onUpdated;
const GroupFollowingWidget(
{Key key, @required this.group, @required this.onUpdated})
: assert(group != null),
assert(onUpdated != null),
super(key: key);
@override
_GroupFollowingWidgetState createState() => _GroupFollowingWidgetState();
}
class _GroupFollowingWidgetState extends SafeState<GroupFollowingWidget> {
Group get _group => widget.group;
@override
Widget build(BuildContext context) {
if (!_group.isAtLeastMember) return Container();
return InkWell(
child: Text(
_group.following ? tr("Following") : tr("Follow"),
style: TextStyle(color: Colors.blue),
),
onTap: () => _toggleFollowing(),
);
}
/// Toggle following status
void _toggleFollowing() async {
if (!await GroupsHelper().setFollowing(_group.id, !_group.following)) {
showSimpleSnack(context, tr("Could not update following status!"));
return;
}
setState(() {
_group.following = !_group.following;
this.widget.onUpdated();
});
}
}