mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 22:39:22 +00:00
48 lines
1.5 KiB
Dart
48 lines
1.5 KiB
Dart
import 'package:comunic/enums/user_page_visibility.dart';
|
|
import 'package:comunic/lists/users_list.dart';
|
|
import 'package:comunic/models/api_request.dart';
|
|
import 'package:comunic/models/user.dart';
|
|
|
|
/// User helper
|
|
///
|
|
/// Helper used to get information about the users of Comunic
|
|
///
|
|
/// @author Pierre HUBERT
|
|
|
|
class UsersHelper {
|
|
/// Download information about some given users ID
|
|
///
|
|
/// Return the list of users information in case of success, null in case of
|
|
/// failure
|
|
Future<UsersList> downloadInfo(List<int> users) async {
|
|
// Execute the request
|
|
final response = await APIRequest(
|
|
uri: "user/getInfoMultiple", args: {"usersID": users.join(",")}).exec();
|
|
|
|
// Check if the request did not execute correctly
|
|
if (response.code != 200) return null;
|
|
|
|
final list = UsersList();
|
|
response.getObject().forEach(
|
|
(k, v) => list.add(
|
|
User(
|
|
id: v["userID"],
|
|
firstName: v["firstName"],
|
|
lastName: v["lastName"],
|
|
pageVisibility: v["publicPage"] == "false"
|
|
? UserPageVisibility.PRIVATE
|
|
: (v["openPage"] == "false"
|
|
? UserPageVisibility.PRIVATE
|
|
: UserPageVisibility.OPEN),
|
|
virtualDirectory: v["virtualDirectory"] == ""
|
|
? null
|
|
: v["virtualDirectory"],
|
|
accountImageURL: v["accountImage"],
|
|
),
|
|
),
|
|
);
|
|
|
|
return list;
|
|
}
|
|
}
|