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> { @@ -141,7 +141,8 @@ class _ChatAddPageState extends State<ChatAddPage> {
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)),
),

1
lib/apps/chat/detail.dart

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

16
lib/apps/group_chat/add.dart

@ -100,6 +100,8 @@ class _GroupAddPageState extends State<GroupAddPage> { @@ -100,6 +100,8 @@ class _GroupAddPageState extends State<GroupAddPage> {
_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<GroupAddPage> { @@ -211,24 +213,12 @@ class _GroupAddPageState extends State<GroupAddPage> {
appBar: AppBar(
title: Row(
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(
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)),

30
lib/apps/group_chat/detail.dart

@ -289,6 +289,7 @@ class _GroupChatDetailState extends State<GroupChatDetail> { @@ -289,6 +289,7 @@ class _GroupChatDetailState extends State<GroupChatDetail> {
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 { @@ -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<MemberDetail> { @@ -687,7 +691,7 @@ class _MemberDetailState extends State<MemberDetail> {
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),

2
lib/apps/group_chat/models.dart

@ -166,7 +166,7 @@ class Member { @@ -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,

2
lib/l10n/localizations_en.dart

@ -143,7 +143,7 @@ class AppLocalizationsEn extends AppLocalizations { @@ -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

2
lib/l10n/localizations_zh.dart

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

1
lib/pages/home.dart

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

4
lib/provider.dart

@ -317,6 +317,10 @@ class AccountProvider extends ChangeNotifier { @@ -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();
}

14
lib/widgets/default_home_show.dart

@ -121,13 +121,13 @@ class _SessionWidget extends StatelessWidget { @@ -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
),
),
]),
],
),

5
lib/widgets/user_info.dart

@ -8,14 +8,15 @@ import 'package:esse/l10n/localizations.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],
};
}

2
src/apps/chat/layer.rs

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

2
src/apps/group_chat/layer.rs

@ -241,7 +241,7 @@ async fn handle_event( @@ -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));
}
}

10
src/apps/group_chat/rpc.rs

@ -27,16 +27,6 @@ pub(crate) fn create_result(mgid: GroupId, gid: i64, ok: bool) -> RpcParam { @@ -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)

6
src/rpc.rs

@ -476,6 +476,10 @@ fn new_rpc_handler( @@ -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( @@ -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);

Loading…
Cancel
Save