mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-12-23 22:12:34 +01:00
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:adaptive_page_layout/adaptive_page_layout.dart';
|
||||||
import 'package:famedlysdk/famedlysdk.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/homeserver_picker_controller.dart';
|
||||||
import 'package:fluffychat/controllers/sign_up_controller.dart';
|
import 'package:fluffychat/controllers/sign_up_controller.dart';
|
||||||
import 'package:fluffychat/controllers/sign_up_password_controller.dart';
|
import 'package:fluffychat/controllers/sign_up_password_controller.dart';
|
||||||
import 'package:fluffychat/views/widgets/matrix.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.dart';
|
||||||
import 'package:fluffychat/views/chat_details.dart';
|
import 'package:fluffychat/views/chat_details.dart';
|
||||||
import 'package:fluffychat/views/chat_encryption_settings.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/famedlysdk.dart';
|
||||||
import 'package:famedlysdk/encryption.dart';
|
import 'package:famedlysdk/encryption.dart';
|
||||||
|
import 'package:matrix_api_lite/fake_matrix_api.dart';
|
||||||
import 'platform_infos.dart';
|
import 'platform_infos.dart';
|
||||||
import 'famedlysdk_store.dart';
|
import 'famedlysdk_store.dart';
|
||||||
|
|
||||||
class FluffyClient extends Client {
|
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
|
/// The ID of the currently active room, if there is one. May be null or emtpy
|
||||||
String activeRoomId;
|
String activeRoomId;
|
||||||
|
|
||||||
factory FluffyClient() {
|
factory FluffyClient({testMode = false}) {
|
||||||
|
_instance ??= FluffyClient._internal(testMode: testMode);
|
||||||
return _instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
FluffyClient._internal()
|
FluffyClient._internal({testMode = false})
|
||||||
: super(
|
: super(
|
||||||
PlatformInfos.clientName,
|
testMode ? 'FluffyChat Widget Tests' : PlatformInfos.clientName,
|
||||||
|
httpClient: testMode ? FakeMatrixApi() : null,
|
||||||
enableE2eeRecovery: true,
|
enableE2eeRecovery: true,
|
||||||
verificationMethods: {
|
verificationMethods: {
|
||||||
KeyVerificationMethod.numbers,
|
KeyVerificationMethod.numbers,
|
||||||
@ -25,7 +28,7 @@ class FluffyClient extends Client {
|
|||||||
importantStateEvents: <String>{
|
importantStateEvents: <String>{
|
||||||
'im.ponies.room_emotes', // we want emotes to work properly
|
'im.ponies.room_emotes', // we want emotes to work properly
|
||||||
},
|
},
|
||||||
databaseBuilder: getDatabase,
|
databaseBuilder: testMode ? null : getDatabase,
|
||||||
supportedLoginTypes: {
|
supportedLoginTypes: {
|
||||||
AuthenticationTypes.password,
|
AuthenticationTypes.password,
|
||||||
if (PlatformInfos.isMobile || PlatformInfos.isWeb)
|
if (PlatformInfos.isMobile || PlatformInfos.isWeb)
|
||||||
|
@ -1,21 +1,13 @@
|
|||||||
import 'package:famedlysdk/famedlysdk.dart';
|
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/list_items/chat_list_item.dart';
|
||||||
import 'package:fluffychat/views/widgets/matrix.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
|
|
||||||
class Archive extends StatefulWidget {
|
class ArchiveView extends StatelessWidget {
|
||||||
@override
|
final ArchiveController controller;
|
||||||
_ArchiveState createState() => _ArchiveState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ArchiveState extends State<Archive> {
|
const ArchiveView(this.controller, {Key key}) : super(key: key);
|
||||||
List<Room> archive;
|
|
||||||
|
|
||||||
Future<List<Room>> getArchive(BuildContext context) async {
|
|
||||||
if (archive != null) return archive;
|
|
||||||
return await Matrix.of(context).client.archive;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -25,17 +17,25 @@ class _ArchiveState extends State<Archive> {
|
|||||||
title: Text(L10n.of(context).archive),
|
title: Text(L10n.of(context).archive),
|
||||||
),
|
),
|
||||||
body: FutureBuilder<List<Room>>(
|
body: FutureBuilder<List<Room>>(
|
||||||
future: getArchive(context),
|
future: controller.getArchive(context),
|
||||||
builder: (BuildContext context, snapshot) {
|
builder: (BuildContext context, snapshot) {
|
||||||
|
if (snapshot.hasError) {
|
||||||
|
return Center(
|
||||||
|
child: Text(
|
||||||
|
L10n.of(context).oopsSomethingWentWrong,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
));
|
||||||
|
}
|
||||||
if (!snapshot.hasData) {
|
if (!snapshot.hasData) {
|
||||||
return Center(child: CircularProgressIndicator());
|
return Center(child: CircularProgressIndicator());
|
||||||
} else {
|
} else {
|
||||||
archive = snapshot.data;
|
controller.archive = snapshot.data;
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
itemCount: archive.length,
|
itemCount: controller.archive.length,
|
||||||
itemBuilder: (BuildContext context, int i) => ChatListItem(
|
itemBuilder: (BuildContext context, int i) => ChatListItem(
|
||||||
archive[i],
|
controller.archive[i],
|
||||||
onForget: () => setState(() => archive.removeAt(i))),
|
onForget: controller.forgetAction,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
@ -86,7 +86,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||||||
|
|
||||||
void _initWithStore() async {
|
void _initWithStore() async {
|
||||||
try {
|
try {
|
||||||
await client.init();
|
if (!testMode) await client.init();
|
||||||
if (client.isLogged()) {
|
if (client.isLogged()) {
|
||||||
final statusMsg = await store.getItem(SettingKeys.ownStatusMessage);
|
final statusMsg = await store.getItem(SettingKeys.ownStatusMessage);
|
||||||
if (statusMsg?.isNotEmpty ?? false) {
|
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.defaultTitle = L10n.of(context).loadingPleaseWait;
|
||||||
LoadingDialog.defaultBackLabel = L10n.of(context).close;
|
LoadingDialog.defaultBackLabel = L10n.of(context).close;
|
||||||
LoadingDialog.defaultOnError = (Object e) => e.toLocalizedString(context);
|
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
|
// 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.
|
// 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';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
testWidgets('Test if the app starts', (WidgetTester tester) async {
|
testWidgets('Test if the app starts', (WidgetTester tester) async {
|
||||||
// Build our app and trigger a frame.
|
await tester.pumpWidget(FluffyChatApp());
|
||||||
//await tester.pumpWidget(App());
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user