initial
This commit is contained in:
parent
ae29162b5d
commit
64dd38f7aa
6 changed files with 265 additions and 2 deletions
0
lib/controllers/client_controller.dart
Normal file
0
lib/controllers/client_controller.dart
Normal file
12
lib/controllers/last_synced_controller.dart
Normal file
12
lib/controllers/last_synced_controller.dart
Normal file
|
@ -0,0 +1,12 @@
|
|||
import "package:riverpod/riverpod.dart";
|
||||
|
||||
class LastSyncedController extends Notifier<String?> {
|
||||
@override
|
||||
String? build() => null;
|
||||
|
||||
void set(String value) => state = value;
|
||||
|
||||
static final provider = NotifierProvider<LastSyncedController, String?>(
|
||||
LastSyncedController.new,
|
||||
);
|
||||
}
|
|
@ -1,12 +1,14 @@
|
|||
import "dart:convert";
|
||||
import "dart:io";
|
||||
import "package:markdown/markdown.dart";
|
||||
import "package:nexusbot/controllers/last_synced_controller.dart";
|
||||
import "package:nexusbot/controllers/login_controller.dart";
|
||||
import "package:nexusbot/controllers/settings_controller.dart";
|
||||
import "package:nexusbot/models/registration.dart";
|
||||
import "package:shelf/shelf.dart";
|
||||
import "package:http/http.dart" as http;
|
||||
import "package:riverpod/riverpod.dart";
|
||||
import "package:matrix/matrix.dart";
|
||||
|
||||
class ApiHelper {
|
||||
final Ref ref;
|
||||
|
@ -86,12 +88,35 @@ class ApiHelper {
|
|||
return json.decode(response.body)["event_id"];
|
||||
}
|
||||
|
||||
Future<String> listen() async {
|
||||
final settings = ref.watch(SettingsController.provider)!;
|
||||
final response = await http.get(
|
||||
settings.homeserver.replace(
|
||||
path: "_matrix/client/v3/sync",
|
||||
queryParameters: {
|
||||
"timeout": "30000",
|
||||
if (ref.watch(LastSyncedController.provider) != null case final since)
|
||||
"since": since,
|
||||
},
|
||||
),
|
||||
headers: await getHeaders(),
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception("Sync failed: ${response.body}");
|
||||
}
|
||||
|
||||
final data = json.decode(response);
|
||||
}
|
||||
|
||||
Future<Response> register(Request request) async {
|
||||
final settings = ref.read(SettingsController.provider)!;
|
||||
final registration = Registration.fromJson(
|
||||
json.decode(await request.readAsString()),
|
||||
);
|
||||
|
||||
Login
|
||||
|
||||
final event = await sendMessage("""# Registration request
|
||||
- Username: `${registration.username}`
|
||||
- Email: `${registration.email}`""", room: settings.adminRoom);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue