refactor: Migrate to null safety
This commit is contained in:
parent
5269f04a99
commit
55f0300f9f
163 changed files with 1759 additions and 1903 deletions
|
|
@ -13,7 +13,7 @@ import 'package:fluffychat/widgets/matrix.dart';
|
|||
import 'package:fluffychat/widgets/permission_slider_dialog.dart';
|
||||
|
||||
class ChatPermissionsSettings extends StatefulWidget {
|
||||
const ChatPermissionsSettings({Key key}) : super(key: key);
|
||||
const ChatPermissionsSettings({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
ChatPermissionsSettingsController createState() =>
|
||||
|
|
@ -21,13 +21,13 @@ class ChatPermissionsSettings extends StatefulWidget {
|
|||
}
|
||||
|
||||
class ChatPermissionsSettingsController extends State<ChatPermissionsSettings> {
|
||||
String get roomId => VRouter.of(context).pathParameters['roomid'];
|
||||
String? get roomId => VRouter.of(context).pathParameters['roomid'];
|
||||
void editPowerLevel(BuildContext context, String key, int currentLevel,
|
||||
{String category}) async {
|
||||
final room = Matrix.of(context).client.getRoomById(roomId);
|
||||
{String? category}) async {
|
||||
final room = Matrix.of(context).client.getRoomById(roomId!)!;
|
||||
if (!room.canSendEvent(EventTypes.RoomPowerLevels)) {
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(SnackBar(content: Text(L10n.of(context).noPermission)));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(L10n.of(context)!.noPermission)));
|
||||
return;
|
||||
}
|
||||
final newLevel =
|
||||
|
|
@ -35,7 +35,7 @@ class ChatPermissionsSettingsController extends State<ChatPermissionsSettings> {
|
|||
.show(context);
|
||||
if (newLevel == null) return;
|
||||
final content = Map<String, dynamic>.from(
|
||||
room.getState(EventTypes.RoomPowerLevels).content);
|
||||
room.getState(EventTypes.RoomPowerLevels)!.content);
|
||||
if (category != null) {
|
||||
if (!content.containsKey(category)) {
|
||||
content[category] = <String, dynamic>{};
|
||||
|
|
@ -58,20 +58,20 @@ class ChatPermissionsSettingsController extends State<ChatPermissionsSettings> {
|
|||
|
||||
Stream get onChanged => Matrix.of(context).client.onSync.stream.where(
|
||||
(e) =>
|
||||
(e?.rooms?.join?.containsKey(roomId) ?? false) &&
|
||||
(e.rooms.join[roomId]?.timeline?.events
|
||||
(e.rooms?.join?.containsKey(roomId) ?? false) &&
|
||||
(e.rooms!.join![roomId!]?.timeline?.events
|
||||
?.any((s) => s.type == EventTypes.RoomPowerLevels) ??
|
||||
false),
|
||||
);
|
||||
|
||||
void updateRoomAction(Capabilities capabilities) async {
|
||||
final room = Matrix.of(context).client.getRoomById(roomId);
|
||||
final room = Matrix.of(context).client.getRoomById(roomId!)!;
|
||||
final String roomVersion =
|
||||
room.getState(EventTypes.RoomCreate).content['room_version'] ?? '1';
|
||||
room.getState(EventTypes.RoomCreate)!.content['room_version'] ?? '1';
|
||||
final newVersion = await showConfirmationDialog<String>(
|
||||
context: context,
|
||||
title: L10n.of(context).replaceRoomWithNewerVersion,
|
||||
actions: capabilities.mRoomVersions.available.entries
|
||||
title: L10n.of(context)!.replaceRoomWithNewerVersion,
|
||||
actions: capabilities.mRoomVersions!.available.entries
|
||||
.where((r) => r.key != roomVersion)
|
||||
.map((version) => AlertDialogAction(
|
||||
key: version.key,
|
||||
|
|
@ -84,15 +84,15 @@ class ChatPermissionsSettingsController extends State<ChatPermissionsSettings> {
|
|||
await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
okLabel: L10n.of(context).yes,
|
||||
cancelLabel: L10n.of(context).cancel,
|
||||
title: L10n.of(context).areYouSure,
|
||||
okLabel: L10n.of(context)!.yes,
|
||||
cancelLabel: L10n.of(context)!.cancel,
|
||||
title: L10n.of(context)!.areYouSure,
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => room.client.upgradeRoom(roomId, newVersion),
|
||||
future: () => room.client.upgradeRoom(roomId!, newVersion),
|
||||
).then((_) => VRouter.of(context).pop());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import 'package:fluffychat/widgets/matrix.dart';
|
|||
class ChatPermissionsSettingsView extends StatelessWidget {
|
||||
final ChatPermissionsSettingsController controller;
|
||||
|
||||
const ChatPermissionsSettingsView(this.controller, {Key key})
|
||||
const ChatPermissionsSettingsView(this.controller, {Key? key})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
|
|
@ -24,19 +24,24 @@ class ChatPermissionsSettingsView extends StatelessWidget {
|
|||
: IconButton(
|
||||
icon: const Icon(Icons.close_outlined),
|
||||
onPressed: () => VRouter.of(context)
|
||||
.toSegments(['rooms', controller.roomId]),
|
||||
.toSegments(['rooms', controller.roomId!]),
|
||||
),
|
||||
title: Text(L10n.of(context).editChatPermissions),
|
||||
title: Text(L10n.of(context)!.editChatPermissions),
|
||||
),
|
||||
body: MaxWidthBody(
|
||||
withScrolling: true,
|
||||
child: StreamBuilder(
|
||||
stream: controller.onChanged,
|
||||
builder: (context, _) {
|
||||
final room =
|
||||
Matrix.of(context).client.getRoomById(controller.roomId);
|
||||
final roomId = controller.roomId;
|
||||
final room = roomId == null
|
||||
? null
|
||||
: Matrix.of(context).client.getRoomById(roomId);
|
||||
if (room == null) {
|
||||
return Center(child: Text(L10n.of(context)!.noRoomsFound));
|
||||
}
|
||||
final powerLevelsContent = Map<String, dynamic>.from(
|
||||
room.getState(EventTypes.RoomPowerLevels).content);
|
||||
room.getState(EventTypes.RoomPowerLevels)!.content);
|
||||
final powerLevels = Map<String, dynamic>.from(powerLevelsContent)
|
||||
..removeWhere((k, v) => v is! int);
|
||||
final eventsPowerLevels =
|
||||
|
|
@ -57,7 +62,7 @@ class ChatPermissionsSettingsView extends StatelessWidget {
|
|||
const Divider(thickness: 1),
|
||||
ListTile(
|
||||
title: Text(
|
||||
L10n.of(context).notifications,
|
||||
L10n.of(context)!.notifications,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).primaryColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
|
|
@ -82,23 +87,22 @@ class ChatPermissionsSettingsView extends StatelessWidget {
|
|||
const Divider(thickness: 1),
|
||||
ListTile(
|
||||
title: Text(
|
||||
L10n.of(context).configureChat,
|
||||
L10n.of(context)!.configureChat,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).primaryColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (eventsPowerLevels != null)
|
||||
for (var entry in eventsPowerLevels.entries)
|
||||
PermissionsListTile(
|
||||
permissionKey: entry.key,
|
||||
category: 'events',
|
||||
permission: entry.value,
|
||||
onTap: () => controller.editPowerLevel(
|
||||
context, entry.key, entry.value,
|
||||
category: 'events'),
|
||||
),
|
||||
for (var entry in eventsPowerLevels.entries)
|
||||
PermissionsListTile(
|
||||
permissionKey: entry.key,
|
||||
category: 'events',
|
||||
permission: entry.value,
|
||||
onTap: () => controller.editPowerLevel(
|
||||
context, entry.key, entry.value,
|
||||
category: 'events'),
|
||||
),
|
||||
if (room.canSendEvent(EventTypes.RoomTombstone)) ...{
|
||||
const Divider(thickness: 1),
|
||||
FutureBuilder<Capabilities>(
|
||||
|
|
@ -110,15 +114,15 @@ class ChatPermissionsSettingsView extends StatelessWidget {
|
|||
strokeWidth: 2));
|
||||
}
|
||||
final String roomVersion = room
|
||||
.getState(EventTypes.RoomCreate)
|
||||
.getState(EventTypes.RoomCreate)!
|
||||
.content['room_version'] ??
|
||||
'1';
|
||||
|
||||
return ListTile(
|
||||
title: Text(
|
||||
'${L10n.of(context).roomVersion}: $roomVersion'),
|
||||
'${L10n.of(context)!.roomVersion}: $roomVersion'),
|
||||
onTap: () =>
|
||||
controller.updateRoomAction(snapshot.data),
|
||||
controller.updateRoomAction(snapshot.data!),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ import 'package:matrix/matrix.dart';
|
|||
class PermissionsListTile extends StatelessWidget {
|
||||
final String permissionKey;
|
||||
final int permission;
|
||||
final String category;
|
||||
final void Function() onTap;
|
||||
final String? category;
|
||||
final void Function()? onTap;
|
||||
|
||||
const PermissionsListTile({
|
||||
Key key,
|
||||
@required this.permissionKey,
|
||||
@required this.permission,
|
||||
Key? key,
|
||||
required this.permissionKey,
|
||||
required this.permission,
|
||||
this.category,
|
||||
this.onTap,
|
||||
}) : super(key: key);
|
||||
|
|
@ -21,43 +21,43 @@ class PermissionsListTile extends StatelessWidget {
|
|||
if (category == null) {
|
||||
switch (permissionKey) {
|
||||
case 'users_default':
|
||||
return L10n.of(context).defaultPermissionLevel;
|
||||
return L10n.of(context)!.defaultPermissionLevel;
|
||||
case 'events_default':
|
||||
return L10n.of(context).sendMessages;
|
||||
return L10n.of(context)!.sendMessages;
|
||||
case 'state_default':
|
||||
return L10n.of(context).configureChat;
|
||||
return L10n.of(context)!.configureChat;
|
||||
case 'ban':
|
||||
return L10n.of(context).banFromChat;
|
||||
return L10n.of(context)!.banFromChat;
|
||||
case 'kick':
|
||||
return L10n.of(context).kickFromChat;
|
||||
return L10n.of(context)!.kickFromChat;
|
||||
case 'redact':
|
||||
return L10n.of(context).deleteMessage;
|
||||
return L10n.of(context)!.deleteMessage;
|
||||
case 'invite':
|
||||
return L10n.of(context).inviteContact;
|
||||
return L10n.of(context)!.inviteContact;
|
||||
}
|
||||
} else if (category == 'notifications') {
|
||||
switch (permissionKey) {
|
||||
case 'rooms':
|
||||
return L10n.of(context).notifications;
|
||||
return L10n.of(context)!.notifications;
|
||||
}
|
||||
} else if (category == 'events') {
|
||||
switch (permissionKey) {
|
||||
case EventTypes.RoomName:
|
||||
return L10n.of(context).changeTheNameOfTheGroup;
|
||||
return L10n.of(context)!.changeTheNameOfTheGroup;
|
||||
case EventTypes.RoomPowerLevels:
|
||||
return L10n.of(context).editChatPermissions;
|
||||
return L10n.of(context)!.editChatPermissions;
|
||||
case EventTypes.HistoryVisibility:
|
||||
return L10n.of(context).visibilityOfTheChatHistory;
|
||||
return L10n.of(context)!.visibilityOfTheChatHistory;
|
||||
case EventTypes.RoomCanonicalAlias:
|
||||
return L10n.of(context).setInvitationLink;
|
||||
return L10n.of(context)!.setInvitationLink;
|
||||
case EventTypes.RoomAvatar:
|
||||
return L10n.of(context).editRoomAvatar;
|
||||
return L10n.of(context)!.editRoomAvatar;
|
||||
case EventTypes.RoomTombstone:
|
||||
return L10n.of(context).replaceRoomWithNewerVersion;
|
||||
return L10n.of(context)!.replaceRoomWithNewerVersion;
|
||||
case EventTypes.Encryption:
|
||||
return L10n.of(context).enableEncryption;
|
||||
return L10n.of(context)!.enableEncryption;
|
||||
case 'm.room.server_acl':
|
||||
return L10n.of(context).editBlockedServers;
|
||||
return L10n.of(context)!.editBlockedServers;
|
||||
}
|
||||
}
|
||||
return permissionKey;
|
||||
|
|
@ -96,9 +96,9 @@ class PermissionsListTile extends StatelessWidget {
|
|||
extension on int {
|
||||
String toLocalizedPowerLevelString(BuildContext context) {
|
||||
return this == 100
|
||||
? L10n.of(context).admin
|
||||
? L10n.of(context)!.admin
|
||||
: this >= 50
|
||||
? L10n.of(context).moderator
|
||||
: L10n.of(context).participant;
|
||||
? L10n.of(context)!.moderator
|
||||
: L10n.of(context)!.participant;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue