diff --git a/lib/apps/chat/detail.dart b/lib/apps/chat/detail.dart index be8b047..06ab387 100644 --- a/lib/apps/chat/detail.dart +++ b/lib/apps/chat/detail.dart @@ -14,7 +14,7 @@ import 'package:esse/widgets/chat_message.dart'; import 'package:esse/widgets/show_contact.dart'; import 'package:esse/global.dart'; import 'package:esse/provider.dart'; -import 'package:esse/session.dart'; +import 'package:esse/session.dart' show SessionType, OnlineType; import 'package:esse/apps/primitives.dart'; import 'package:esse/apps/chat/models.dart'; @@ -53,6 +53,12 @@ class _ChatDetailState extends State { }); } + @override + void deactivate() { + context.read().clearActivedSession(SessionType.Chat); + super.deactivate(); + } + _generateRecordPath() { this._recordName = DateTime.now().millisecondsSinceEpoch.toString() + '_' + diff --git a/lib/apps/group_chat/detail.dart b/lib/apps/group_chat/detail.dart index 6bcfbe0..0b0790d 100644 --- a/lib/apps/group_chat/detail.dart +++ b/lib/apps/group_chat/detail.dart @@ -18,6 +18,7 @@ import 'package:esse/widgets/show_contact.dart'; import 'package:esse/rpc.dart'; import 'package:esse/global.dart'; import 'package:esse/provider.dart'; +import 'package:esse/session.dart' show SessionType; import 'package:esse/apps/primitives.dart'; import 'package:esse/apps/group_chat/models.dart'; @@ -57,6 +58,12 @@ class _GroupChatDetailState extends State { }); } + @override + void deactivate() { + context.read().clearActivedSession(SessionType.Group); + super.deactivate(); + } + _generateRecordPath() { this._recordName = DateTime.now().millisecondsSinceEpoch.toString() + '_' + diff --git a/lib/provider.dart b/lib/provider.dart index dd0f807..1152293 100644 --- a/lib/provider.dart +++ b/lib/provider.dart @@ -207,6 +207,16 @@ class AccountProvider extends ChangeNotifier { notifyListeners(); } + clearActivedSession(SessionType type) { + if (this.activedSession.type == type && this.actived > 0) { + rpc.send('session-suspend', [this.actived, this.activedSession.gid, + this.activedSession.type == SessionType.Group] + ); + this.actived = 0; + this.coreShowWidget = DefaultCoreShow(); + } + } + updateActivedSession(int id, [SessionType type, int fid]) { if (fid != null && fid > 0) { for (int k in this.sessions.keys) { @@ -221,11 +231,9 @@ class AccountProvider extends ChangeNotifier { if (id > 0) { if (this.actived != id && this.actived > 0) { - bool must = false; - if (this.activedSession.type == SessionType.Group) { - must = true; - } - rpc.send('session-suspend', [this.actived, this.activedSession.gid, must]); + rpc.send('session-suspend', [this.actived, this.activedSession.gid, + this.activedSession.type == SessionType.Group] + ); } this.actived = id; this.activedSession.lastReaded = true;