From c8ff9af2e3d1fafbe55b8b9e90747848fdb6cebd Mon Sep 17 00:00:00 2001 From: Sun Date: Sat, 29 May 2021 15:53:04 +0800 Subject: [PATCH] fix group join by scan qr & session readed --- lib/apps/chat/add.dart | 3 ++- lib/apps/chat/detail.dart | 1 + lib/apps/group_chat/add.dart | 16 +++------------- lib/apps/group_chat/detail.dart | 30 +++++++++++++++++------------- lib/apps/group_chat/models.dart | 2 +- lib/l10n/localizations_en.dart | 2 +- lib/l10n/localizations_zh.dart | 2 +- lib/pages/home.dart | 1 + lib/provider.dart | 4 ++++ lib/widgets/default_home_show.dart | 14 +++++++------- lib/widgets/user_info.dart | 5 +++-- src/apps/chat/layer.rs | 2 +- src/apps/group_chat/layer.rs | 2 +- src/apps/group_chat/rpc.rs | 10 ---------- src/rpc.rs | 6 ++++-- 15 files changed, 47 insertions(+), 53 deletions(-) diff --git a/lib/apps/chat/add.dart b/lib/apps/chat/add.dart index 92dff98..e84fcde 100644 --- a/lib/apps/chat/add.dart +++ b/lib/apps/chat/add.dart @@ -141,7 +141,8 @@ class _ChatAddPageState extends State { context, Icons.info, lang.info, - UserInfo(id: account.id, name: account.name, addr: Global.addr) + UserInfo(app: 'add-friend', + id: account.id, name: account.name, addr: Global.addr) ), child: Text(lang.myQrcode, style: TextStyle(fontSize: 16.0)), ), diff --git a/lib/apps/chat/detail.dart b/lib/apps/chat/detail.dart index c405ac5..5a78d96 100644 --- a/lib/apps/chat/detail.dart +++ b/lib/apps/chat/detail.dart @@ -273,6 +273,7 @@ class _ChatDetailState extends State { Icons.info, lang.friendInfo, UserInfo( + app: 'add-friend', id: 'EH' + friend.gid.toUpperCase(), name: friend.name, addr: '0x' + friend.addr) diff --git a/lib/apps/group_chat/add.dart b/lib/apps/group_chat/add.dart index 25df764..b5d1e61 100644 --- a/lib/apps/group_chat/add.dart +++ b/lib/apps/group_chat/add.dart @@ -100,6 +100,8 @@ class _GroupAddPageState extends State { _scanCallback(bool isOk, String app, List params) { Navigator.of(context).pop(); + print(app); + print(params); if (isOk && app == 'add-group' && params.length == 3) { this._joinIdController.text = params[0]; this._joinAddrController.text = params[1]; @@ -211,24 +213,12 @@ class _GroupAddPageState extends State { appBar: AppBar( title: Row( children: [ - if (!isDesktop) - GestureDetector( - onTap: () { - //context.read().requestClear(); - Navigator.pop(context); - }, - child: Container( - width: 20.0, - child: Icon(Icons.arrow_back, color: color.primary)), - ), - SizedBox(width: 15.0), Expanded( child: Text('Add Group Chat', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20.0)), ), TextButton( - onPressed: () => Navigator.push( - context, + onPressed: () => Navigator.push(context, MaterialPageRoute(builder: (context) => QRScan(callback: _scanCallback)) ), child: Text(lang.scanQr, style: TextStyle(fontSize: 16.0)), diff --git a/lib/apps/group_chat/detail.dart b/lib/apps/group_chat/detail.dart index e1cd5f4..788e14d 100644 --- a/lib/apps/group_chat/detail.dart +++ b/lib/apps/group_chat/detail.dart @@ -289,6 +289,7 @@ class _GroupChatDetailState extends State { if (value == 1) { showShadowDialog(context, Icons.info, lang.groupChat, UserInfo( + app: 'add-group', id: 'EG' + this.group.gid.toUpperCase(), name: this.group.name, addr: '0x' + this.group.addr @@ -591,18 +592,21 @@ class _MemberDrawerWidget extends StatelessWidget { const _MemberDrawerWidget({Key key, this.title}) : super(key: key); Widget _item(context, Member member, bool isOwner, Color color) { - return ListTile( - leading: member.showAvatar(), - title: Text(member.name, textAlign: TextAlign.left, style: TextStyle(fontSize: 16.0)), - trailing: Text(isOwner ? 'Owner' : (member.isManager ? 'Manager' : ''), - style: TextStyle(color: color)), - onTap: () { - Navigator.pop(context); - showShadowDialog(context, Icons.group_rounded, title, - MemberDetail(member: member, isGroupOwner: isOwner, isGroupManager: member.isManager), - 10.0, - ); - } + return Container( + height: 55.0, + child: ListTile( + leading: member.showAvatar(colorSurface: false), + title: Text(member.name, textAlign: TextAlign.left, style: TextStyle(fontSize: 16.0)), + trailing: Text(isOwner ? 'Owner' : (member.isManager ? 'Manager' : ''), + style: TextStyle(color: color)), + onTap: () { + Navigator.pop(context); + showShadowDialog(context, Icons.group_rounded, title, + MemberDetail(member: member, isGroupOwner: isOwner, isGroupManager: member.isManager), + 10.0, + ); + } + ) ); } @@ -687,7 +691,7 @@ class _MemberDetailState extends State { return Column( mainAxisSize: MainAxisSize.max, children: [ - widget.member.showAvatar(width: 100.0, colorSurface: true), + widget.member.showAvatar(width: 100.0), const SizedBox(height: 10.0), Text(widget.member.name), const SizedBox(height: 10.0), diff --git a/lib/apps/group_chat/models.dart b/lib/apps/group_chat/models.dart index 7ff8032..e1557d5 100644 --- a/lib/apps/group_chat/models.dart +++ b/lib/apps/group_chat/models.dart @@ -166,7 +166,7 @@ class Member { this.isManager = params[5]; } - Avatar showAvatar({double width = 45.0, colorSurface = false}) { + Avatar showAvatar({double width = 45.0, colorSurface = true}) { final avatar = Global.avatarPath + this.mid + '.png'; return Avatar( width: width, diff --git a/lib/l10n/localizations_en.dart b/lib/l10n/localizations_en.dart index 73b45cf..9241703 100644 --- a/lib/l10n/localizations_en.dart +++ b/lib/l10n/localizations_en.dart @@ -143,7 +143,7 @@ class AppLocalizationsEn extends AppLocalizations { @override String get myQrcode => 'My QRCode'; @override - String get qrFriend => 'Scan for friend'; + String get qrFriend => 'Scan for Add'; @override String get friendInfo => 'Friend Info'; @override diff --git a/lib/l10n/localizations_zh.dart b/lib/l10n/localizations_zh.dart index 3fad8a4..c4e002d 100644 --- a/lib/l10n/localizations_zh.dart +++ b/lib/l10n/localizations_zh.dart @@ -143,7 +143,7 @@ class AppLocalizationsZh extends AppLocalizations { @override String get myQrcode => '我的二维码'; @override - String get qrFriend => '扫二维码加好友'; + String get qrFriend => '扫二维码添加'; @override String get friendInfo => '好友信息'; @override diff --git a/lib/pages/home.dart b/lib/pages/home.dart index 6638313..3fa4d55 100644 --- a/lib/pages/home.dart +++ b/lib/pages/home.dart @@ -188,6 +188,7 @@ class _HomeListState extends State { Icons.info, lang.info, UserInfo( + app: 'add-friend', id: provider.activedAccount.id, name: provider.activedAccount.name, addr: Global.addr) diff --git a/lib/provider.dart b/lib/provider.dart index 126ac10..fb76e20 100644 --- a/lib/provider.dart +++ b/lib/provider.dart @@ -317,6 +317,10 @@ class AccountProvider extends ChangeNotifier { _sessionLast(List params) { final id = params[0]; this.sessions[id].last(params); + if (id == this.actived && !this.sessions[id].lastReaded) { + rpc.send('session-readed', [id]); + this.sessions[id].lastReaded = true; + } orderSessions(id); notifyListeners(); } diff --git a/lib/widgets/default_home_show.dart b/lib/widgets/default_home_show.dart index 4a590f9..ae57b98 100644 --- a/lib/widgets/default_home_show.dart +++ b/lib/widgets/default_home_show.dart @@ -121,13 +121,13 @@ class _SessionWidget extends StatelessWidget { overflow: TextOverflow.ellipsis, style: const TextStyle(color: Color(0xFFADB0BB), fontSize: 12.0)), ), - // if (session.isClosed) - // Container( - // margin: const EdgeInsets.only(left: 15.0, right: 20.0), - // child: Text(lang.unfriended, - // style: TextStyle(color: color.primary, fontSize: 12.0), - // ), - // ) + Container(width: 8.0, height: 8.0, + margin: const EdgeInsets.only(left: 15.0, right: 20.0), + decoration: BoxDecoration( + color: session.lastReaded ? color.background : Colors.red, + shape: BoxShape.circle + ), + ), ]), ], ), diff --git a/lib/widgets/user_info.dart b/lib/widgets/user_info.dart index 5a75516..7644a8f 100644 --- a/lib/widgets/user_info.dart +++ b/lib/widgets/user_info.dart @@ -8,14 +8,15 @@ import 'package:esse/l10n/localizations.dart'; import 'package:esse/utils/better_print.dart'; class UserInfo extends StatefulWidget { + final String app; final String id; final String name; final String addr; Map qrInfo; - UserInfo({Key key, this.id, this.name, this.addr}) : super(key: key) { + UserInfo({Key key, this.id, this.name, this.addr, this.app}) : super(key: key) { this.qrInfo = { - "app": "add-friend", + "app": this.app, "params": [this.id, this.addr, this.name], }; } diff --git a/src/apps/chat/layer.rs b/src/apps/chat/layer.rs index f736d48..d3326d4 100644 --- a/src/apps/chat/layer.rs +++ b/src/apps/chat/layer.rs @@ -325,7 +325,7 @@ impl LayerEvent { &id, &msg.datetime, &msg.content, - true, + false, )); } else { let c_db = chat_db(&layer.base, &mgid)?; diff --git a/src/apps/group_chat/layer.rs b/src/apps/group_chat/layer.rs index 981c357..e418048 100644 --- a/src/apps/group_chat/layer.rs +++ b/src/apps/group_chat/layer.rs @@ -241,7 +241,7 @@ async fn handle_event( println!("Sync: create message ok"); results .rpcs - .push(session_last(mgid, &sid, &msg.datetime, &msg.content, true)); + .push(session_last(mgid, &sid, &msg.datetime, &msg.content, false)); } } diff --git a/src/apps/group_chat/rpc.rs b/src/apps/group_chat/rpc.rs index 3a28cda..aaea990 100644 --- a/src/apps/group_chat/rpc.rs +++ b/src/apps/group_chat/rpc.rs @@ -27,16 +27,6 @@ pub(crate) fn create_result(mgid: GroupId, gid: i64, ok: bool) -> RpcParam { rpc_response(0, "group-chat-result", json!([gid, ok]), mgid) } -#[inline] -pub(crate) fn group_online(mgid: GroupId, gid: i64) -> RpcParam { - rpc_response(0, "group-chat-online", json!([gid]), mgid) -} - -#[inline] -pub(crate) fn group_offline(mgid: GroupId, fid: i64, gid: &GroupId) -> RpcParam { - rpc_response(0, "group-chat-offline", json!([fid, gid.to_hex()]), mgid) -} - #[inline] pub(crate) fn group_agree(mgid: GroupId, rid: i64, group: GroupChat) -> RpcParam { rpc_response(0, "group-chat-agree", json!([rid, group.to_rpc()]), mgid) diff --git a/src/rpc.rs b/src/rpc.rs index dc68898..78165b4 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -476,6 +476,10 @@ fn new_rpc_handler( let id = params[0].as_i64()?; let remote = GroupId::from_hex(params[1].as_str()?)?; + let group_lock = state.group.read().await; + let db = session_db(group_lock.base(), &gid)?; + Session::readed(&db, &id)?; + let mut layer_lock = state.layer.write().await; let online = layer_lock.running_mut(&gid)?.active(&remote, true); drop(layer_lock); @@ -483,8 +487,6 @@ fn new_rpc_handler( return Ok(HandleResult::rpc(json!([id, addr.to_hex()]))); } - let group_lock = state.group.read().await; - let db = session_db(group_lock.base(), &gid)?; let s = Session::get(&db, &id)?; drop(db);