1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-24 13:59:22 +00:00

Continue to fix issues

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

View File

@ -12,12 +12,12 @@ AdvancedGroupInfo? _forezGroup;
class ForezGroupHelper { class ForezGroupHelper {
static Future<void> setId(int groupID) async { static Future<void> setId(int groupID) async {
(await PreferencesHelper.getInstance())! (await PreferencesHelper.getInstance())
.setInt(PreferencesKeyList.FOREZ_GROUP, groupID); .setInt(PreferencesKeyList.FOREZ_GROUP, groupID);
} }
static Future<int?> getId() async { static Future<int?> getId() async {
return (await PreferencesHelper.getInstance())! return (await PreferencesHelper.getInstance())
.getInt(PreferencesKeyList.FOREZ_GROUP); .getInt(PreferencesKeyList.FOREZ_GROUP);
} }

View File

@ -125,7 +125,7 @@ class _ForezDirectoryScreenState extends State<ForezDirectoryScreen> {
} }
void _openUserProfile(User user) => void _openUserProfile(User user) =>
MainController.of(context)!.openUserPage(user.id!); MainController.of(context)!.openUserPage(user.id);
} }
class _ForezMemberTile extends StatelessWidget { class _ForezMemberTile extends StatelessWidget {

View File

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

View File

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

View File

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

View File

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

View File

@ -69,7 +69,7 @@ class GroupsHelper {
final list = GroupsList(); final list = GroupsList();
response response
.getObject()! .getObject()
.forEach((k, d) => list[int.parse(k)] = getGroupFromAPI(d)); .forEach((k, d) => list[int.parse(k)] = getGroupFromAPI(d));
return list; return list;
@ -189,7 +189,7 @@ class GroupsHelper {
case 200: case 200:
return GetAdvancedInfoResult(GetAdvancedInfoStatus.SUCCESS, return GetAdvancedInfoResult(GetAdvancedInfoStatus.SUCCESS,
_getAdvancedGroupInfoFromAPI(result.getObject()!)); _getAdvancedGroupInfoFromAPI(result.getObject()));
default: default:
throw Exception("Could not get advanced group information!"); 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) await APIRequest(uri: "notifications/count_all_news", needLogin: true)
.exec(); .exec();
final content = response.assertOk().getObject()!; final content = response.assertOk().getObject();
return CountUnreadNotifications( return CountUnreadNotifications(
notifications: content["notifications"], notifications: content["notifications"],

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -46,8 +46,7 @@ class ComunicApplication extends StatefulWidget {
const ComunicApplication({ const ComunicApplication({
Key? key, Key? key,
required this.preferences, required this.preferences,
}) : assert(preferences != null), }) : super(key: key);
super(key: key);
@override @override
ComunicApplicationState createState() => ComunicApplicationState(); ComunicApplicationState createState() => ComunicApplicationState();

View File

@ -1,5 +1,3 @@
/// Account image settings /// Account image settings
/// ///
/// @author Pierre Hubert /// @author Pierre Hubert
@ -15,7 +13,5 @@ class AccountImageSettings {
required this.hasImage, required this.hasImage,
required this.imageURL, required this.imageURL,
required this.visibility, required this.visibility,
}) : assert(hasImage != null), });
assert(imageURL != null),
assert(visibility != null);
} }

View File

@ -38,15 +38,7 @@ class AdvancedUserInfo extends User implements LikeElement {
required this.location, required this.location,
required this.userLike, required this.userLike,
required this.likes, required this.likes,
}) : assert(publicNote != null), }) : super(
assert(canPostTexts != null),
assert(isFriendsListPublic != null),
assert(numberFriends != null),
assert(accountCreationTime != null),
assert(personalWebsite != null),
assert(userLike != null),
assert(likes != null),
super(
id: id, id: id,
firstName: firstName, firstName: firstName,
lastName: lastName, lastName: lastName,

View File

@ -13,7 +13,5 @@ class ApplicationPreferences {
required this.enableDarkMode, required this.enableDarkMode,
required this.forceMobileMode, required this.forceMobileMode,
required this.showPerformancesOverlay, required this.showPerformancesOverlay,
}) : assert(enableDarkMode != null), }) ;
assert(forceMobileMode != null),
assert(showPerformancesOverlay != null);
} }

View File

@ -8,7 +8,5 @@ class AuthenticationDetails {
final String email; final String email;
final String password; final String password;
const AuthenticationDetails({required this.email, required this.password}) const AuthenticationDetails({required this.email, required this.password});
: assert(email != null),
assert(password != null);
} }

View File

@ -7,7 +7,7 @@ import 'package:comunic/helpers/database/database_contract.dart';
abstract class CacheModel { abstract class CacheModel {
final int id; final int id;
const CacheModel({required this.id}) : assert(id != null); const CacheModel({required this.id});
/// Initialize a CacheModel from a map /// Initialize a CacheModel from a map
CacheModel.fromMap(Map<String, dynamic> map) CacheModel.fromMap(Map<String, dynamic> map)

View File

@ -14,8 +14,7 @@ class CallMember {
CallMember({ CallMember({
required this.userID, required this.userID,
this.status = MemberStatus.JOINED, this.status = MemberStatus.JOINED,
}) : assert(userID != null), });
assert(status != null);
bool get hasVideoStream => bool get hasVideoStream =>
stream != null && stream!.getVideoTracks().length > 0; stream != null && stream!.getVideoTracks().length > 0;

View File

@ -28,16 +28,9 @@ class Comment implements LikeElement {
required this.imageURL, required this.imageURL,
required this.likes, required this.likes,
required this.userLike, required this.userLike,
}) : assert(id != null), });
assert(userID != null),
assert(postID != null),
assert(timeSent != null),
assert(content != null),
assert(likes != null),
assert(userLike != null);
bool get hasContent => bool get hasContent => !content.isNull && content.length > 0;
content != null && !content.isNull && content.length > 0;
bool get hasImage => imageURL != null; bool get hasImage => imageURL != null;

View File

@ -47,12 +47,7 @@ class Config {
this.toursEntriesBuilder, this.toursEntriesBuilder,
this.additionalLoading, this.additionalLoading,
this.mainRouteBuilder, this.mainRouteBuilder,
}) : assert(apiServerName != null), });
assert(apiServerUri != null),
assert(apiServerSecure != null),
assert(clientName != null),
assert(splashBackgroundColor != null),
assert(appName != null);
/// Get and set static configuration /// Get and set static configuration
static Config? _config; static Config? _config;

View File

@ -37,13 +37,7 @@ class Conversation extends SerializableElement<Conversation> {
/*required*/ required bool this.canEveryoneAddMembers, /*required*/ required bool this.canEveryoneAddMembers,
this.callCapabilities = CallCapabilities.NONE, this.callCapabilities = CallCapabilities.NONE,
this.isHavingCall = false, this.isHavingCall = false,
}) : assert(id != null), }) : assert((groupID == null) == (groupMinMembershipLevel == null));
assert(lastActivity != null),
assert(members != null),
assert(canEveryoneAddMembers != null),
assert((groupID == null) == (groupMinMembershipLevel == null)),
assert(callCapabilities != null),
assert(isHavingCall != null);
/// Check out whether a conversation has a fixed name or not /// Check out whether a conversation has a fixed name or not
bool get hasName => this.name != null; bool get hasName => this.name != null;

View File

@ -1,5 +1,3 @@
/// Conversation member /// Conversation member
/// ///
/// @author Pierre Hubert /// @author Pierre Hubert
@ -12,16 +10,12 @@ class ConversationMember {
final bool isAdmin; final bool isAdmin;
const ConversationMember({ const ConversationMember({
/*required*/ required this.userID, required this.userID,
/*required*/ required this.lastMessageSeen, required this.lastMessageSeen,
/*required*/ required this.lastAccessTime, required this.lastAccessTime,
/*required*/ required this.following, required this.following,
/*required*/ required this.isAdmin, required this.isAdmin,
}) : assert(userID != null), });
assert(lastMessageSeen != null),
assert(lastAccessTime != null),
assert(following != null),
assert(isAdmin != null);
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {
'userID': userID, 'userID': userID,

View File

@ -42,10 +42,7 @@ class ConversationMessageFile {
required String this.name, required String this.name,
required this.thumbnail, required this.thumbnail,
required String this.type, required String this.type,
}) : assert(url != null), });
assert(size != null),
assert(name != null),
assert(type != null);
/// Get the type of file /// Get the type of file
ConversationMessageFileType? get fileType { ConversationMessageFileType? get fileType {
@ -140,8 +137,6 @@ class ConversationServerMessage {
..add(userWhoRemoved) ..add(userWhoRemoved)
..add(userRemoved); ..add(userRemoved);
} }
throw Exception("Unsupported server message type!");
} }
String? getText(UsersList? list) { String? getText(UsersList? list) {
@ -167,8 +162,6 @@ class ConversationServerMessage {
"2": list.getUser(userRemoved).fullName, "2": list.getUser(userRemoved).fullName,
}); });
} }
throw Exception("Unsupported message type!");
} }
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {

View File

@ -17,8 +17,6 @@ class NewConversation {
required this.follow, required this.follow,
required this.canEveryoneAddMembers, required this.canEveryoneAddMembers,
required this.color, required this.color,
}) : assert(members != null), }) :
assert(members.length > 0), assert(members.length > 0);
assert(follow != null),
assert(canEveryoneAddMembers != null);
} }

View File

@ -12,28 +12,22 @@ import 'package:comunic/utils/ui_utils.dart';
class User implements SerializableElement<User> { class User implements SerializableElement<User> {
final int id; final int id;
final String? firstName; final String firstName;
final String? lastName; final String lastName;
final UserPageVisibility pageVisibility; final UserPageVisibility pageVisibility;
final String? virtualDirectory; final String? virtualDirectory;
final String? accountImageURL; final String accountImageURL;
final CustomEmojiesList customEmojies; final CustomEmojiesList customEmojies;
const User({ const User({
required int this.id, required this.id,
required String this.firstName, required this.firstName,
required String this.lastName, required this.lastName,
required this.pageVisibility, required this.pageVisibility,
required this.virtualDirectory, required this.virtualDirectory,
required String this.accountImageURL, required this.accountImageURL,
required this.customEmojies, required this.customEmojies,
}) : assert(id != null), }) : assert(id > 0);
assert(id > 0),
assert(firstName != null),
assert(lastName != null),
assert(pageVisibility != null),
assert(accountImageURL != null),
assert(customEmojies != null);
/// Get user full name /// Get user full name
String get fullName => firstName! + " " + lastName!; String get fullName => firstName! + " " + lastName!;
@ -68,5 +62,5 @@ class User implements SerializableElement<User> {
jsonDecode(map["customEmojies"])); jsonDecode(map["customEmojies"]));
@override @override
int compareTo(User other) => id!.compareTo(other.id!); int compareTo(User other) => id.compareTo(other.id);
} }