🎨 Formatted all the code

This commit is contained in:
2024-05-01 17:37:34 +08:00
parent 28c0094837
commit cd5cfedb2f
51 changed files with 938 additions and 540 deletions

View File

@@ -8,7 +8,8 @@ import 'package:solian/utils/service_url.dart';
class AuthProvider extends ChangeNotifier {
AuthProvider();
final deviceEndpoint = getRequestUri('passport', '/api/notifications/subscribe');
final deviceEndpoint =
getRequestUri('passport', '/api/notifications/subscribe');
final tokenEndpoint = getRequestUri('passport', '/api/auth/token');
final userinfoEndpoint = getRequestUri('passport', '/api/users/me');
final redirectUrl = Uri.parse('solian://auth');
@@ -29,8 +30,10 @@ class AuthProvider extends ChangeNotifier {
Future<bool> loadClient() async {
if (await storage.containsKey(key: storageKey)) {
try {
final credentials = oauth2.Credentials.fromJson((await storage.read(key: storageKey))!);
client = oauth2.Client(credentials, identifier: clientId, secret: clientSecret);
final credentials =
oauth2.Credentials.fromJson((await storage.read(key: storageKey))!);
client = oauth2.Client(credentials,
identifier: clientId, secret: clientSecret);
await fetchProfiles();
return true;
} catch (e) {
@@ -42,7 +45,8 @@ class AuthProvider extends ChangeNotifier {
}
}
Future<oauth2.Client> createClient(BuildContext context, String username, String password) async {
Future<oauth2.Client> createClient(
BuildContext context, String username, String password) async {
if (await loadClient()) {
return client!;
}
@@ -68,15 +72,17 @@ class AuthProvider extends ChangeNotifier {
Future<void> refreshToken() async {
if (client != null) {
final credentials =
await client!.credentials.refresh(identifier: clientId, secret: clientSecret, basicAuth: false);
client = oauth2.Client(credentials, identifier: clientId, secret: clientSecret);
final credentials = await client!.credentials.refresh(
identifier: clientId, secret: clientSecret, basicAuth: false);
client = oauth2.Client(credentials,
identifier: clientId, secret: clientSecret);
storage.write(key: storageKey, value: credentials.toJson());
}
notifyListeners();
}
Future<void> signin(BuildContext context, String username, String password) async {
Future<void> signin(
BuildContext context, String username, String password) async {
client = await createClient(context, username, password);
storage.write(key: storageKey, value: client!.credentials.toJson());
@@ -94,7 +100,10 @@ class AuthProvider extends ChangeNotifier {
if (client == null) {
await loadClient();
}
if (lastRefreshedAt == null || DateTime.now().subtract(const Duration(minutes: 3)).isAfter(lastRefreshedAt!)) {
if (lastRefreshedAt == null ||
DateTime.now()
.subtract(const Duration(minutes: 3))
.isAfter(lastRefreshedAt!)) {
await refreshToken();
lastRefreshedAt = DateTime.now();
}

View File

@@ -32,7 +32,9 @@ class ChatProvider extends ChangeNotifier {
scheme: ori.scheme.replaceFirst('http', 'ws'),
host: ori.host,
path: ori.path,
queryParameters: {'tk': Uri.encodeComponent(auth.client!.credentials.accessToken)},
queryParameters: {
'tk': Uri.encodeComponent(auth.client!.credentials.accessToken)
},
);
final channel = WebSocketChannel.connect(uri);
@@ -41,7 +43,8 @@ class ChatProvider extends ChangeNotifier {
return channel;
}
bool handleCall(Call call, Channel channel, {Function? onUpdate, Function? onDispose}) {
bool handleCall(Call call, Channel channel,
{Function? onUpdate, Function? onDispose}) {
if (this.call != null) return false;
this.call = ChatCallInstance(
@@ -106,7 +109,8 @@ class ChatCallInstance {
});
void init() {
subscription = Hardware.instance.onDeviceChange.stream.listen(revertDevices);
subscription =
Hardware.instance.onDeviceChange.stream.listen(revertDevices);
room = Room();
listener = room.createListener();
Hardware.instance.enumerateDevices().then(revertDevices);
@@ -114,7 +118,8 @@ class ChatCallInstance {
}
Future<void> checkPermissions() async {
if (lkPlatformIs(PlatformType.macOS) || lkPlatformIs(PlatformType.linux)) return;
if (lkPlatformIs(PlatformType.macOS) || lkPlatformIs(PlatformType.linux))
return;
await Permission.camera.request();
await Permission.microphone.request();
@@ -131,7 +136,8 @@ class ChatCallInstance {
throw Exception("unauthorized");
}
var uri = getRequestUri('messaging', '/api/channels/${channel.alias}/calls/ongoing/token');
var uri = getRequestUri(
'messaging', '/api/channels/${channel.alias}/calls/ongoing/token');
var res = await auth.client!.post(uri);
if (res.statusCode == 200) {
@@ -184,10 +190,12 @@ class ChatCallInstance {
useiOSBroadcastExtension: true,
params: VideoParameters(
dimensions: VideoDimensionsPresets.h1080_169,
encoding: VideoEncoding(maxBitrate: 3 * 1000 * 1000, maxFramerate: 30),
encoding:
VideoEncoding(maxBitrate: 3 * 1000 * 1000, maxFramerate: 30),
),
),
defaultCameraCaptureOptions: CameraCaptureOptions(maxFrameRate: 30, params: videoParameters),
defaultCameraCaptureOptions:
CameraCaptureOptions(maxFrameRate: 30, params: videoParameters),
),
fastConnectOptions: FastConnectOptions(
microphone: TrackOption(track: audioTrack),
@@ -220,7 +228,8 @@ class ChatCallInstance {
room.addListener(onRoomDidUpdate);
setupRoomListeners(context);
sortParticipants();
WidgetsBindingCompatible.instance?.addPostFrameCallback((_) => autoPublish(context));
WidgetsBindingCompatible.instance
?.addPostFrameCallback((_) => autoPublish(context));
if (lkPlatformIsMobile()) {
Hardware.instance.setSpeakerphoneOn(true);
@@ -295,7 +304,8 @@ class ChatCallInstance {
}
// First joined people first
return a.participant.joinedAt.millisecondsSinceEpoch - b.participant.joinedAt.millisecondsSinceEpoch;
return a.participant.joinedAt.millisecondsSinceEpoch -
b.participant.joinedAt.millisecondsSinceEpoch;
});
ParticipantTrack localTrack = ParticipantTrack(
@@ -304,7 +314,8 @@ class ChatCallInstance {
isScreenShare: false,
);
if (room.localParticipant != null) {
final localParticipantTracks = room.localParticipant?.videoTrackPublications;
final localParticipantTracks =
room.localParticipant?.videoTrackPublications;
if (localParticipantTracks != null) {
for (var t in localParticipantTracks) {
localTrack.videoTrack = t.track;
@@ -317,7 +328,8 @@ class ChatCallInstance {
if (focusTrack == null) {
focusTrack = participantTracks.first;
} else {
final idx = participantTracks.indexWhere((x) => focusTrack!.participant.sid == x.participant.sid);
final idx = participantTracks
.indexWhere((x) => focusTrack!.participant.sid == x.participant.sid);
focusTrack = participantTracks[idx];
}

View File

@@ -16,11 +16,11 @@ class FriendProvider extends ChangeNotifier {
var res = await auth.client!.get(uri);
if (res.statusCode == 200) {
final result = jsonDecode(utf8.decode(res.bodyBytes)) as List<dynamic>;
friends = result.map((x) => Friendship.fromJson(x)).toList();
notifyListeners();
friends = result.map((x) => Friendship.fromJson(x)).toList();
notifyListeners();
} else {
var message = utf8.decode(res.bodyBytes);
throw Exception(message);
}
}
}
}

View File

@@ -17,7 +17,8 @@ class NotifyProvider extends ChangeNotifier {
List<model.Notification> notifications = List.empty(growable: true);
final FlutterLocalNotificationsPlugin localNotify = FlutterLocalNotificationsPlugin();
final FlutterLocalNotificationsPlugin localNotify =
FlutterLocalNotificationsPlugin();
NotifyProvider() {
initNotify();
@@ -31,8 +32,10 @@ class NotifyProvider extends ChangeNotifier {
DarwinNotificationCategory("general"),
],
);
const linuxSettings = LinuxInitializationSettings(defaultActionName: 'Open notification');
const InitializationSettings initializationSettings = InitializationSettings(
const linuxSettings =
LinuxInitializationSettings(defaultActionName: 'Open notification');
const InitializationSettings initializationSettings =
InitializationSettings(
android: androidSettings,
iOS: darwinSettings,
macOS: darwinSettings,
@@ -43,7 +46,8 @@ class NotifyProvider extends ChangeNotifier {
}
Future<void> requestPermissions() async {
if (lkPlatformIs(PlatformType.macOS) || lkPlatformIs(PlatformType.linux)) return;
if (lkPlatformIs(PlatformType.macOS) || lkPlatformIs(PlatformType.linux))
return;
await Permission.notification.request();
}
@@ -53,8 +57,11 @@ class NotifyProvider extends ChangeNotifier {
var uri = getRequestUri('passport', '/api/notifications?skip=0&take=25');
var res = await auth.client!.get(uri);
if (res.statusCode == 200) {
final result = PaginationResult.fromJson(jsonDecode(utf8.decode(res.bodyBytes)));
notifications = result.data?.map((x) => model.Notification.fromJson(x)).toList() ?? List.empty(growable: true);
final result =
PaginationResult.fromJson(jsonDecode(utf8.decode(res.bodyBytes)));
notifications =
result.data?.map((x) => model.Notification.fromJson(x)).toList() ??
List.empty(growable: true);
}
notifyListeners();
@@ -71,7 +78,9 @@ class NotifyProvider extends ChangeNotifier {
scheme: ori.scheme.replaceFirst('http', 'ws'),
host: ori.host,
path: ori.path,
queryParameters: {'tk': Uri.encodeComponent(auth.client!.credentials.accessToken)},
queryParameters: {
'tk': Uri.encodeComponent(auth.client!.credentials.accessToken)
},
);
final channel = WebSocketChannel.connect(uri);