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

Start to fix null safety migration errors

This commit is contained in:
2022-03-10 19:39:57 +01:00
parent ab2c5da0da
commit 3a997cdc56
258 changed files with 2879 additions and 2912 deletions

View File

@ -16,4 +16,7 @@ class AbstractList<E> extends ListBase<E> {
@override
void operator []=(int index, E value) => _list[index] = value;
@override
void add(E element) => _list.add(element);
}

View File

@ -11,7 +11,7 @@ class BaseSet<T> extends SetBase<T> {
bool add(T value) => _set.add(value);
@override
bool contains(Object element) => _set.contains(element);
bool contains(Object? element) => _set.contains(element);
@override
Iterator<T> get iterator => _set.iterator;
@ -20,10 +20,10 @@ class BaseSet<T> extends SetBase<T> {
int get length => _set.length;
@override
T lookup(Object element) => _set.lookup(element);
T? lookup(Object? element) => _set.lookup(element);
@override
bool remove(Object value) => _set.remove(value);
bool remove(Object? value) => _set.remove(value);
@override
Set<T> toSet() => _set.toSet();

View File

@ -10,10 +10,10 @@ class CallMembersList extends AbstractList<CallMember> {
Set<int> get usersID => this.map((f) => f.userID).toSet();
/// Remove a specific member from this list
void removeUser(int userID) => this.removeWhere((f) => f.userID == userID);
void removeUser(int? userID) => this.removeWhere((f) => f.userID == userID);
/// Get the connection of a specific user
CallMember getUser(int userID) => this.firstWhere((f) => f.userID == userID);
CallMember getUser(int? userID) => this.firstWhere((f) => f.userID == userID);
/// Extract ready peers from this list
CallMembersList get readyPeers =>

View File

@ -1,31 +1,14 @@
import 'dart:collection';
import 'package:comunic/lists/abstract_list.dart';
import 'package:comunic/models/conversation_message.dart';
/// Conversations messages list
///
/// @author Pierre HUBERT
class ConversationMessagesList extends ListBase<ConversationMessage> {
final List<ConversationMessage> _list = [];
set length(int v) => _list.length = v;
int get length => _list.length;
@override
ConversationMessage operator [](int index) {
return _list[index];
}
@override
void operator []=(int index, ConversationMessage value) {
_list[index] = value;
}
class ConversationMessagesList extends AbstractList<ConversationMessage> {
/// Get the list of the users ID who own a message in this list
Set<int> getUsersID() {
final Set<int> users = Set();
Set<int?> getUsersID() {
final Set<int?> users = Set();
for (ConversationMessage message in this) users.addAll(message.usersID);
@ -33,18 +16,18 @@ class ConversationMessagesList extends ListBase<ConversationMessage> {
}
/// Get the ID of the last message present in this list
int get lastMessageID {
int lastMessageID = 0;
int? get lastMessageID {
int? lastMessageID = 0;
for (ConversationMessage message in this)
if (message.id > lastMessageID) lastMessageID = message.id;
if (message.id! > lastMessageID!) lastMessageID = message.id;
return lastMessageID;
}
/// Get the ID of the first message present in this list
int get firstMessageID {
int firstMessageID = this[0].id;
int? get firstMessageID {
int? firstMessageID = this[0].id;
for (ConversationMessage message in this)
if (message.id < firstMessageID) firstMessageID = message.id;
if (message.id! < firstMessageID!) firstMessageID = message.id;
return firstMessageID;
}
@ -55,5 +38,5 @@ class ConversationMessagesList extends ListBase<ConversationMessage> {
}
/// Remove a message from this list
void removeMsg(int id) => removeWhere((f) => f.id == id);
void removeMsg(int? id) => removeWhere((f) => f.id == id);
}

View File

@ -22,12 +22,15 @@ class ConversationsList extends ListBase<Conversation> {
/// Get the entire lists of users ID in this list
Set<int> get allUsersID {
final Set<int> list = Set();
forEach((c) => c.members.forEach((member) => list.add(member.userID)));
forEach((c) => c.members!.forEach((member) => list.add(member.userID)));
return list;
}
/// Get the entire lists of groups ID in this list
Set<int> get allGroupsID => where((element) => element.isGroupConversation)
Set<int?> get allGroupsID => where((element) => element.isGroupConversation)
.map((e) => e.groupID)
.toSet();
@override
void add(Conversation element) => _list.add(element);
}

View File

@ -7,8 +7,7 @@ import 'package:comunic/models/custom_emoji.dart';
class CustomEmojiesList extends AbstractList<CustomEmoji> {
/// Check if an emoji, identified by its shortcut, is present in this list
bool hasShortcut(String shortcut) =>
firstWhere((f) => f.shortcut == shortcut, orElse: () => null) != null;
bool hasShortcut(String shortcut) => any((f) => f.shortcut == shortcut);
/// Serialize this list
List<Map<String, dynamic>> toSerializableList() =>

View File

@ -7,7 +7,7 @@ import 'package:comunic/models/forez_presence.dart';
class PresenceSet extends BaseSet<Presence> {
/// Get the presence of a specific user
PresenceSet getForUser(int userID) =>
PresenceSet getForUser(int? userID) =>
PresenceSet()..addAll(where((element) => element.userID == userID));
bool containsDate(DateTime dt) => any(
@ -24,11 +24,11 @@ class PresenceSet extends BaseSet<Presence> {
element.day == dt.day,
);
void toggleDate(DateTime dt, int userID) {
void toggleDate(DateTime dt, int? userID) {
if (containsDate(dt))
removeDate(dt);
else
add(Presence.fromDateTime(dt, userID));
add(Presence.fromDateTime(dt, userID!));
}
int countAtDate(DateTime dt) => where(

View File

@ -6,23 +6,23 @@ import 'package:comunic/models/group.dart';
///
/// @author Pierre HUBERT
class GroupsList extends MapBase<int, Group> {
final Map<int, Group> _groups = Map();
class GroupsList extends MapBase<int?, Group> {
final Map<int?, Group?> _groups = Map();
@override
Group operator [](Object key) => _groups[key];
Group? operator [](Object? key) => _groups[key];
@override
void operator []=(int key, Group value) => _groups[key] = value;
void operator []=(int? key, Group? value) => _groups[key] = value;
@override
void clear() => _groups.clear();
@override
Iterable<int> get keys => _groups.keys;
Iterable<int?> get keys => _groups.keys;
@override
Group remove(Object key) => _groups.remove(key);
Group? remove(Object? key) => _groups.remove(key);
Group getGroup(int id) => this[id];
Group? getGroup(int? id) => this[id];
}

View File

@ -5,20 +5,20 @@ import 'package:comunic/models/membership.dart';
///
/// @author Pierre Hubert
class MembershipList extends AbstractList<Membership> {
class MembershipList extends AbstractList<Membership?> {
/// Get the IDs of all the users included in some way in this list
Set<int> get usersId {
final s = Set<int>();
Set<int?> get usersId {
final s = Set<int?>();
forEach((m) {
switch (m.type) {
switch (m!.type) {
case MembershipType.FRIEND:
s.add(m.friend.id);
s.add(m.friend!.id);
break;
case MembershipType.GROUP:
break;
case MembershipType.CONVERSATION:
s.addAll(m.conversation.membersID);
s.addAll(m.conversation!.membersID);
break;
}
});
@ -27,16 +27,16 @@ class MembershipList extends AbstractList<Membership> {
}
/// Get the ID of the groups included in this list
Set<int> get groupsId => where((f) => f.type == MembershipType.GROUP)
.map((f) => f.groupID)
Set<int?> get groupsId => where((f) => f!.type == MembershipType.GROUP)
.map((f) => f!.groupID)
.toSet();
/// Remove a friend membership from the list
void removeFriend(int friendID) => remove(firstWhere(
(f) => f.type == MembershipType.FRIEND && f.friend.id == friendID));
(f) => f!.type == MembershipType.FRIEND && f.friend!.id == friendID));
/// Get the list of conversations of a group
Set<Membership> getGroupConversations(int groupID) => where((element) =>
element.type == MembershipType.CONVERSATION &&
element.conversation.groupID == groupID).toSet();
Set<Membership?> getGroupConversations(int groupID) => where((element) =>
element!.type == MembershipType.CONVERSATION &&
element.conversation!.groupID == groupID).toSet();
}

View File

@ -8,8 +8,8 @@ import 'package:comunic/models/notification.dart';
class NotificationsList extends AbstractList<Notification> {
/// Get the ID of all the users related to the notifications
/// included in the list
Set<int> get usersIds {
final list = Set<int>();
Set<int?> get usersIds {
final list = Set<int?>();
forEach((n) {
list.add(n.fromUser);
@ -28,8 +28,8 @@ class NotificationsList extends AbstractList<Notification> {
/// Get the ID of all the groups related to the notifications
/// included in the list
Set<int> get groupsIds {
final list = Set<int>();
Set<int?> get groupsIds {
final list = Set<int?>();
forEach((n) {
if (n.onElemType == NotificationElementType.GROUP_PAGE)

View File

@ -22,23 +22,23 @@ class PostsList extends ListBase<Post> {
void operator []=(int index, Post value) => _list[index] = value;
// Get the list of users ID in this set
Set<int> get usersID {
Set<int> set = Set();
Set<int?> get usersID {
Set<int?> set = Set();
forEach((p) {
set.add(p.userID);
if (p.userPageID != null && p.userPageID > 0) set.add(p.userPageID);
if (p.userPageID != null && p.userPageID! > 0) set.add(p.userPageID);
if (p.comments != null) set.addAll(p.comments.usersID);
if (p.comments != null) set.addAll(p.comments!.usersID);
});
return set;
}
/// Get the list of groups in this list of posts
Set<int> get groupsID {
Set<int> set = Set();
Set<int?> get groupsID {
Set<int?> set = Set();
forEach((p) {
if (p.isGroupPost) set.add(p.groupID);

View File

@ -7,8 +7,8 @@ import 'package:comunic/models/unread_conversation.dart';
class UnreadConversationsList extends AbstractList<UnreadConversation> {
/// Get the ID of the users included in this list
Set<int> get usersID {
final set = Set<int>();
Set<int?> get usersID {
final set = Set<int?>();
forEach((element) {
set.addAll(element.conv.membersID);
set.addAll(element.message.usersID);
@ -17,8 +17,8 @@ class UnreadConversationsList extends AbstractList<UnreadConversation> {
}
/// Get the ID of the groups references ind this list
Set<int> get groupsID {
final set = Set<int>();
Set<int?> get groupsID {
final set = Set<int?>();
forEach((element) {
if (element.conv.isGroupConversation) set.add(element.conv.groupID);
});

View File

@ -24,7 +24,7 @@ class UsersList extends ListBase<User> {
}
/// Find a user with a specific ID
User getUser(int userID) {
User getUser(int? userID) {
for (int i = 0; i < this.length; i++)
if (this[i].id == userID) return this[i];
@ -32,8 +32,11 @@ class UsersList extends ListBase<User> {
}
/// Check if the user is included in this list or not
bool hasUser(int userID) => any((f) => f.id == userID);
bool hasUser(int? userID) => any((f) => f.id == userID);
/// Get the list of users ID present in this list
List<int> get usersID => List.generate(length, (i) => this[i].id);
List<int?> get usersID => List.generate(length, (i) => this[i].id);
@override
void add(User element) => _list.add(element);
}