mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Show groups posts
This commit is contained in:
73
lib/helpers/groups_helper.dart
Normal file
73
lib/helpers/groups_helper.dart
Normal file
@ -0,0 +1,73 @@
|
||||
import 'package:comunic/lists/groups_list.dart';
|
||||
import 'package:comunic/models/api_request.dart';
|
||||
import 'package:comunic/models/group.dart';
|
||||
|
||||
/// Groups helper
|
||||
///
|
||||
/// @author Pierre HUBERT
|
||||
|
||||
const _APIGroupsMembershipLevelsMap = {
|
||||
"administrator": GroupMembershipLevel.ADMINISTRATOR,
|
||||
"moderator": GroupMembershipLevel.MODERATOR,
|
||||
"member": GroupMembershipLevel.MEMBER,
|
||||
"invited": GroupMembershipLevel.INVITED,
|
||||
"pending": GroupMembershipLevel.PENDING,
|
||||
"visitor": GroupMembershipLevel.VISITOR
|
||||
};
|
||||
|
||||
const _APIGroupsVisibilityLevelsMap = {
|
||||
"open": GroupVisibilityLevel.OPEN,
|
||||
"private": GroupVisibilityLevel.PRIVATE,
|
||||
"secrete": GroupVisibilityLevel.SECRETE
|
||||
};
|
||||
|
||||
const _APIGroupsRegistrationLevelsMap = {
|
||||
"open": GroupRegistrationLevel.OPEN,
|
||||
"moderated": GroupRegistrationLevel.MODERATED,
|
||||
"closed": GroupRegistrationLevel.CLOSED
|
||||
};
|
||||
|
||||
const _APIGroupsPostsCreationLevelsMap = {
|
||||
"moderators": GroupPostCreationLevel.MODERATORS,
|
||||
"members": GroupPostCreationLevel.MEMBERS
|
||||
};
|
||||
|
||||
class GroupsHelper {
|
||||
/// Get a list of groups from the server
|
||||
Future<GroupsList> getList(Set<int> groups) async {
|
||||
|
||||
if(groups.length == 0)
|
||||
return GroupsList();
|
||||
|
||||
final response = await APIRequest(
|
||||
uri: "groups/get_multiple_info",
|
||||
needLogin: true,
|
||||
args: {"list": groups.join(",")},
|
||||
).exec();
|
||||
|
||||
if (response.code != 200) return null;
|
||||
|
||||
final list = GroupsList();
|
||||
|
||||
response
|
||||
.getObject()
|
||||
.forEach((k, d) => list[int.parse(k)] = _getGroupFromAPI(d));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/// Turn an API entry into a group object
|
||||
Group _getGroupFromAPI(Map<String, dynamic> map) {
|
||||
return Group(
|
||||
id: map["id"],
|
||||
name: map["name"],
|
||||
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"]);
|
||||
}
|
||||
}
|
@ -43,6 +43,9 @@ class PostsHelper {
|
||||
final response = await APIRequest(
|
||||
uri: "posts/get_latest",
|
||||
needLogin: true,
|
||||
args: {
|
||||
"include_groups": true.toString()
|
||||
}
|
||||
).exec();
|
||||
|
||||
if (response.code != 200) return null;
|
||||
|
Reference in New Issue
Block a user