loading spaces
This commit is contained in:
parent
dca9ee1939
commit
65028a1231
14 changed files with 629 additions and 86 deletions
|
|
@ -1,33 +1,31 @@
|
|||
// import "dart:io";
|
||||
import "dart:io";
|
||||
|
||||
// import "package:matrix/matrix.dart";
|
||||
// import "package:nexusbot/controllers/settings_controller.dart";
|
||||
// import "package:riverpod/riverpod.dart";
|
||||
// import "package:sqflite_common_ffi/sqflite_ffi.dart";
|
||||
import "package:matrix/matrix.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:sqflite_common_ffi/sqflite_ffi.dart";
|
||||
|
||||
// class ClientController extends AsyncNotifier<Client> {
|
||||
// @override
|
||||
// Future<Client> build() async {
|
||||
// final settings = ref.watch(SettingsController.provider)!;
|
||||
// final client = Client(
|
||||
// "nexusbot",
|
||||
// database: await MatrixSdkDatabase.init(
|
||||
// "NexusBot",
|
||||
// database: await databaseFactoryFfi.openDatabase(inMemoryDatabasePath),
|
||||
// ),
|
||||
// );
|
||||
class ClientController extends AsyncNotifier<Client> {
|
||||
@override
|
||||
Future<Client> build() async {
|
||||
final client = Client(
|
||||
"nexus",
|
||||
database: await MatrixSdkDatabase.init(
|
||||
"nexus",
|
||||
database: await databaseFactoryFfi.openDatabase("./test.db"),
|
||||
),
|
||||
);
|
||||
//mxc
|
||||
await client.checkHomeserver(Uri.https("federated.nexus"));
|
||||
await client.login(
|
||||
LoginType.mLoginPassword,
|
||||
identifier: AuthenticationUserIdentifier(user: "quadradical"),
|
||||
password: File("./password.txt").readAsStringSync(),
|
||||
);
|
||||
|
||||
// await client.checkHomeserver(settings.homeserver);
|
||||
// await client.login(
|
||||
// LoginType.mLoginPassword,
|
||||
// identifier: AuthenticationUserIdentifier(user: settings.name),
|
||||
// password: (await File(settings.botPasswordFile).readAsString()).trim(),
|
||||
// );
|
||||
return client;
|
||||
}
|
||||
|
||||
// return client;
|
||||
// }
|
||||
|
||||
// static final provider = AsyncNotifierProvider<ClientController, Client>(
|
||||
// ClientController.new,
|
||||
// );
|
||||
// }
|
||||
static final provider = AsyncNotifierProvider<ClientController, Client>(
|
||||
ClientController.new,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
36
lib/controllers/spaces_controller.dart
Normal file
36
lib/controllers/spaces_controller.dart
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import "package:flutter/widgets.dart";
|
||||
import "package:matrix/matrix.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:nexus/controllers/client_controller.dart";
|
||||
import "package:nexus/models/space.dart";
|
||||
|
||||
class SpacesController extends AsyncNotifier<List<Space>> {
|
||||
@override
|
||||
Future<List<Space>> build() async {
|
||||
final client = await ref.watch(ClientController.provider.future);
|
||||
|
||||
return Future.wait(
|
||||
client.rooms.where((room) => room.isSpace).map((data) async {
|
||||
final thumb = await data.avatar?.getThumbnailUri(
|
||||
client,
|
||||
width: 40,
|
||||
height: 40,
|
||||
);
|
||||
return Space(
|
||||
roomData: data,
|
||||
avatar: thumb == null
|
||||
? null
|
||||
: Image.network(
|
||||
thumb.toString(),
|
||||
width: 40,
|
||||
headers: {"authorization": "Bearer ${client.accessToken}"},
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
static final provider = AsyncNotifierProvider<SpacesController, List<Space>>(
|
||||
SpacesController.new,
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue