Skip to content

Commit

Permalink
fix invite to group chat
Browse files Browse the repository at this point in the history
  • Loading branch information
sunhuachuang committed Apr 24, 2022
1 parent 92c7192 commit b4674ac
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 44 deletions.
12 changes: 7 additions & 5 deletions lib/apps/chat/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Friend {
String pid = '';
String name = '';
String wallet = '';
String cloud = '';
String remark = '';
bool isClosed = false;
RelativeTime time = RelativeTime();
Expand All @@ -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];
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/apps/group/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 6 additions & 7 deletions lib/widgets/qr_scan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ class _QRScanState extends State<QRScan> {
super.reassemble();
if (Platform.isAndroid) {
controller?.pauseCamera();
} else if (Platform.isIOS) {
controller?.resumeCamera();
}
controller?.resumeCamera();
}

@override
Expand Down Expand Up @@ -109,10 +110,8 @@ class _QRScanState extends State<QRScan> {
);
}

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;
Expand All @@ -122,14 +121,14 @@ class _QRScanState extends State<QRScan> {
// 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();
}
}
6 changes: 3 additions & 3 deletions lib/widgets/user_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ class _UserInfoState extends State<UserInfo> {
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)),
Expand Down
50 changes: 39 additions & 11 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/apps/group/models/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/apps/group/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ pub(crate) fn new_rpc_handler(handler: &mut RpcHandler<Global>) {
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)
Expand Down
4 changes: 2 additions & 2 deletions src/group/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl Group {
Group {
sessions: HashMap::new(),
delivery: HashMap::new(),
delivery_count: 0,
delivery_count: 1,
}
}

Expand All @@ -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) {
Expand Down
19 changes: 10 additions & 9 deletions src/group/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -223,19 +223,20 @@ impl InviteType {
pub fn deserialize(s: &str) -> Result<InviteType> {
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")),
}
}
}

0 comments on commit b4674ac

Please sign in to comment.