diff --git a/lib/config/routes.dart b/lib/config/routes.dart index ef31c69a..45d2b0dd 100644 --- a/lib/config/routes.dart +++ b/lib/config/routes.dart @@ -215,10 +215,20 @@ class AppRoutes { buildTransition: _dynamicTransition, ), VWidget( - path: 'emotes', + path: 'multiple_emotes', widget: MultipleEmotesSettings(), buildTransition: _dynamicTransition, ), + VWidget( + path: 'emotes', + widget: EmotesSettings(), + buildTransition: _dynamicTransition, + ), + VWidget( + path: 'emotes/:state_key', + widget: EmotesSettings(), + buildTransition: _dynamicTransition, + ), ]; List get _settingsRoutes => [ diff --git a/lib/pages/chat_details.dart b/lib/pages/chat_details.dart index 448ca27c..629324c7 100644 --- a/lib/pages/chat_details.dart +++ b/lib/pages/chat_details.dart @@ -240,9 +240,9 @@ class ChatDetailsController extends State { if ((room.states['im.ponies.room_emotes'] ?? {}) .keys .any((String s) => s.isNotEmpty)) { - VRouter.of(context).pushNamed('/rooms/${room.id}/emotes'); + VRouter.of(context).push('/rooms/${room.id}/details/multiple_emotes'); } else { - VRouter.of(context).pushNamed('/settings/emotes'); + VRouter.of(context).push('/rooms/${room.id}/details/emotes'); } } diff --git a/lib/pages/settings_emotes.dart b/lib/pages/settings_emotes.dart index 7824e262..62152343 100644 --- a/lib/pages/settings_emotes.dart +++ b/lib/pages/settings_emotes.dart @@ -6,6 +6,7 @@ import 'package:fluffychat/utils/platform_infos.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'package:vrouter/vrouter.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart'; import 'package:image_picker/image_picker.dart'; @@ -13,10 +14,7 @@ import 'views/settings_emotes_view.dart'; import '../widgets/matrix.dart'; class EmotesSettings extends StatefulWidget { - final Room room; - final String stateKey; - - EmotesSettings({this.room, this.stateKey}); + EmotesSettings({Key key}) : super(key: key); @override EmotesSettingsController createState() => EmotesSettingsController(); @@ -31,6 +29,11 @@ class EmoteEntry { } class EmotesSettingsController extends State { + String get roomId => VRouter.of(context).pathParameters['roomid']; + Room get room => + roomId != null ? Matrix.of(context).client.getRoomById(roomId) : null; + String get stateKey => VRouter.of(context).pathParameters['state_key']; + List emotes; bool showSave = false; TextEditingController newEmoteController = TextEditingController(); @@ -43,11 +46,10 @@ class EmotesSettingsController extends State { final client = Matrix.of(context).client; // be sure to preserve any data not in "short" Map content; - if (widget.room != null) { - content = widget.room - .getState('im.ponies.room_emotes', widget.stateKey ?? '') - ?.content ?? - {}; + if (room != null) { + content = + room.getState('im.ponies.room_emotes', stateKey ?? '')?.content ?? + {}; } else { content = client.accountData['im.ponies.user_emotes']?.content ?? {}; @@ -74,11 +76,11 @@ class EmotesSettingsController extends State { } // remove the old "short" key content.remove('short'); - if (widget.room != null) { + if (room != null) { await showFutureLoadingDialog( context: context, - future: () => client.setRoomStateWithKey(widget.room.id, - 'im.ponies.room_emotes', content, widget.stateKey ?? ''), + future: () => client.setRoomStateWithKey( + room.id, 'im.ponies.room_emotes', content, stateKey ?? ''), ); } else { await showFutureLoadingDialog( @@ -90,7 +92,7 @@ class EmotesSettingsController extends State { } Future setIsGloballyActive(bool active) async { - if (widget.room == null) { + if (room == null) { return; } final client = Matrix.of(context).client; @@ -100,16 +102,14 @@ class EmotesSettingsController extends State { if (!(content['rooms'] is Map)) { content['rooms'] = {}; } - if (!(content['rooms'][widget.room.id] is Map)) { - content['rooms'][widget.room.id] = {}; + if (!(content['rooms'][room.id] is Map)) { + content['rooms'][room.id] = {}; } - if (!(content['rooms'][widget.room.id][widget.stateKey ?? ''] is Map)) { - content['rooms'][widget.room.id] - [widget.stateKey ?? ''] = {}; + if (!(content['rooms'][room.id][stateKey ?? ''] is Map)) { + content['rooms'][room.id][stateKey ?? ''] = {}; } - } else if (content['rooms'] is Map && - content['rooms'][widget.room.id] is Map) { - content['rooms'][widget.room.id].remove(widget.stateKey ?? ''); + } else if (content['rooms'] is Map && content['rooms'][room.id] is Map) { + content['rooms'][room.id].remove(stateKey ?? ''); } // and save await showFutureLoadingDialog( @@ -159,17 +159,16 @@ class EmotesSettingsController extends State { } bool isGloballyActive(Client client) => - widget.room != null && + room != null && client.accountData['im.ponies.emote_rooms']?.content is Map && client.accountData['im.ponies.emote_rooms'].content['rooms'] is Map && - client.accountData['im.ponies.emote_rooms'].content['rooms'] - [widget.room.id] is Map && - client.accountData['im.ponies.emote_rooms'].content['rooms'] - [widget.room.id][widget.stateKey ?? ''] is Map; + client.accountData['im.ponies.emote_rooms'].content['rooms'][room.id] + is Map && + client.accountData['im.ponies.emote_rooms'].content['rooms'][room.id] + [stateKey ?? ''] is Map; - bool get readonly => widget.room == null - ? false - : !(widget.room.canSendEvent('im.ponies.room_emotes')); + bool get readonly => + room == null ? false : !(room.canSendEvent('im.ponies.room_emotes')); void saveAction() async { await _save(context); @@ -264,10 +263,9 @@ class EmotesSettingsController extends State { if (emotes == null) { emotes = []; Map emoteSource; - if (widget.room != null) { - emoteSource = widget.room - .getState('im.ponies.room_emotes', widget.stateKey ?? '') - ?.content; + if (room != null) { + emoteSource = + room.getState('im.ponies.room_emotes', stateKey ?? '')?.content; } else { emoteSource = Matrix.of(context) .client diff --git a/lib/pages/views/settings_emotes_view.dart b/lib/pages/views/settings_emotes_view.dart index f2650d39..d67fdb8d 100644 --- a/lib/pages/views/settings_emotes_view.dart +++ b/lib/pages/views/settings_emotes_view.dart @@ -28,7 +28,7 @@ class EmotesSettingsView extends StatelessWidget { : null, body: MaxWidthBody( child: StreamBuilder( - stream: controller.widget.room?.onUpdate?.stream, + stream: controller.room?.onUpdate?.stream, builder: (context, snapshot) { return Column( children: [ @@ -81,7 +81,7 @@ class EmotesSettingsView extends StatelessWidget { ), ), ), - if (controller.widget.room != null) + if (controller.room != null) ListTile( title: Text(L10n.of(context).enableEmotesGlobally), trailing: Switch( @@ -89,7 +89,7 @@ class EmotesSettingsView extends StatelessWidget { onChanged: controller.setIsGloballyActive, ), ), - if (!controller.readonly || controller.widget.room != null) + if (!controller.readonly || controller.room != null) Divider( height: 2, thickness: 2, diff --git a/lib/pages/views/settings_multiple_emotes_view.dart b/lib/pages/views/settings_multiple_emotes_view.dart index 17fce177..a14f2c69 100644 --- a/lib/pages/views/settings_multiple_emotes_view.dart +++ b/lib/pages/views/settings_multiple_emotes_view.dart @@ -44,7 +44,8 @@ class MultipleEmotesSettingsView extends StatelessWidget { return ListTile( title: Text(packName), onTap: () async { - VRouter.of(context).push('/settings/emotes'); + VRouter.of(context) + .push('/rooms/${room.id}/details/emotes/${keys[i]}'); }, ); });