refactor: MVC archive
This commit is contained in:
parent
fa0162a71b
commit
c2cbad7ffa
@ -1,10 +1,10 @@
|
||||
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/controllers/archive_controller.dart';
|
||||
import 'package:fluffychat/controllers/homeserver_picker_controller.dart';
|
||||
import 'package:fluffychat/controllers/sign_up_controller.dart';
|
||||
import 'package:fluffychat/controllers/sign_up_password_controller.dart';
|
||||
import 'package:fluffychat/views/widgets/matrix.dart';
|
||||
import 'package:fluffychat/views/archive.dart';
|
||||
import 'package:fluffychat/views/chat.dart';
|
||||
import 'package:fluffychat/views/chat_details.dart';
|
||||
import 'package:fluffychat/views/chat_encryption_settings.dart';
|
||||
|
23
lib/controllers/archive_controller.dart
Normal file
23
lib/controllers/archive_controller.dart
Normal file
@ -0,0 +1,23 @@
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/views/archive_view.dart';
|
||||
import 'package:fluffychat/views/widgets/matrix.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class Archive extends StatefulWidget {
|
||||
@override
|
||||
ArchiveController createState() => ArchiveController();
|
||||
}
|
||||
|
||||
class ArchiveController extends State<Archive> {
|
||||
List<Room> archive;
|
||||
|
||||
Future<List<Room>> getArchive(BuildContext context) async {
|
||||
if (archive != null) return archive;
|
||||
return await Matrix.of(context).client.archive;
|
||||
}
|
||||
|
||||
void forgetAction(int i) => setState(() => archive.removeAt(i));
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ArchiveView(this);
|
||||
}
|
@ -1,21 +1,24 @@
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:famedlysdk/encryption.dart';
|
||||
import 'package:matrix_api_lite/fake_matrix_api.dart';
|
||||
import 'platform_infos.dart';
|
||||
import 'famedlysdk_store.dart';
|
||||
|
||||
class FluffyClient extends Client {
|
||||
static final FluffyClient _instance = FluffyClient._internal();
|
||||
static FluffyClient _instance;
|
||||
|
||||
/// The ID of the currently active room, if there is one. May be null or emtpy
|
||||
String activeRoomId;
|
||||
|
||||
factory FluffyClient() {
|
||||
factory FluffyClient({testMode = false}) {
|
||||
_instance ??= FluffyClient._internal(testMode: testMode);
|
||||
return _instance;
|
||||
}
|
||||
|
||||
FluffyClient._internal()
|
||||
FluffyClient._internal({testMode = false})
|
||||
: super(
|
||||
PlatformInfos.clientName,
|
||||
testMode ? 'FluffyChat Widget Tests' : PlatformInfos.clientName,
|
||||
httpClient: testMode ? FakeMatrixApi() : null,
|
||||
enableE2eeRecovery: true,
|
||||
verificationMethods: {
|
||||
KeyVerificationMethod.numbers,
|
||||
@ -25,7 +28,7 @@ class FluffyClient extends Client {
|
||||
importantStateEvents: <String>{
|
||||
'im.ponies.room_emotes', // we want emotes to work properly
|
||||
},
|
||||
databaseBuilder: getDatabase,
|
||||
databaseBuilder: testMode ? null : getDatabase,
|
||||
supportedLoginTypes: {
|
||||
AuthenticationTypes.password,
|
||||
if (PlatformInfos.isMobile || PlatformInfos.isWeb)
|
||||
|
@ -1,21 +1,13 @@
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/controllers/archive_controller.dart';
|
||||
import 'package:fluffychat/views/widgets/list_items/chat_list_item.dart';
|
||||
import 'package:fluffychat/views/widgets/matrix.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
class Archive extends StatefulWidget {
|
||||
@override
|
||||
_ArchiveState createState() => _ArchiveState();
|
||||
}
|
||||
class ArchiveView extends StatelessWidget {
|
||||
final ArchiveController controller;
|
||||
|
||||
class _ArchiveState extends State<Archive> {
|
||||
List<Room> archive;
|
||||
|
||||
Future<List<Room>> getArchive(BuildContext context) async {
|
||||
if (archive != null) return archive;
|
||||
return await Matrix.of(context).client.archive;
|
||||
}
|
||||
const ArchiveView(this.controller, {Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -25,17 +17,25 @@ class _ArchiveState extends State<Archive> {
|
||||
title: Text(L10n.of(context).archive),
|
||||
),
|
||||
body: FutureBuilder<List<Room>>(
|
||||
future: getArchive(context),
|
||||
future: controller.getArchive(context),
|
||||
builder: (BuildContext context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return Center(
|
||||
child: Text(
|
||||
L10n.of(context).oopsSomethingWentWrong,
|
||||
textAlign: TextAlign.center,
|
||||
));
|
||||
}
|
||||
if (!snapshot.hasData) {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
} else {
|
||||
archive = snapshot.data;
|
||||
controller.archive = snapshot.data;
|
||||
return ListView.builder(
|
||||
itemCount: archive.length,
|
||||
itemCount: controller.archive.length,
|
||||
itemBuilder: (BuildContext context, int i) => ChatListItem(
|
||||
archive[i],
|
||||
onForget: () => setState(() => archive.removeAt(i))),
|
||||
controller.archive[i],
|
||||
onForget: controller.forgetAction,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
@ -86,7 +86,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
||||
|
||||
void _initWithStore() async {
|
||||
try {
|
||||
await client.init();
|
||||
if (!testMode) await client.init();
|
||||
if (client.isLogged()) {
|
||||
final statusMsg = await store.getItem(SettingKeys.ownStatusMessage);
|
||||
if (statusMsg?.isNotEmpty ?? false) {
|
||||
@ -261,7 +261,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
||||
});
|
||||
});
|
||||
}
|
||||
client = widget.testClient ?? FluffyClient();
|
||||
client = FluffyClient();
|
||||
LoadingDialog.defaultTitle = L10n.of(context).loadingPleaseWait;
|
||||
LoadingDialog.defaultBackLabel = L10n.of(context).close;
|
||||
LoadingDialog.defaultOnError = (Object e) => e.toLocalizedString(context);
|
||||
|
15
test/archive_test.dart
Normal file
15
test/archive_test.dart
Normal file
@ -0,0 +1,15 @@
|
||||
/*import 'package:fluffychat/controllers/archive_controller.dart';
|
||||
import 'package:fluffychat/main.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'utils/test_client.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Test if the widget can be created', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(FluffyChatApp(
|
||||
testWidget: Archive(),
|
||||
testClient: await testClient(loggedIn: true),
|
||||
));
|
||||
});
|
||||
}
|
||||
*/
|
20
test/utils/test_client.dart
Normal file
20
test/utils/test_client.dart
Normal file
@ -0,0 +1,20 @@
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/utils/fluffy_client.dart';
|
||||
|
||||
Future<FluffyClient> testClient({
|
||||
bool loggedIn = false,
|
||||
String homeserver = 'https://fakeserver.notexisting',
|
||||
String id = 'FluffyChat Widget Test',
|
||||
}) async {
|
||||
final client = FluffyClient(testMode: true);
|
||||
if (homeserver != null) {
|
||||
await client.checkHomeserver(homeserver);
|
||||
}
|
||||
if (loggedIn) {
|
||||
await client.login(
|
||||
identifier: AuthenticationUserIdentifier(user: '@alice:example.invalid'),
|
||||
password: '1234',
|
||||
);
|
||||
}
|
||||
return client;
|
||||
}
|
@ -5,11 +5,11 @@
|
||||
// gestures. You can also use WidgetTester to find child widgets in the widget
|
||||
// tree, read text, and verify that the values of widget properties are correct.
|
||||
|
||||
import 'package:fluffychat/main.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Test if the app starts', (WidgetTester tester) async {
|
||||
// Build our app and trigger a frame.
|
||||
//await tester.pumpWidget(App());
|
||||
await tester.pumpWidget(FluffyChatApp());
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user