From b4674acb58e464b571032460605249d92a9ea970 Mon Sep 17 00:00:00 2001 From: Sun Date: Sun, 24 Apr 2022 12:00:17 +0800 Subject: [PATCH] fix invite to group chat --- lib/apps/chat/models.dart | 12 ++++---- lib/apps/group/models.dart | 4 +-- lib/session.dart | 4 +-- lib/widgets/qr_scan.dart | 13 ++++----- lib/widgets/user_info.dart | 6 ++-- pubspec.lock | 50 ++++++++++++++++++++++++++-------- src/apps/group/models/group.rs | 2 +- src/apps/group/rpc.rs | 4 +-- src/group/mod.rs | 4 +-- src/group/models.rs | 19 +++++++------ 10 files changed, 74 insertions(+), 44 deletions(-) diff --git a/lib/apps/chat/models.dart b/lib/apps/chat/models.dart index ed87780..e13b09d 100644 --- a/lib/apps/chat/models.dart +++ b/lib/apps/chat/models.dart @@ -11,6 +11,7 @@ class Friend { String pid = ''; String name = ''; String wallet = ''; + String cloud = ''; String remark = ''; bool isClosed = false; RelativeTime time = RelativeTime(); @@ -36,11 +37,12 @@ class Friend { this.pid = params[1]; this.name = params[2]; this.wallet = params[3]; - this.remark = params[4]; - this.isClosed = params[5]; - this.time = RelativeTime.fromInt(params[6]); - if (params.length == 8) { - this.online = params[7]; + this.cloud = params[4]; + this.remark = params[5]; + this.isClosed = params[6]; + this.time = RelativeTime.fromInt(params[7]); + if (params.length == 9) { + this.online = params[8]; } } } diff --git a/lib/apps/group/models.dart b/lib/apps/group/models.dart index ff0d834..a73ca5c 100644 --- a/lib/apps/group/models.dart +++ b/lib/apps/group/models.dart @@ -9,7 +9,7 @@ import 'package:esse/apps/primitives.dart'; class GroupChat { int id = 0; - String gid = ''; + int gid = 0; String addr = ''; String name = ''; bool isClosed = false; @@ -26,7 +26,7 @@ class GroupChat { this.isLocal = params[4]; Avatar showAvatar({double width = 45.0}) { - final avatar = Global.avatarPath + this.gid + '.png'; + final avatar = Global.avatarPath + "${this.gid}.png"; return Avatar(width: width, name: this.name, avatarPath: avatar); } } diff --git a/lib/session.dart b/lib/session.dart index f2f1a09..9f498ea 100644 --- a/lib/session.dart +++ b/lib/session.dart @@ -150,10 +150,10 @@ class Session { String avatar = Global.avatarPath; switch (this.type) { case SessionType.Chat: - avatar + this.pid + '.png'; + avatar = avatar + this.pid + '.png'; break; case SessionType.Group: - avatar + 'group_' + this.pid + '.png'; + avatar = avatar + 'group_' + this.pid + '.png'; break; default: break; diff --git a/lib/widgets/qr_scan.dart b/lib/widgets/qr_scan.dart index 551b30e..47f88ac 100644 --- a/lib/widgets/qr_scan.dart +++ b/lib/widgets/qr_scan.dart @@ -25,8 +25,9 @@ class _QRScanState extends State { super.reassemble(); if (Platform.isAndroid) { controller?.pauseCamera(); + } else if (Platform.isIOS) { + controller?.resumeCamera(); } - controller?.resumeCamera(); } @override @@ -109,10 +110,8 @@ class _QRScanState extends State { ); } - void _onQRViewCreated(QRViewController controller) { - setState(() { - this.controller = controller; - }); + void _onQRViewCreated(QRViewController controller) async { + this.controller = controller; controller.scannedDataStream.listen((scanData) async { if (scanData.code == null) { return; @@ -122,14 +121,14 @@ class _QRScanState extends State { // TODO show Error. return; } - await controller.pauseCamera(); + await this.controller?.pauseCamera(); widget.callback(true, qrInfo["app"], qrInfo["params"]); }); } @override void dispose() { - controller?.dispose(); + this.controller?.dispose(); super.dispose(); } } diff --git a/lib/widgets/user_info.dart b/lib/widgets/user_info.dart index e2e2d45..bbaf43f 100644 --- a/lib/widgets/user_info.dart +++ b/lib/widgets/user_info.dart @@ -84,9 +84,9 @@ class _UserInfoState extends State { foregroundColor: Colors.black, ), Container( - height: 44, - width: 44, - padding: EdgeInsets.all(2.0), + height: 40, + width: 40, + padding: EdgeInsets.all(1.0), decoration: BoxDecoration( borderRadius: BorderRadius.circular(10.0), border: Border.all(color: Color(0x40ADB0BB)), diff --git a/pubspec.lock b/pubspec.lock index 0af9d9d..c0b77fc 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -154,7 +154,7 @@ packages: name: device_info_plus url: "https://pub.dartlang.org" source: hosted - version: "3.2.2" + version: "3.2.3" device_info_plus_linux: dependency: transitive description: @@ -168,7 +168,7 @@ packages: name: device_info_plus_macos url: "https://pub.dartlang.org" source: hosted - version: "2.2.2" + version: "2.2.3" device_info_plus_platform_interface: dependency: transitive description: @@ -306,7 +306,7 @@ packages: name: flutter_inappwebview url: "https://pub.dartlang.org" source: hosted - version: "5.3.2" + version: "5.4.1" flutter_keyboard_visibility: dependency: transitive description: @@ -360,7 +360,7 @@ packages: name: flutter_native_splash url: "https://pub.dartlang.org" source: hosted - version: "2.1.2+1" + version: "2.1.6" flutter_plugin_android_lifecycle: dependency: transitive description: @@ -374,7 +374,7 @@ packages: name: flutter_quill url: "https://pub.dartlang.org" source: hosted - version: "4.1.0" + version: "4.1.3" flutter_test: dependency: "direct dev" description: flutter @@ -404,6 +404,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.3.2" + get_it: + dependency: transitive + description: + name: get_it + url: "https://pub.dartlang.org" + source: hosted + version: "7.2.0" gettext_parser: dependency: transitive description: @@ -459,6 +466,13 @@ packages: name: image_picker url: "https://pub.dartlang.org" source: hosted + version: "0.8.5" + image_picker_android: + dependency: transitive + description: + name: image_picker_android + url: "https://pub.dartlang.org" + source: hosted version: "0.8.4+11" image_picker_for_web: dependency: transitive @@ -467,6 +481,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.6" + image_picker_ios: + dependency: transitive + description: + name: image_picker_ios + url: "https://pub.dartlang.org" + source: hosted + version: "0.8.5" image_picker_platform_interface: dependency: transitive description: @@ -521,6 +542,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.4.7" + lint: + dependency: transitive + description: + name: lint + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.2" lints: dependency: transitive description: @@ -555,7 +583,7 @@ packages: name: msix url: "https://pub.dartlang.org" source: hosted - version: "3.4.1" + version: "3.5.1" nested: dependency: transitive description: @@ -945,7 +973,7 @@ packages: name: url_launcher url: "https://pub.dartlang.org" source: hosted - version: "6.0.20" + version: "6.1.0" url_launcher_android: dependency: transitive description: @@ -1015,7 +1043,7 @@ packages: name: video_player url: "https://pub.dartlang.org" source: hosted - version: "2.3.0" + version: "2.4.0" video_player_android: dependency: transitive description: @@ -1029,21 +1057,21 @@ packages: name: video_player_avfoundation url: "https://pub.dartlang.org" source: hosted - version: "2.3.1" + version: "2.3.2" video_player_platform_interface: dependency: transitive description: name: video_player_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "5.1.1" + version: "5.1.2" video_player_web: dependency: transitive description: name: video_player_web url: "https://pub.dartlang.org" source: hosted - version: "2.0.7" + version: "2.0.8" vm_service: dependency: transitive description: diff --git a/src/apps/group/models/group.rs b/src/apps/group/models/group.rs index 7433213..a4a086e 100644 --- a/src/apps/group/models/group.rs +++ b/src/apps/group/models/group.rs @@ -35,7 +35,7 @@ pub(crate) struct GroupChat { impl GroupChat { pub fn new(addr: PeerId, name: String) -> Self { let mut rng = ChaChaRng::from_entropy(); - let gid = rng.next_u64(); + let gid = rng.next_u64() >> 1; // fixed i64 Self { gid, diff --git a/src/apps/group/rpc.rs b/src/apps/group/rpc.rs index 1c960f4..76f3138 100644 --- a/src/apps/group/rpc.rs +++ b/src/apps/group/rpc.rs @@ -175,12 +175,12 @@ pub(crate) fn new_rpc_handler(handler: &mut RpcHandler) { let mut msg = crate::group::Message::new(&pid, f.id, true, m_type, raw, false); msg.insert(&chat_db)?; let event = crate::group::GroupEvent::Message(msg.hash, nm); - let tid = state.layer.write().await.delivery(msg.id); + let tid = state.group.write().await.delivery(msg.id); let data = bincode::serialize(&event).unwrap_or(vec![]); results.groups.push(SendType::Event(tid, f.pid, data)); // update session. - crate::group::update_session(&s_db, &id, &msg, &mut results); + crate::group::update_session(&s_db, &fid, &msg, &mut results); // handle group member let avatar = read_avatar(&state.base, &pid, &f.pid) diff --git a/src/group/mod.rs b/src/group/mod.rs index 77b7299..b4ae14d 100644 --- a/src/group/mod.rs +++ b/src/group/mod.rs @@ -78,7 +78,7 @@ impl Group { Group { sessions: HashMap::new(), delivery: HashMap::new(), - delivery_count: 0, + delivery_count: 1, } } @@ -92,7 +92,7 @@ impl Group { pub fn clear(&mut self) { self.sessions.clear(); self.delivery.clear(); - self.delivery_count = 0; + self.delivery_count = 1; } pub fn add(&mut self, pid: PeerId, sid: i64, fid: i64, h: i64) { diff --git a/src/group/models.rs b/src/group/models.rs index afc484d..94c689a 100644 --- a/src/group/models.rs +++ b/src/group/models.rs @@ -9,7 +9,7 @@ pub(crate) use self::request::Request; use esse_primitives::{id_from_str, id_to_str, MessageType, NetworkMessage}; use group_types::GroupChatId; use std::path::PathBuf; -use tdn::types::primitives::{HandleResult, PeerId, Result}; +use tdn::types::primitives::{HandleResult, PeerId, Result, PEER_ID_LENGTH}; use crate::apps::group::GroupChat; use crate::rpc::session_create; @@ -52,7 +52,7 @@ pub(crate) async fn from_network_message( } NetworkMessage::Invite(content) => { // check is Tmp group. - let itype = InviteType::deserialize(&content)?; + let itype = InviteType::deserialize(&content).unwrap(); match itype { InviteType::Group(gcd, addr, name) => { // 1 add group chat. @@ -223,19 +223,20 @@ impl InviteType { pub fn deserialize(s: &str) -> Result { match &s[0..3] { "0;;" => { - if s.len() < 103 { - // 16(gid) + 64(pid) + 7 - Err(anyhow!("invite invalid")) + if s.len() < 63 { + // 16(gid) + 40(pid) + 7 + Err(anyhow!("invite group invalid")) } else { + let bytes = &s[3..]; let mut gid_bytes = [0u8; 8]; - gid_bytes.copy_from_slice(&hex::decode(&s[3..19])?); + gid_bytes.copy_from_slice(&hex::decode(&bytes[0..16])?); let gid = GroupChatId::from_le_bytes(gid_bytes); - let addr = PeerId::from_hex(&s[22..86])?; - let name = s[88..].to_owned(); + let addr = PeerId::from_hex(&bytes[18..(PEER_ID_LENGTH * 2 + 18)])?; + let name = bytes[(PEER_ID_LENGTH * 2 + 20)..].to_owned(); Ok(InviteType::Group(gid, addr, name)) } } - _ => Err(anyhow!("invite invalid")), + _ => Err(anyhow!("invite type invalid")), } } }