Browse Source

fix group join by scan qr & session readed

pull/18/head
Sun 4 years ago
parent
commit
c8ff9af2e3
  1. 3
      lib/apps/chat/add.dart
  2. 1
      lib/apps/chat/detail.dart
  3. 16
      lib/apps/group_chat/add.dart
  4. 30
      lib/apps/group_chat/detail.dart
  5. 2
      lib/apps/group_chat/models.dart
  6. 2
      lib/l10n/localizations_en.dart
  7. 2
      lib/l10n/localizations_zh.dart
  8. 1
      lib/pages/home.dart
  9. 4
      lib/provider.dart
  10. 14
      lib/widgets/default_home_show.dart
  11. 5
      lib/widgets/user_info.dart
  12. 2
      src/apps/chat/layer.rs
  13. 2
      src/apps/group_chat/layer.rs
  14. 10
      src/apps/group_chat/rpc.rs
  15. 6
      src/rpc.rs

3
lib/apps/chat/add.dart

@ -141,7 +141,8 @@ class _ChatAddPageState extends State<ChatAddPage> {
context, context,
Icons.info, Icons.info,
lang.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)), child: Text(lang.myQrcode, style: TextStyle(fontSize: 16.0)),
), ),

1
lib/apps/chat/detail.dart

@ -273,6 +273,7 @@ class _ChatDetailState extends State<ChatDetail> {
Icons.info, Icons.info,
lang.friendInfo, lang.friendInfo,
UserInfo( UserInfo(
app: 'add-friend',
id: 'EH' + friend.gid.toUpperCase(), id: 'EH' + friend.gid.toUpperCase(),
name: friend.name, name: friend.name,
addr: '0x' + friend.addr) addr: '0x' + friend.addr)

16
lib/apps/group_chat/add.dart

@ -100,6 +100,8 @@ class _GroupAddPageState extends State<GroupAddPage> {
_scanCallback(bool isOk, String app, List params) { _scanCallback(bool isOk, String app, List params) {
Navigator.of(context).pop(); Navigator.of(context).pop();
print(app);
print(params);
if (isOk && app == 'add-group' && params.length == 3) { if (isOk && app == 'add-group' && params.length == 3) {
this._joinIdController.text = params[0]; this._joinIdController.text = params[0];
this._joinAddrController.text = params[1]; this._joinAddrController.text = params[1];
@ -211,24 +213,12 @@ class _GroupAddPageState extends State<GroupAddPage> {
appBar: AppBar( appBar: AppBar(
title: Row( title: Row(
children: [ children: [
if (!isDesktop)
GestureDetector(
onTap: () {
//context.read<ChatProvider>().requestClear();
Navigator.pop(context);
},
child: Container(
width: 20.0,
child: Icon(Icons.arrow_back, color: color.primary)),
),
SizedBox(width: 15.0),
Expanded( Expanded(
child: Text('Add Group Chat', child: Text('Add Group Chat',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20.0)), style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20.0)),
), ),
TextButton( TextButton(
onPressed: () => Navigator.push( onPressed: () => Navigator.push(context,
context,
MaterialPageRoute(builder: (context) => QRScan(callback: _scanCallback)) MaterialPageRoute(builder: (context) => QRScan(callback: _scanCallback))
), ),
child: Text(lang.scanQr, style: TextStyle(fontSize: 16.0)), child: Text(lang.scanQr, style: TextStyle(fontSize: 16.0)),

30
lib/apps/group_chat/detail.dart

@ -289,6 +289,7 @@ class _GroupChatDetailState extends State<GroupChatDetail> {
if (value == 1) { if (value == 1) {
showShadowDialog(context, Icons.info, lang.groupChat, showShadowDialog(context, Icons.info, lang.groupChat,
UserInfo( UserInfo(
app: 'add-group',
id: 'EG' + this.group.gid.toUpperCase(), id: 'EG' + this.group.gid.toUpperCase(),
name: this.group.name, name: this.group.name,
addr: '0x' + this.group.addr addr: '0x' + this.group.addr
@ -591,18 +592,21 @@ class _MemberDrawerWidget extends StatelessWidget {
const _MemberDrawerWidget({Key key, this.title}) : super(key: key); const _MemberDrawerWidget({Key key, this.title}) : super(key: key);
Widget _item(context, Member member, bool isOwner, Color color) { Widget _item(context, Member member, bool isOwner, Color color) {
return ListTile( return Container(
leading: member.showAvatar(), height: 55.0,
title: Text(member.name, textAlign: TextAlign.left, style: TextStyle(fontSize: 16.0)), child: ListTile(
trailing: Text(isOwner ? 'Owner' : (member.isManager ? 'Manager' : ''), leading: member.showAvatar(colorSurface: false),
style: TextStyle(color: color)), title: Text(member.name, textAlign: TextAlign.left, style: TextStyle(fontSize: 16.0)),
onTap: () { trailing: Text(isOwner ? 'Owner' : (member.isManager ? 'Manager' : ''),
Navigator.pop(context); style: TextStyle(color: color)),
showShadowDialog(context, Icons.group_rounded, title, onTap: () {
MemberDetail(member: member, isGroupOwner: isOwner, isGroupManager: member.isManager), Navigator.pop(context);
10.0, showShadowDialog(context, Icons.group_rounded, title,
); MemberDetail(member: member, isGroupOwner: isOwner, isGroupManager: member.isManager),
} 10.0,
);
}
)
); );
} }
@ -687,7 +691,7 @@ class _MemberDetailState extends State<MemberDetail> {
return Column( return Column(
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: [ children: [
widget.member.showAvatar(width: 100.0, colorSurface: true), widget.member.showAvatar(width: 100.0),
const SizedBox(height: 10.0), const SizedBox(height: 10.0),
Text(widget.member.name), Text(widget.member.name),
const SizedBox(height: 10.0), const SizedBox(height: 10.0),

2
lib/apps/group_chat/models.dart

@ -166,7 +166,7 @@ class Member {
this.isManager = params[5]; 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'; final avatar = Global.avatarPath + this.mid + '.png';
return Avatar( return Avatar(
width: width, width: width,

2
lib/l10n/localizations_en.dart

@ -143,7 +143,7 @@ class AppLocalizationsEn extends AppLocalizations {
@override @override
String get myQrcode => 'My QRCode'; String get myQrcode => 'My QRCode';
@override @override
String get qrFriend => 'Scan for friend'; String get qrFriend => 'Scan for Add';
@override @override
String get friendInfo => 'Friend Info'; String get friendInfo => 'Friend Info';
@override @override

2
lib/l10n/localizations_zh.dart

@ -143,7 +143,7 @@ class AppLocalizationsZh extends AppLocalizations {
@override @override
String get myQrcode => '我的二维码'; String get myQrcode => '我的二维码';
@override @override
String get qrFriend => '扫二维码加好友'; String get qrFriend => '扫二维码';
@override @override
String get friendInfo => '好友信息'; String get friendInfo => '好友信息';
@override @override

1
lib/pages/home.dart

@ -188,6 +188,7 @@ class _HomeListState extends State<HomeList> {
Icons.info, Icons.info,
lang.info, lang.info,
UserInfo( UserInfo(
app: 'add-friend',
id: provider.activedAccount.id, id: provider.activedAccount.id,
name: provider.activedAccount.name, name: provider.activedAccount.name,
addr: Global.addr) addr: Global.addr)

4
lib/provider.dart

@ -317,6 +317,10 @@ class AccountProvider extends ChangeNotifier {
_sessionLast(List params) { _sessionLast(List params) {
final id = params[0]; final id = params[0];
this.sessions[id].last(params); 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); orderSessions(id);
notifyListeners(); notifyListeners();
} }

14
lib/widgets/default_home_show.dart

@ -121,13 +121,13 @@ class _SessionWidget extends StatelessWidget {
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: const TextStyle(color: Color(0xFFADB0BB), fontSize: 12.0)), style: const TextStyle(color: Color(0xFFADB0BB), fontSize: 12.0)),
), ),
// if (session.isClosed) Container(width: 8.0, height: 8.0,
// Container( margin: const EdgeInsets.only(left: 15.0, right: 20.0),
// margin: const EdgeInsets.only(left: 15.0, right: 20.0), decoration: BoxDecoration(
// child: Text(lang.unfriended, color: session.lastReaded ? color.background : Colors.red,
// style: TextStyle(color: color.primary, fontSize: 12.0), shape: BoxShape.circle
// ), ),
// ) ),
]), ]),
], ],
), ),

5
lib/widgets/user_info.dart

@ -8,14 +8,15 @@ import 'package:esse/l10n/localizations.dart';
import 'package:esse/utils/better_print.dart'; import 'package:esse/utils/better_print.dart';
class UserInfo extends StatefulWidget { class UserInfo extends StatefulWidget {
final String app;
final String id; final String id;
final String name; final String name;
final String addr; final String addr;
Map qrInfo; 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 = { this.qrInfo = {
"app": "add-friend", "app": this.app,
"params": [this.id, this.addr, this.name], "params": [this.id, this.addr, this.name],
}; };
} }

2
src/apps/chat/layer.rs

@ -325,7 +325,7 @@ impl LayerEvent {
&id, &id,
&msg.datetime, &msg.datetime,
&msg.content, &msg.content,
true, false,
)); ));
} else { } else {
let c_db = chat_db(&layer.base, &mgid)?; let c_db = chat_db(&layer.base, &mgid)?;

2
src/apps/group_chat/layer.rs

@ -241,7 +241,7 @@ async fn handle_event(
println!("Sync: create message ok"); println!("Sync: create message ok");
results results
.rpcs .rpcs
.push(session_last(mgid, &sid, &msg.datetime, &msg.content, true)); .push(session_last(mgid, &sid, &msg.datetime, &msg.content, false));
} }
} }

10
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) 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] #[inline]
pub(crate) fn group_agree(mgid: GroupId, rid: i64, group: GroupChat) -> RpcParam { pub(crate) fn group_agree(mgid: GroupId, rid: i64, group: GroupChat) -> RpcParam {
rpc_response(0, "group-chat-agree", json!([rid, group.to_rpc()]), mgid) rpc_response(0, "group-chat-agree", json!([rid, group.to_rpc()]), mgid)

6
src/rpc.rs

@ -476,6 +476,10 @@ fn new_rpc_handler(
let id = params[0].as_i64()?; let id = params[0].as_i64()?;
let remote = GroupId::from_hex(params[1].as_str()?)?; 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 mut layer_lock = state.layer.write().await;
let online = layer_lock.running_mut(&gid)?.active(&remote, true); let online = layer_lock.running_mut(&gid)?.active(&remote, true);
drop(layer_lock); drop(layer_lock);
@ -483,8 +487,6 @@ fn new_rpc_handler(
return Ok(HandleResult::rpc(json!([id, addr.to_hex()]))); 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)?; let s = Session::get(&db, &id)?;
drop(db); drop(db);

Loading…
Cancel
Save