Compare commits
2 Commits
5d79692766
...
cd5cfedb2f
Author | SHA1 | Date | |
---|---|---|---|
cd5cfedb2f | |||
28c0094837 |
@ -21,8 +21,9 @@ linter:
|
||||
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
|
||||
# producing the lint.
|
||||
rules:
|
||||
# avoid_print: false # Uncomment to disable the `avoid_print` rule
|
||||
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
|
||||
lines_longer_than_80_chars: false
|
||||
avoid_print: false # Uncomment to disable the `avoid_print` rule
|
||||
prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
|
||||
|
||||
# Additional information about this file can be found at
|
||||
# https://dart.dev/guides/language/analysis-options
|
||||
|
@ -16,6 +16,8 @@
|
||||
"confirmation": "Confirmation",
|
||||
"confirmCancel": "Not sure",
|
||||
"confirmOkay": "OK",
|
||||
"email": "Email Address",
|
||||
"nickname": "Nickname",
|
||||
"username": "Username",
|
||||
"password": "Password",
|
||||
"next": "Next",
|
||||
|
@ -16,6 +16,8 @@
|
||||
"confirmation": "确认",
|
||||
"confirmCancel": "不太确定",
|
||||
"confirmOkay": "确定",
|
||||
"email": "邮箱地址",
|
||||
"nickname": "显示名",
|
||||
"username": "用户名",
|
||||
"password": "密码",
|
||||
"next": "下一步",
|
||||
|
@ -29,7 +29,8 @@ class Call {
|
||||
createdAt: DateTime.parse(json["created_at"]),
|
||||
updatedAt: DateTime.parse(json["updated_at"]),
|
||||
deletedAt: json["deleted_at"],
|
||||
endedAt: json["ended_at"] != null ? DateTime.parse(json["ended_at"]) : null,
|
||||
endedAt:
|
||||
json["ended_at"] != null ? DateTime.parse(json["ended_at"]) : null,
|
||||
externalId: json["external_id"],
|
||||
founderId: json["founder_id"],
|
||||
channelId: json["channel_id"],
|
||||
|
@ -43,11 +43,15 @@ class Message {
|
||||
content: json["content"],
|
||||
metadata: json["metadata"],
|
||||
type: json["type"],
|
||||
attachments: List<Attachment>.from(json["attachments"]?.map((x) => Attachment.fromJson(x)) ?? List.empty()),
|
||||
attachments: List<Attachment>.from(
|
||||
json["attachments"]?.map((x) => Attachment.fromJson(x)) ??
|
||||
List.empty()),
|
||||
channel: Channel.fromJson(json["channel"]),
|
||||
sender: Sender.fromJson(json["sender"]),
|
||||
replyId: json["reply_id"],
|
||||
replyTo: json["reply_to"] != null ? Message.fromJson(json["reply_to"]) : null,
|
||||
replyTo: json["reply_to"] != null
|
||||
? Message.fromJson(json["reply_to"])
|
||||
: null,
|
||||
channelId: json["channel_id"],
|
||||
senderId: json["sender_id"],
|
||||
);
|
||||
@ -60,7 +64,8 @@ class Message {
|
||||
"content": content,
|
||||
"metadata": metadata,
|
||||
"type": type,
|
||||
"attachments": List<dynamic>.from(attachments?.map((x) => x.toJson()) ?? List.empty()),
|
||||
"attachments": List<dynamic>.from(
|
||||
attachments?.map((x) => x.toJson()) ?? List.empty()),
|
||||
"channel": channel?.toJson(),
|
||||
"sender": sender.toJson(),
|
||||
"reply_id": replyId,
|
||||
|
@ -34,7 +34,9 @@ class Notification {
|
||||
deletedAt: json["deleted_at"],
|
||||
subject: json["subject"],
|
||||
content: json["content"],
|
||||
links: json["links"] != null ? List<Link>.from(json["links"].map((x) => Link.fromJson(x))) : List.empty(),
|
||||
links: json["links"] != null
|
||||
? List<Link>.from(json["links"].map((x) => Link.fromJson(x)))
|
||||
: List.empty(),
|
||||
isImportant: json["is_important"],
|
||||
isRealtime: json["is_realtime"],
|
||||
readAt: json["read_at"],
|
||||
@ -49,7 +51,9 @@ class Notification {
|
||||
"deleted_at": deletedAt,
|
||||
"subject": subject,
|
||||
"content": content,
|
||||
"links": links != null ? List<dynamic>.from(links!.map((x) => x.toJson())) : List.empty(),
|
||||
"links": links != null
|
||||
? List<dynamic>.from(links!.map((x) => x.toJson()))
|
||||
: List.empty(),
|
||||
"is_important": isImportant,
|
||||
"is_realtime": isRealtime,
|
||||
"read_at": readAt,
|
||||
|
@ -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');
|
||||
@ -26,11 +27,13 @@ class AuthProvider extends ChangeNotifier {
|
||||
|
||||
DateTime? lastRefreshedAt;
|
||||
|
||||
Future<bool> pickClient() async {
|
||||
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,8 +45,9 @@ class AuthProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
Future<oauth2.Client> createClient(BuildContext context, String username, String password) async {
|
||||
if (await pickClient()) {
|
||||
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());
|
||||
|
||||
@ -92,9 +98,12 @@ class AuthProvider extends ChangeNotifier {
|
||||
const storage = FlutterSecureStorage();
|
||||
if (await storage.containsKey(key: storageKey)) {
|
||||
if (client == null) {
|
||||
await pickClient();
|
||||
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();
|
||||