2024-05-25 16:11:00 +00:00
|
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:solian/providers/auth.dart';
|
|
|
|
import 'package:solian/services.dart';
|
|
|
|
|
|
|
|
class ChannelProvider extends GetxController {
|
2024-05-25 17:21:08 +00:00
|
|
|
Future<Response> getChannel(String alias, {String realm = 'global'}) async {
|
|
|
|
final AuthProvider auth = Get.find();
|
|
|
|
if (!await auth.isAuthorized) throw Exception('unauthorized');
|
|
|
|
|
2024-05-26 05:39:21 +00:00
|
|
|
final client = GetConnect(maxAuthRetries: 3);
|
2024-05-25 17:21:08 +00:00
|
|
|
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
|
|
|
|
|
|
|
|
final resp = await client.get('/api/channels/$realm/$alias');
|
|
|
|
if (resp.statusCode != 200) {
|
|
|
|
throw Exception(resp.bodyString);
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp;
|
|
|
|
}
|
|
|
|
|
2024-05-25 16:11:00 +00:00
|
|
|
Future<Response> listAvailableChannel({String realm = 'global'}) async {
|
|
|
|
final AuthProvider auth = Get.find();
|
|
|
|
if (!await auth.isAuthorized) throw Exception('unauthorized');
|
|
|
|
|
2024-05-26 05:39:21 +00:00
|
|
|
final client = GetConnect(maxAuthRetries: 3);
|
2024-05-25 16:11:00 +00:00
|
|
|
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
|
|
|
|
client.httpClient.addAuthenticator(auth.requestAuthenticator);
|
|
|
|
|
|
|
|
final resp = await client.get('/api/channels/$realm/me/available');
|
|
|
|
if (resp.statusCode != 200) {
|
|
|
|
throw Exception(resp.bodyString);
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp;
|
|
|
|
}
|
|
|
|
}
|