✨ Realm basis
This commit is contained in:
@ -44,10 +44,10 @@ class ChatProvider extends ChangeNotifier {
|
||||
return channel;
|
||||
}
|
||||
|
||||
Future<Channel> fetchChannel(String alias) async {
|
||||
Future<Channel> fetchChannel(String alias, String realm) async {
|
||||
final Client client = Client();
|
||||
|
||||
var uri = getRequestUri('messaging', '/api/channels/global/$alias');
|
||||
var uri = getRequestUri('messaging', '/api/channels/$realm/$alias');
|
||||
var res = await client.get(uri);
|
||||
if (res.statusCode == 200) {
|
||||
final result = jsonDecode(utf8.decode(res.bodyBytes));
|
||||
@ -60,10 +60,10 @@ class ChatProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
Future<Call?> fetchOngoingCall(String alias) async {
|
||||
Future<Call?> fetchOngoingCall(String alias, String realm) async {
|
||||
final Client client = Client();
|
||||
|
||||
var uri = getRequestUri('messaging', '/api/channels/global/$alias/calls/ongoing');
|
||||
var uri = getRequestUri('messaging', '/api/channels/$realm/$alias/calls/ongoing');
|
||||
var res = await client.get(uri);
|
||||
if (res.statusCode == 200) {
|
||||
final result = jsonDecode(utf8.decode(res.bodyBytes));
|
||||
|
42
lib/providers/realm.dart
Normal file
42
lib/providers/realm.dart
Normal file
@ -0,0 +1,42 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:solian/models/realm.dart';
|
||||
import 'package:solian/providers/auth.dart';
|
||||
import 'package:solian/utils/service_url.dart';
|
||||
|
||||
class RealmProvider with ChangeNotifier {
|
||||
List<Realm> realms = List.empty();
|
||||
|
||||
Realm? focusRealm;
|
||||
|
||||
Future<void> fetch(AuthProvider auth) async {
|
||||
if (!await auth.isAuthorized()) return;
|
||||
|
||||
var uri = getRequestUri('passport', '/api/realms/me/available');
|
||||
|
||||
var res = await auth.client!.get(uri);
|
||||
if (res.statusCode == 200) {
|
||||
final result = jsonDecode(utf8.decode(res.bodyBytes)) as List<dynamic>;
|
||||
realms = result.map((x) => Realm.fromJson(x)).toList();
|
||||
notifyListeners();
|
||||
} else {
|
||||
var message = utf8.decode(res.bodyBytes);
|
||||
throw Exception(message);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Realm> fetchSingle(AuthProvider auth, String alias) async {
|
||||
var uri = getRequestUri('passport', '/api/realms/$alias');
|
||||
var res = await auth.client!.get(uri);
|
||||
if (res.statusCode == 200) {
|
||||
final result = jsonDecode(utf8.decode(res.bodyBytes));
|
||||
focusRealm = Realm.fromJson(result);
|
||||
notifyListeners();
|
||||
return focusRealm!;
|
||||
} else {
|
||||
var message = utf8.decode(res.bodyBytes);
|
||||
throw Exception(message);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user