1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2025-06-19 00:05:16 +00:00

Continue to fix issues

This commit is contained in:
2022-03-10 20:36:55 +01:00
parent 299a95ea45
commit 7a0b44e446
30 changed files with 66 additions and 126 deletions

View File

@ -33,7 +33,7 @@ class AccountHelper {
/// Warning : This method MUST BE CALLED AT LEAST ONCE AFTER APP START !!!
Future<bool> signedIn() async {
bool signedIn =
(await PreferencesHelper.getInstance())!.getLoginToken() != null;
(await PreferencesHelper.getInstance()).getLoginToken() != null;
// Load current user ID for later use
if (signedIn && _currentUserID == -1) await _loadCurrentUserID();
@ -56,8 +56,8 @@ class AccountHelper {
else if (response.code != 200) return AuthResult.NETWORK_ERROR;
// Save login token
await (await PreferencesHelper.getInstance())!
.setLoginToken(response.getObject()!["token"]);
await (await PreferencesHelper.getInstance())
.setLoginToken(response.getObject()["token"]);
// Get current user ID
final userID = await _downloadCurrentUserID();
@ -132,7 +132,7 @@ class AccountHelper {
/// Get current user email address
static Future<String?> getCurrentAccountEmailAddress() async =>
(await APIRequest.withLogin("account/mail")
.execWithThrowGetObject())!["mail"];
.execWithThrowGetObject())["mail"];
/// Check out whether security questions have been set for an account or not
///
@ -141,7 +141,7 @@ class AccountHelper {
(await APIRequest.withoutLogin("account/has_security_questions")
.addString("email", email)
.execWithThrow())
.getObject()!["defined"];
.getObject()["defined"];
/// Get the security questions of the user
///
@ -150,7 +150,7 @@ class AccountHelper {
((await APIRequest.withoutLogin("account/get_security_questions")
.addString("email", email)
.execWithThrow())
.getObject()!["questions"])
.getObject()["questions"])
.cast<String>();
/// Validate given security answers
@ -165,7 +165,7 @@ class AccountHelper {
.addString("answers",
answers.map((f) => Uri.encodeComponent(f)).join("&"))
.execWithThrow())
.getObject()!["reset_token"];
.getObject()["reset_token"];
/// Check a password reset token
///
@ -200,13 +200,12 @@ class AccountHelper {
if (response.code != 200) return null;
return response.getObject()!["userID"];
return response.getObject()["userID"];
}
/// Get the ID of the currently signed in user
Future<void> _loadCurrentUserID() async {
final preferences =
await PreferencesHelper.getInstance();
final preferences = await PreferencesHelper.getInstance();
_currentUserID = preferences.getInt(PreferencesKeyList.USER_ID);
}

View File

@ -23,7 +23,7 @@ class APIHelper {
//Add user token (if required)
if (request.needLogin) {
final token = (await PreferencesHelper.getInstance())!.getLoginToken();
final token = (await PreferencesHelper.getInstance()).getLoginToken();
if (token == null) {
EventsHelper.emit(InvalidLoginTokensEvent());

View File

@ -38,7 +38,7 @@ class ConversationsHelper {
/// Throws in case of failure
static Future<int> createConversation(NewConversation settings) async {
final response = await APIRequest.withLogin("conversations/create", args: {
"name": settings.name ?? "",
"name": settings.name,
"follow": settings.follow ? "true" : "false",
"users": settings.members.join(","),
"color": colorToHex(settings.color)
@ -46,7 +46,7 @@ class ConversationsHelper {
.addBool("canEveryoneAddMembers", settings.canEveryoneAddMembers)
.execWithThrow();
return response.getObject()!["conversationID"];
return response.getObject()["conversationID"];
}
/// Add a member to a conversation.
@ -89,7 +89,7 @@ class ConversationsHelper {
// Update conversation settings
if (settings.isComplete)
request
.addString("name", settings.name ?? "")
.addString("name", settings.name)
.addBool("canEveryoneAddMembers", settings.canEveryoneAddMembers!)
.addString("color", colorToHex(settings.color));
@ -153,7 +153,7 @@ class ConversationsHelper {
needLogin: true,
args: {"conversationID": id.toString()}).execWithThrow();
final conversation = apiToConversation(response.getObject()!);
final conversation = apiToConversation(response.getObject());
await ConversationsSerializationHelper()
.insertOrReplaceElement((c) => c.id == conversation.id, conversation);
@ -210,7 +210,7 @@ class ConversationsHelper {
).execWithThrow();
// Get and return conversation ID
return int.parse(response.getObject()!["conversationsID"][0].toString());
return int.parse(response.getObject()["conversationsID"][0].toString());
}
/// Asynchronously get the name of the conversation

View File

@ -107,7 +107,7 @@ class FriendsHelper {
if (response.code != 200)
throw Exception("Could not get friendship status!");
final obj = response.getObject()!;
final obj = response.getObject();
return FriendStatus(
userID: userID,

View File

@ -69,7 +69,7 @@ class GroupsHelper {
final list = GroupsList();
response
.getObject()!
.getObject()
.forEach((k, d) => list[int.parse(k)] = getGroupFromAPI(d));
return list;
@ -189,7 +189,7 @@ class GroupsHelper {
case 200:
return GetAdvancedInfoResult(GetAdvancedInfoStatus.SUCCESS,
_getAdvancedGroupInfoFromAPI(result.getObject()!));
_getAdvancedGroupInfoFromAPI(result.getObject()));
default:
throw Exception("Could not get advanced group information!");

View File

@ -55,7 +55,7 @@ class NotificationsHelper {
await APIRequest(uri: "notifications/count_all_news", needLogin: true)
.exec();
final content = response.assertOk().getObject()!;
final content = response.assertOk().getObject();
return CountUnreadNotifications(
notifications: content["notifications"],

View File

@ -123,7 +123,7 @@ class PostsHelper {
if (!response.isOK)
throw Exception("Could not get information about the post!");
return _apiToPost(response.getObject()!);
return _apiToPost(response.getObject());
}
/// Create a new post
@ -177,7 +177,6 @@ class PostsHelper {
default:
throw Exception("Unsupported post type :" + post.kind.toString());
break;
}
final response = await request.execWithFiles();

View File

@ -47,13 +47,13 @@ class PushNotificationsHelper {
response["independent_push_url"]);
}
await (await PreferencesHelper.getInstance())!.setString(
await (await PreferencesHelper.getInstance()).setString(
PreferencesKeyList.PUSH_NOTIFICATIONS_STATUS, response["status"]);
}
/// Clear local push notifications status
static Future<void> clearLocalStatus() async {
await (await PreferencesHelper.getInstance())!
await (await PreferencesHelper.getInstance())
.removeKey(PreferencesKeyList.PUSH_NOTIFICATIONS_STATUS);
// Stop local refresh notification refresh

View File

@ -15,7 +15,7 @@ class ServerConfigurationHelper {
final response =
(await APIRequest.withoutLogin("server/config").execWithThrow())
.getObject()!;
.getObject();
final banner = response["banner"];
final pushNotificationsPolicy = response["push_notifications"];

View File

@ -25,7 +25,7 @@ class SettingsHelper {
final response =
(await APIRequest(uri: "settings/get_general", needLogin: true).exec())
.assertOk()
.getObject()!;
.getObject();
return GeneralSettings(
email: response["email"],
@ -88,7 +88,7 @@ class SettingsHelper {
(await APIRequest(uri: "settings/get_account_image", needLogin: true)
.exec())
.assertOk()
.getObject()!;
.getObject();
return AccountImageSettings(
hasImage: response["has_image"],
@ -175,7 +175,7 @@ class SettingsHelper {
(await APIRequest(uri: "settings/get_security", needLogin: true)
.addString("password", password)
.execWithThrow())
.getObject()!;
.getObject();
return SecuritySettings(
securityQuestion1: response["security_question_1"],
@ -207,7 +207,7 @@ class SettingsHelper {
final response =
(await APIRequest.withLogin("settings/get_data_conservation_policy")
.execWithThrow())
.getObject()!;
.getObject();
return DataConservationPolicySettings(
inactiveAccountLifeTime: response["inactive_account_lifetime"],

View File

@ -12,7 +12,7 @@ class SurveyHelper {
apiToSurvey((await APIRequest.withLogin("surveys/get_info")
.addInt("postID", postID)
.execWithThrow())
.getObject()!);
.getObject());
/// Cancel the response of a user to a survey
Future<bool> cancelResponse(Survey survey) async {

View File

@ -23,7 +23,7 @@ enum GetUserAdvancedInformationErrorCause {
class GetUserAdvancedUserError extends Error {
final GetUserAdvancedInformationErrorCause cause;
GetUserAdvancedUserError(this.cause) : assert(cause != null);
GetUserAdvancedUserError(this.cause);
}
class UsersHelper {
@ -42,7 +42,7 @@ class UsersHelper {
if (response.code != 200) return null;
final list = UsersList();
response.getObject()!.forEach(
response.getObject().forEach(
(k, v) => list.add(
User(
id: v["userID"],
@ -151,7 +151,7 @@ class UsersHelper {
throw new GetUserAdvancedUserError(cause);
}
return apiToAdvancedUserInfo(response.getObject()!);
return apiToAdvancedUserInfo(response.getObject());
}
/// Parse the list of custom emojies

View File

@ -29,8 +29,8 @@ class VirtualDirectoryHelper {
return VirtualDirectoryResult(type: VirtualDirectoryType.NONE);
case 200:
final id = response.getObject()!["id"];
final kind = response.getObject()!["kind"];
final id = response.getObject()["id"];
final kind = response.getObject()["kind"];
switch (kind) {
case "user":
return VirtualDirectoryResult(
@ -42,7 +42,6 @@ class VirtualDirectoryHelper {
default:
throw Exception("Unsupported virtual directory kind: $kind");
}
break;
default:
throw new Exception("Could not get virtual directory!");

View File

@ -30,7 +30,7 @@ class WebSocketHelper {
static Future<String?> _getWsToken() async =>
(await APIRequest(uri: "ws/token", needLogin: true).exec())
.assertOk()
.getObject()!["token"];
.getObject()["token"];
/// Connect to WebSocket
static connect() async {