ignalxy 4 роки тому
батько
коміт
2e32fca687

+ 1 - 1
lib/presenter/contact_list.dart

@@ -25,7 +25,7 @@ class ContactListPresenter extends ChangeNotifier {
     }
     SuspensionUtil.sortListBySuspensionTag(list);
     SuspensionUtil.setShowSuspensionStatus(list);
-    list.add(ContactInfo(name: '新的朋友', tag: '↑', bgColor: Colors.orange, iconData: Icons.person_add));
+    list.add(ContactInfo(name: 'New friends', tag: '↑', bgColor: Colors.orange, iconData: Icons.person_add));
     return list;
   }
 

+ 16 - 3
lib/presenter/login.dart

@@ -1,7 +1,7 @@
 import 'package:dio/dio.dart';
-import 'package:flutter/material.dart';
 import 'package:flutter_secure_storage/flutter_secure_storage.dart';
-import 'package:provider/provider.dart';
+
+import 'package:encrypt/encrypt.dart';
 
 import 'package:e2ee_chat/common/global.dart';
 import 'package:e2ee_chat/common/api.dart';
@@ -43,10 +43,23 @@ class LoginPresenter extends ProfilePresenter {
 
   User? get user => profile.user;
 
+  @Transient()
+  Future<String?> get _secretKey async {
+    if (user == null) return null;
+    final storage = FlutterSecureStorage();
+    String? _key = await storage.read(key: _keyKey);
+    if (_key == null) {
+      _key = Key.fromSecureRandom(256).base64;
+      await storage.write(key: _keyKey, value: _key);
+    }
+    return _key;
+  }
+
+  String get _keyKey => "e2ee_chat secret key of ${user!.username}";
+
   Future<bool> login({String? username, String? password}) async {
     debug('UserModel login begin');
     if (username != null) {
-
       profile.user = User(username);
     }
     bool _result = false;

+ 13 - 2
lib/presenter/user_chat.dart

@@ -73,10 +73,21 @@ class UserChatPresenter extends ChatListPresenter {
     // messages.forEach((message) => list.add(message.chatMessage));
   }
 
-  ChatMessage chatMessageFromMessagePackage(String plaintext) {
+  ChatMessage chatMessageFromMessagePackage(String encText) {
     // Map<String, dynamic> json0 = jsonDecode(s);
     // String plaintext = json0["plaintext"];
-    debug('plaintext: $plaintext');
+    ChatMessage? _message;
+    try {
+      _message = ChatMessage.fromJson(jsonDecode(encText));
+    } catch (e) {
+      try {
+
+      } catch (e) {
+
+      }
+    }
+    debug('plaintext: $encText');
+
     return ChatMessage.fromJson(jsonDecode(plaintext));
   }
 

+ 0 - 1
lib/view/add_friend.dart

@@ -44,7 +44,6 @@ class _AddFriendViewState extends State<AddFriendView> {
                   constraints: BoxConstraints.expand(height: 55.0),
                   child: ElevatedButton(
                     style: ButtonStyle(
-                      foregroundColor: MaterialStateProperty.all<Color>(Provider.of<ThemeModel>(context).theme),
                       //TODO: something wrong with text color
                       textStyle: MaterialStateProperty.all<TextStyle>(TextStyle(color: Colors.white)),
                     ),

+ 1 - 1
lib/view/home.dart

@@ -40,7 +40,7 @@ class _HomeRouteState extends State<HomeRoute> {
                     child: Row(
                       children: [
                         Icon(Icons.person_add),
-                        Text("添加朋友"),
+                        Text("add friends"),
                       ],
                     )),
               ))

+ 0 - 1
lib/view/login.dart

@@ -79,7 +79,6 @@ class _LoginRouteState extends State<LoginRoute> {
                   constraints: BoxConstraints.expand(height: 55.0),
                   child: ElevatedButton(
                     style: ButtonStyle(
-                      foregroundColor: MaterialStateProperty.all<Color>(Provider.of<ThemeModel>(context).theme),
                       //TODO: something wrong with text color
                       textStyle: MaterialStateProperty.all<TextStyle>(TextStyle(color: Colors.white)),
                     ),

+ 21 - 0
pubspec.lock

@@ -22,6 +22,13 @@ packages:
       url: "https://pub.flutter-io.cn"
     source: hosted
     version: "2.1.1"
+  asn1lib:
+    dependency: transitive
+    description:
+      name: asn1lib
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "1.0.2"
   async:
     dependency: transitive
     description:
@@ -211,6 +218,13 @@ packages:
       url: "https://pub.flutter-io.cn"
     source: hosted
     version: "2.0.0"
+  encrypt:
+    dependency: "direct main"
+    description:
+      name: encrypt
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "5.0.0"
   fake_async:
     dependency: transitive
     description:
@@ -497,6 +511,13 @@ packages:
       url: "https://pub.flutter-io.cn"
     source: hosted
     version: "2.0.1"
+  pointycastle:
+    dependency: transitive
+    description:
+      name: pointycastle
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "3.1.3"
   pool:
     dependency: transitive
     description:

+ 7 - 5
pubspec.yaml

@@ -25,9 +25,13 @@ dependencies:
     sdk: flutter
   flutter_localizations:
     sdk: flutter
-  fluttertoast: ^8.0.7
   provider: ^5.0.0
+  rxdart: ^0.27.1
+
   flutter_secure_storage: ^4.2.0
+  crypto: ^3.0.1
+  encrypt: ^5.0.0
+
   objectbox: ^1.0.0
   objectbox_flutter_libs: any
   # for ObjectBox Sync use this dependency instead:
@@ -36,19 +40,17 @@ dependencies:
   dio: ^4.0.0
   dio_cookie_manager: ^2.0.0
   cookie_jar: ^3.0.1
-  crypto: ^3.0.1
-  rxdart: ^0.27.1
+  web_socket_channel: ^2.1.0
 
   permission_handler: ^8.1.2
 
   lpinyin: ^2.0.3
   common_utils: ^2.0.2
-  web_socket_channel: ^2.1.0
 
   # The following adds the Cupertino Icons font to your application.
   # Use with the CupertinoIcons class for iOS style icons.
   cupertino_icons: ^1.0.2
-
+  fluttertoast: ^8.0.7
   flutter_slidable: ^0.6.0
   scrollable_positioned_list: ^0.2.0-nullsafety.0
   dash_chat: ^1.1.16