mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Start to build groups page
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import 'package:comunic/lists/groups_list.dart';
|
||||
import 'package:comunic/models/advanced_group_info.dart';
|
||||
import 'package:comunic/models/api_request.dart';
|
||||
import 'package:comunic/models/group.dart';
|
||||
import 'package:comunic/utils/api_utils.dart';
|
||||
@ -35,6 +36,17 @@ const _APIGroupsPostsCreationLevelsMap = {
|
||||
|
||||
final _groupsListCache = GroupsList();
|
||||
|
||||
/// Callback for getting advanced user information
|
||||
enum GetAdvancedInfoStatus { SUCCESS, ACCESS_DENIED }
|
||||
|
||||
class GetAdvancedInfoResult {
|
||||
final GetAdvancedInfoStatus status;
|
||||
final AdvancedGroupInfo info;
|
||||
|
||||
GetAdvancedInfoResult(this.status, this.info) : assert(status != null);
|
||||
}
|
||||
|
||||
/// Groups helper
|
||||
class GroupsHelper {
|
||||
/// Download a list of groups information from the server
|
||||
Future<GroupsList> _downloadList(Set<int> groups) async {
|
||||
@ -92,6 +104,15 @@ class GroupsHelper {
|
||||
return list;
|
||||
}
|
||||
|
||||
/// Get information about a single group
|
||||
///
|
||||
/// Throws in case of failure
|
||||
Future<Group> getSingle(int groupID, {bool force = false}) async {
|
||||
return (await getListOrThrow(Set<int>()..add(groupID), force: force))
|
||||
.values
|
||||
.first;
|
||||
}
|
||||
|
||||
/// Get the list of groups of a user
|
||||
Future<Set<int>> getListUser() async =>
|
||||
(await APIRequest(uri: "groups/get_my_list", needLogin: true).exec())
|
||||
@ -127,6 +148,27 @@ class GroupsHelper {
|
||||
"accept": accept ? "true" : "false",
|
||||
});
|
||||
|
||||
/// Get advanced information about the user
|
||||
Future<GetAdvancedInfoResult> getAdvancedInfo(int groupID) async {
|
||||
// Get advanced information about the user
|
||||
final result =
|
||||
await (APIRequest(uri: "groups/get_advanced_info", needLogin: true)
|
||||
..addInt("id", groupID))
|
||||
.exec();
|
||||
|
||||
switch (result.code) {
|
||||
case 401:
|
||||
return GetAdvancedInfoResult(GetAdvancedInfoStatus.ACCESS_DENIED, null);
|
||||
|
||||
case 200:
|
||||
return GetAdvancedInfoResult(GetAdvancedInfoStatus.SUCCESS,
|
||||
_getAdvancedGroupInfoFromAPI(result.getObject()));
|
||||
|
||||
default:
|
||||
throw Exception("Could not get advanced group information!");
|
||||
}
|
||||
}
|
||||
|
||||
/// Turn an API entry into a group object
|
||||
Group _getGroupFromAPI(Map<String, dynamic> map) {
|
||||
return Group(
|
||||
@ -142,4 +184,25 @@ class GroupsHelper {
|
||||
virtualDirectory: map["virtual_directory"],
|
||||
following: map["following"]);
|
||||
}
|
||||
|
||||
/// Get advanced group information
|
||||
AdvancedGroupInfo _getAdvancedGroupInfoFromAPI(Map<String, dynamic> map) =>
|
||||
AdvancedGroupInfo(
|
||||
id: map["id"],
|
||||
name: map["name"],
|
||||
iconURL: map["icon_url"],
|
||||
numberMembers: map["number_members"],
|
||||
membershipLevel: _APIGroupsMembershipLevelsMap[map["membership"]],
|
||||
visibilityLevel: _APIGroupsVisibilityLevelsMap[map["visibility"]],
|
||||
registrationLevel:
|
||||
_APIGroupsRegistrationLevelsMap[map["registration_level"]],
|
||||
postCreationLevel: _APIGroupsPostsCreationLevelsMap[map["posts_level"]],
|
||||
virtualDirectory: map["virtual_directory"],
|
||||
following: map["following"],
|
||||
timeCreate: map["time_create"],
|
||||
description: map["description"],
|
||||
url: map["url"],
|
||||
numberLikes: map["number_likes"],
|
||||
isLiking: map["is_liking"],
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user