Compare commits

..

2 Commits

Author SHA1 Message Date
cd5cfedb2f 🎨 Formatted all the code 2024-05-01 17:37:34 +08:00
28c0094837 Better to solve multi-factor authenticate 2024-05-01 11:27:48 +08:00
51 changed files with 966 additions and 549 deletions

View File

@ -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

View File

@ -16,6 +16,8 @@
"confirmation": "Confirmation",
"confirmCancel": "Not sure",
"confirmOkay": "OK",
"email": "Email Address",
"nickname": "Nickname",
"username": "Username",
"password": "Password",
"next": "Next",

View File

@ -16,6 +16,8 @@
"confirmation": "确认",
"confirmCancel": "不太确定",
"confirmOkay": "确定",
"email": "邮箱地址",
"nickname": "显示名",
"username": "用户名",
"password": "密码",
"next": "下一步",

View File

@ -25,28 +25,29 @@ class Call {
});
factory Call.fromJson(Map<String, dynamic> json) => Call(
id: json["id"],
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,
externalId: json["external_id"],
founderId: json["founder_id"],
channelId: json["channel_id"],
channel: Channel.fromJson(json["channel"]),
);
id: json["id"],
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,
externalId: json["external_id"],
founderId: json["founder_id"],
channelId: json["channel_id"],
channel: Channel.fromJson(json["channel"]),
);
Map<String, dynamic> toJson() => {
"id": id,
"created_at": createdAt.toIso8601String(),
"updated_at": updatedAt.toIso8601String(),
"deleted_at": deletedAt,
"ended_at": endedAt?.toIso8601String(),
"external_id": externalId,
"founder_id": founderId,
"channel_id": channelId,
"channel": channel.toJson(),
};
"id": id,
"created_at": createdAt.toIso8601String(),
"updated_at": updatedAt.toIso8601String(),
"deleted_at": deletedAt,
"ended_at": endedAt?.toIso8601String(),
"external_id": externalId,
"founder_id": founderId,
"channel_id": channelId,
"channel": channel.toJson(),
};
}
enum ParticipantStatsType {
@ -60,9 +61,9 @@ enum ParticipantStatsType {
class ParticipantTrack {
ParticipantTrack(
{required this.participant,
required this.videoTrack,
required this.isScreenShare});
required this.videoTrack,
required this.isScreenShare});
VideoTrack? videoTrack;
Participant participant;
bool isScreenShare;
}
}

View File

@ -32,36 +32,36 @@ class Channel {
});
factory Channel.fromJson(Map<String, dynamic> json) => Channel(
id: json["id"],
createdAt: DateTime.parse(json["created_at"]),
updatedAt: DateTime.parse(json["updated_at"]),
deletedAt: json["deleted_at"],
alias: json["alias"],
name: json["name"],
description: json["description"],
members: json["members"],
calls: json["calls"],
type: json["type"],
account: Account.fromJson(json["account"]),
accountId: json["account_id"],
realmId: json["realm_id"],
);
id: json["id"],
createdAt: DateTime.parse(json["created_at"]),
updatedAt: DateTime.parse(json["updated_at"]),
deletedAt: json["deleted_at"],
alias: json["alias"],
name: json["name"],
description: json["description"],
members: json["members"],
calls: json["calls"],
type: json["type"],
account: Account.fromJson(json["account"]),
accountId: json["account_id"],
realmId: json["realm_id"],
);
Map<String, dynamic> toJson() => {
"id": id,
"created_at": createdAt.toIso8601String(),
"updated_at": updatedAt.toIso8601String(),
"deleted_at": deletedAt,
"alias": alias,
"name": name,
"description": description,
"members": members,
"calls": calls,
"type": type,
"account": account,
"account_id": accountId,
"realm_id": realmId,
};
"id": id,
"created_at": createdAt.toIso8601String(),
"updated_at": updatedAt.toIso8601String(),
"deleted_at": deletedAt,
"alias": alias,
"name": name,
"description": description,
"members": members,
"calls": calls,
"type": type,
"account": account,
"account_id": accountId,
"realm_id": realmId,
};
}
class ChannelMember {
@ -86,24 +86,24 @@ class ChannelMember {
});
factory ChannelMember.fromJson(Map<String, dynamic> json) => ChannelMember(
id: json["id"],
createdAt: DateTime.parse(json["created_at"]),
updatedAt: DateTime.parse(json["updated_at"]),
deletedAt: json["deleted_at"],
channelId: json["channel_id"],
accountId: json["account_id"],
account: Account.fromJson(json["account"]),
notify: json["notify"],
);
id: json["id"],
createdAt: DateTime.parse(json["created_at"]),
updatedAt: DateTime.parse(json["updated_at"]),
deletedAt: json["deleted_at"],
channelId: json["channel_id"],
accountId: json["account_id"],
account: Account.fromJson(json["account"]),
notify: json["notify"],
);
Map<String, dynamic> toJson() => {
"id": id,
"created_at": createdAt.toIso8601String(),
"updated_at": updatedAt.toIso8601String(),
"deleted_at": deletedAt,
"channel_id": channelId,
"account_id": accountId,
"account": account.toJson(),
"notify": notify,
};
}
"id": id,
"created_at": createdAt.toIso8601String(),
"updated_at": updatedAt.toIso8601String(),
"deleted_at": deletedAt,
"channel_id": channelId,
"account_id": accountId,
"account": account.toJson(),
"notify": notify,
};
}

View File

@ -26,30 +26,30 @@ class Friendship {
});
factory Friendship.fromJson(Map<String, dynamic> json) => Friendship(
id: json["id"],
createdAt: DateTime.parse(json["created_at"]),
updatedAt: DateTime.parse(json["updated_at"]),
deletedAt: json["deleted_at"],
accountId: json["account_id"],
relatedId: json["related_id"],
blockedBy: json["blocked_by"],
account: Account.fromJson(json["account"]),
related: Account.fromJson(json["related"]),
status: json["status"],
);
id: json["id"],
createdAt: DateTime.parse(json["created_at"]),
updatedAt: DateTime.parse(json["updated_at"]),
deletedAt: json["deleted_at"],
accountId: json["account_id"],
relatedId: json["related_id"],
blockedBy: json["blocked_by"],
account: Account.fromJson(json["account"]),
related: Account.fromJson(json["related"]),
status: json["status"],
);
Map<String, dynamic> toJson() => {
"id": id,
"created_at": createdAt.toIso8601String(),
"updated_at": updatedAt.toIso8601String(),
"deleted_at": deletedAt,
"account_id": accountId,
"related_id": relatedId,
"blocked_by": blockedBy,
"account": account.toJson(),
"related": related.toJson(),
"status": status,
};
"id": id,
"created_at": createdAt.toIso8601String(),
"updated_at": updatedAt.toIso8601String(),
"deleted_at": deletedAt,
"account_id": accountId,
"related_id": relatedId,
"blocked_by": blockedBy,
"account": account.toJson(),
"related": related.toJson(),
"status": status,
};
Account getOtherside(int selfId) {
if (accountId != selfId) {
@ -58,4 +58,4 @@ class Friendship {
return related;
}
}
}
}

View File

@ -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,

View File

@ -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,

View File

@ -10,14 +10,14 @@ class NetworkPackage {
});
factory NetworkPackage.fromJson(Map<String, dynamic> json) => NetworkPackage(
method: json["w"],
message: json["m"],
payload: json["p"],
);
method: json["w"],
message: json["m"],
payload: json["p"],
);
Map<String, dynamic> toJson() => {
"w": method,
"m": message,
"p": payload,
};
}
"w": method,
"m": message,
"p": payload,
};
}

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');
@ -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();
lastRefreshedAt = DateTime.now();
}

View File

@ -22,7 +22,7 @@ class ChatProvider extends ChangeNotifier {
ChatCallInstance? call;
Future<WebSocketChannel?> connect(AuthProvider auth) async {
if (auth.client == null) await auth.pickClient();
if (auth.client == null) await auth.loadClient();
if (!await auth.isAuthorized()) return null;