pretty cool
This commit is contained in:
parent
b42081b525
commit
40bad1e06e
7 changed files with 539 additions and 53 deletions
33
lib/controllers/client_controller.dart
Normal file
33
lib/controllers/client_controller.dart
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
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";
|
||||
|
||||
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),
|
||||
),
|
||||
);
|
||||
|
||||
await client.checkHomeserver(settings.homeserver);
|
||||
await client.login(
|
||||
LoginType.mLoginPassword,
|
||||
identifier: AuthenticationUserIdentifier(user: settings.name),
|
||||
password: (await File(settings.botPasswordFile).readAsString()).trim(),
|
||||
);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
static final provider = AsyncNotifierProvider<ClientController, Client>(
|
||||
ClientController.new,
|
||||
);
|
||||
}
|
||||
48
lib/controllers/room_chat_controller.dart
Normal file
48
lib/controllers/room_chat_controller.dart
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import "package:flutter_chat_core/flutter_chat_core.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
|
||||
class RoomChatController extends Notifier<ChatController> {
|
||||
RoomChatController(this.id);
|
||||
final String id;
|
||||
|
||||
@override
|
||||
InMemoryChatController build() => InMemoryChatController(
|
||||
messages: [
|
||||
Message.text(id: "foo2", authorId: "foo", text: "**Some** text"),
|
||||
Message.text(
|
||||
id: "foo3",
|
||||
authorId: "foo5",
|
||||
text: "Some text 2 https://federated.nexus",
|
||||
),
|
||||
Message.text(
|
||||
id: "aksdjflkasdjf",
|
||||
authorId: "foo",
|
||||
text: "Some text 2 https://github.com/Henry-hiles/nixos",
|
||||
),
|
||||
Message.system(id: "foo4", authorId: "", text: "system"),
|
||||
Message.text(id: "foo6", authorId: "foo5", text: "Some text 2"),
|
||||
Message.image(
|
||||
id: "foo5",
|
||||
authorId: "foobar3",
|
||||
source:
|
||||
"https://henryhiles.com/_astro/federatedNexus.BvZmkdyc_2b28Im.webp",
|
||||
),
|
||||
Message.text(id: "foo7", authorId: "foobar3", text: "this has an image"),
|
||||
],
|
||||
);
|
||||
|
||||
void send(String message) {
|
||||
state.insertMessage(
|
||||
Message.text(
|
||||
id: DateTime.now().millisecondsSinceEpoch.toString(),
|
||||
authorId: "foo",
|
||||
text: message,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static final provider =
|
||||
NotifierProvider.family<RoomChatController, ChatController, String>(
|
||||
RoomChatController.new,
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue