1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-12-25 04:18:51 +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 {
static Future<void> setId(int groupID) async {
(await PreferencesHelper.getInstance())!
(await PreferencesHelper.getInstance())
.setInt(PreferencesKeyList.FOREZ_GROUP, groupID);
}
static Future<int?> getId() async {
return (await PreferencesHelper.getInstance())!
return (await PreferencesHelper.getInstance())
.getInt(PreferencesKeyList.FOREZ_GROUP);
}

View File

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

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 {

View File

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

View File

@ -1,5 +1,3 @@
/// Account image settings
///
/// @author Pierre Hubert
@ -15,7 +13,5 @@ class AccountImageSettings {
required this.hasImage,
required this.imageURL,
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.userLike,
required this.likes,
}) : assert(publicNote != null),
assert(canPostTexts != null),
assert(isFriendsListPublic != null),
assert(numberFriends != null),
assert(accountCreationTime != null),
assert(personalWebsite != null),
assert(userLike != null),
assert(likes != null),
super(
}) : super(
id: id,
firstName: firstName,
lastName: lastName,

View File

@ -13,7 +13,5 @@ class ApplicationPreferences {
required this.enableDarkMode,
required this.forceMobileMode,
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 password;
const AuthenticationDetails({required this.email, required this.password})
: assert(email != null),
assert(password != null);
const AuthenticationDetails({required this.email, required this.password});
}

View File

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

View File

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

View File

@ -28,16 +28,9 @@ class Comment implements LikeElement {
required this.imageURL,
required this.likes,
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 =>
content != null && !content.isNull && content.length > 0;
bool get hasContent => !content.isNull && content.length > 0;
bool get hasImage => imageURL != null;

View File

@ -47,12 +47,7 @@ class Config {
this.toursEntriesBuilder,
this.additionalLoading,
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
static Config? _config;

View File

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

View File

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

View File

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

View File

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

View File

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