mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 21:09:21 +00:00
67 lines
2.2 KiB
Dart
67 lines
2.2 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:comunic/models/account_image_settings.dart';
|
|
import 'package:comunic/models/api_request.dart';
|
|
|
|
/// Settings helper
|
|
///
|
|
/// @author Pierre Hubert
|
|
|
|
const _APIAccountImageVisibilityAPILevels = {
|
|
"open": AccountImageVisibilityLevels.EVERYONE,
|
|
"public": AccountImageVisibilityLevels.COMUNIC_USERS,
|
|
"friends": AccountImageVisibilityLevels.FRIENDS_ONLY,
|
|
};
|
|
|
|
class SettingsHelper {
|
|
/// Get & return account image settings
|
|
static Future<AccountImageSettings> getAccountImageSettings() async {
|
|
final response =
|
|
(await APIRequest(uri: "settings/get_account_image", needLogin: true)
|
|
.exec())
|
|
.assertOk()
|
|
.getObject();
|
|
|
|
return AccountImageSettings(
|
|
hasImage: response["has_image"],
|
|
imageURL: response["image_url"],
|
|
visibility:
|
|
_APIAccountImageVisibilityAPILevels[response["visibility"]]);
|
|
}
|
|
|
|
/// Upload a new account image
|
|
static Future<bool> uploadAccountImage(File newImage) async =>
|
|
(await APIRequest(uri: "settings/upload_account_image", needLogin: true)
|
|
.addFile("picture", newImage)
|
|
.execWithFiles())
|
|
.isOK;
|
|
|
|
/// Upload a new account image from memory
|
|
static Future<bool> uploadAccountImageFromMemory(List<int> bytes) async =>
|
|
(await APIRequest(uri: "settings/upload_account_image", needLogin: true)
|
|
.addBytesFile("picture", BytesFile("accountImage.png", bytes))
|
|
.execWithFiles())
|
|
.isOK;
|
|
|
|
/// Change account image visibility level
|
|
static Future<bool> setAccountImageVisibilityLevel(
|
|
AccountImageVisibilityLevels level) async =>
|
|
(await APIRequest(
|
|
uri: "settings/set_account_image_visibility", needLogin: true)
|
|
.addString(
|
|
"visibility",
|
|
|
|
// Find appropriate visibility level
|
|
_APIAccountImageVisibilityAPILevels.entries
|
|
.firstWhere((f) => f.value == level)
|
|
.key)
|
|
.exec())
|
|
.isOK;
|
|
|
|
/// Delete user account image
|
|
static Future<bool> deleteAccountImage() async =>
|
|
(await APIRequest(uri: "settings/delete_account_image", needLogin: true)
|
|
.exec())
|
|
.isOK;
|
|
}
|