mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 21:09:21 +00:00
Display the list of memberships
This commit is contained in:
parent
286639889b
commit
c5c544fb34
@ -7,7 +7,6 @@ import 'package:comunic/models/group.dart';
|
|||||||
/// @author Pierre HUBERT
|
/// @author Pierre HUBERT
|
||||||
|
|
||||||
class GroupsList extends MapBase<int, Group> {
|
class GroupsList extends MapBase<int, Group> {
|
||||||
|
|
||||||
final Map<int, Group> _groups = Map();
|
final Map<int, Group> _groups = Map();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -25,5 +24,5 @@ class GroupsList extends MapBase<int, Group> {
|
|||||||
@override
|
@override
|
||||||
Group remove(Object key) => _groups.remove(key);
|
Group remove(Object key) => _groups.remove(key);
|
||||||
|
|
||||||
|
Group getGroup(int id) => this[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,4 +5,29 @@ import 'package:comunic/models/membership.dart';
|
|||||||
///
|
///
|
||||||
/// @author Pierre Hubert
|
/// @author Pierre Hubert
|
||||||
|
|
||||||
class MembershipList extends AbstractList<Membership> {}
|
class MembershipList extends AbstractList<Membership> {
|
||||||
|
/// Get the IDs of all the users included in some way in this list
|
||||||
|
Set<int> get usersId {
|
||||||
|
final s = Set<int>();
|
||||||
|
|
||||||
|
forEach((m) {
|
||||||
|
switch (m.type) {
|
||||||
|
case MembershipType.FRIEND:
|
||||||
|
s.add(m.friend.id);
|
||||||
|
break;
|
||||||
|
case MembershipType.GROUP:
|
||||||
|
break;
|
||||||
|
case MembershipType.CONVERSATION:
|
||||||
|
s.addAll(m.conversation.members);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the ID of the groups included in this list
|
||||||
|
Set<int> get groupsId => where((f) => f.type == MembershipType.GROUP)
|
||||||
|
.map((f) => f.groupID)
|
||||||
|
.toSet();
|
||||||
|
}
|
||||||
|
@ -35,4 +35,17 @@ class Membership {
|
|||||||
friend = null,
|
friend = null,
|
||||||
assert(groupID != null),
|
assert(groupID != null),
|
||||||
assert(groupLastActive != null);
|
assert(groupLastActive != null);
|
||||||
|
|
||||||
|
int get lastActive {
|
||||||
|
switch (type) {
|
||||||
|
case MembershipType.FRIEND:
|
||||||
|
return friend.lastActive;
|
||||||
|
case MembershipType.GROUP:
|
||||||
|
return groupLastActive;
|
||||||
|
case MembershipType.CONVERSATION:
|
||||||
|
return conversation.lastActive;
|
||||||
|
default:
|
||||||
|
throw Exception("Unreachable statment!");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,9 @@ class _TabletRouteState extends State<TabletRoute> {
|
|||||||
|
|
||||||
Widget _buildLeftPane() => Theme(
|
Widget _buildLeftPane() => Theme(
|
||||||
data: Theme.of(context).copyWith(
|
data: Theme.of(context).copyWith(
|
||||||
textTheme: TextTheme(body1: TextStyle(color: Colors.white))),
|
textTheme: TextTheme(body1: TextStyle(color: Colors.white)),
|
||||||
|
iconTheme: IconThemeData(color: Colors.white),
|
||||||
|
),
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 300,
|
width: 300,
|
||||||
color: Color(0xFF222D32),
|
color: Color(0xFF222D32),
|
||||||
|
@ -1,6 +1,17 @@
|
|||||||
|
import 'package:comunic/helpers/conversations_helper.dart';
|
||||||
|
import 'package:comunic/helpers/groups_helper.dart';
|
||||||
|
import 'package:comunic/helpers/users_helper.dart';
|
||||||
import 'package:comunic/helpers/webapp_helper.dart';
|
import 'package:comunic/helpers/webapp_helper.dart';
|
||||||
|
import 'package:comunic/lists/groups_list.dart';
|
||||||
import 'package:comunic/lists/memberships_list.dart';
|
import 'package:comunic/lists/memberships_list.dart';
|
||||||
|
import 'package:comunic/lists/users_list.dart';
|
||||||
|
import 'package:comunic/models/membership.dart';
|
||||||
|
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
||||||
|
import 'package:comunic/ui/widgets/group_icon_widget.dart';
|
||||||
import 'package:comunic/ui/widgets/safe_state.dart';
|
import 'package:comunic/ui/widgets/safe_state.dart';
|
||||||
|
import 'package:comunic/utils/date_utils.dart';
|
||||||
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
|
import 'package:comunic/utils/ui_utils.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
/// Memberships panel
|
/// Memberships panel
|
||||||
@ -12,15 +23,24 @@ class MembershipsPanel extends StatefulWidget {
|
|||||||
_MembershipsPanelState createState() => _MembershipsPanelState();
|
_MembershipsPanelState createState() => _MembershipsPanelState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const _MembershipIconsWidth = 30.0;
|
||||||
|
|
||||||
class _MembershipsPanelState extends SafeState<MembershipsPanel> {
|
class _MembershipsPanelState extends SafeState<MembershipsPanel> {
|
||||||
|
final _refreshKey = GlobalKey<RefreshIndicatorState>();
|
||||||
MembershipList _membershipList;
|
MembershipList _membershipList;
|
||||||
|
UsersList _usersList;
|
||||||
|
GroupsList _groupsList;
|
||||||
|
|
||||||
Future<void> _refresh() async {
|
Future<void> _refresh() async {
|
||||||
try {
|
try {
|
||||||
final memberships = await WebAppHelper.getMemberships();
|
final memberships = await WebAppHelper.getMemberships();
|
||||||
|
final users = await UsersHelper().getListWithThrow(memberships.usersId);
|
||||||
|
final groups = await GroupsHelper().getListOrThrow(memberships.groupsId);
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_membershipList = memberships;
|
_membershipList = memberships;
|
||||||
|
_usersList = users;
|
||||||
|
_groupsList = groups;
|
||||||
});
|
});
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
print("Could not load the list of memberships! $e\n$s");
|
print("Could not load the list of memberships! $e\n$s");
|
||||||
@ -36,6 +56,72 @@ class _MembershipsPanelState extends SafeState<MembershipsPanel> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container();
|
if (_membershipList == null) return buildCenteredProgressBar();
|
||||||
|
|
||||||
|
return RefreshIndicator(
|
||||||
|
key: _refreshKey, child: _buildMembershipsList(), onRefresh: _refresh);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildMembershipsList() {
|
||||||
|
return ListTileTheme(
|
||||||
|
iconColor: IconTheme.of(context).color,
|
||||||
|
child: ListView.builder(
|
||||||
|
itemBuilder: _buildMembershipTile,
|
||||||
|
itemCount: _membershipList.length,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildMembershipTile(BuildContext context, int index) {
|
||||||
|
final membership = _membershipList[index];
|
||||||
|
|
||||||
|
switch (membership.type) {
|
||||||
|
case MembershipType.FRIEND:
|
||||||
|
return _buildFriendMembership(membership);
|
||||||
|
|
||||||
|
case MembershipType.GROUP:
|
||||||
|
return _buildGroupMembership(membership);
|
||||||
|
|
||||||
|
case MembershipType.CONVERSATION:
|
||||||
|
return _buildConversationMembership(membership);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO : add support for requested friendship
|
||||||
|
// TODO : add private messages icon support
|
||||||
|
Widget _buildFriendMembership(Membership membership) {
|
||||||
|
final user = _usersList.getUser(membership.friend.id);
|
||||||
|
final connected = membership.friend.isConnected;
|
||||||
|
return ListTile(
|
||||||
|
leading: AccountImageWidget(user: user, width: _MembershipIconsWidth),
|
||||||
|
title: Text(user.displayName),
|
||||||
|
subtitle: Text(
|
||||||
|
connected ? tr("Online") : diffTimeFromNowToStr(membership.lastActive),
|
||||||
|
style: TextStyle(color: connected ? Colors.green : null),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO : add support for pending groups memberships
|
||||||
|
Widget _buildGroupMembership(Membership membership) {
|
||||||
|
final group = _groupsList.getGroup(membership.groupID);
|
||||||
|
return ListTile(
|
||||||
|
leading: GroupIcon(
|
||||||
|
group: group,
|
||||||
|
width: _MembershipIconsWidth,
|
||||||
|
),
|
||||||
|
title: Text(group.displayName),
|
||||||
|
subtitle: Text(diffTimeFromNowToStr(membership.lastActive)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildConversationMembership(Membership membership) {
|
||||||
|
return ListTile(
|
||||||
|
dense: true,
|
||||||
|
leading: Icon(Icons.message),
|
||||||
|
title: Text(ConversationsHelper.getConversationName(
|
||||||
|
membership.conversation, _usersList)),
|
||||||
|
subtitle: Text(diffTimeFromNowToStr(membership.lastActive)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user