mirror of
https://github.com/krille-chan/fluffychat
synced 2024-09-10 13:05:11 +00:00
fix: Various multiaccount fixes
This commit is contained in:
parent
672b2abc98
commit
f072d6ae20
2 changed files with 33 additions and 13 deletions
|
@ -67,6 +67,17 @@ abstract class ClientManager {
|
|||
await Store().setItem(clientNamespace, jsonEncode(clientNamesList));
|
||||
}
|
||||
|
||||
static Future<void> removeClientNameFromStore(String clientName) async {
|
||||
final clientNamesList = <String>[];
|
||||
final rawClientNames = await Store().getItem(clientNamespace);
|
||||
if (rawClientNames != null) {
|
||||
final stored = (jsonDecode(rawClientNames) as List).cast<String>();
|
||||
clientNamesList.addAll(stored);
|
||||
}
|
||||
clientNamesList.remove(clientName);
|
||||
await Store().setItem(clientNamespace, jsonEncode(clientNamesList));
|
||||
}
|
||||
|
||||
static Client createClient(String clientName) => Client(
|
||||
clientName,
|
||||
enableE2eeRecovery: true,
|
||||
|
|
|
@ -63,14 +63,22 @@ class Matrix extends StatefulWidget {
|
|||
}
|
||||
|
||||
class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
||||
int activeClient = 0;
|
||||
int _activeClient = -1;
|
||||
String activeBundle;
|
||||
Store store = Store();
|
||||
BuildContext navigatorContext;
|
||||
|
||||
BackgroundPush _backgroundPush;
|
||||
|
||||
Client get client => widget.clients[_safeActiveClient];
|
||||
Client get client {
|
||||
if (widget.clients.isEmpty) {
|
||||
widget.clients.add(getLoginClient());
|
||||
}
|
||||
if (_activeClient < 0 || _activeClient >= widget.clients.length) {
|
||||
return currentBundle.first;
|
||||
}
|
||||
return widget.clients[_activeClient];
|
||||
}
|
||||
|
||||
bool get isMultiAccount => widget.clients.length > 1;
|
||||
|
||||
|
@ -80,20 +88,10 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
String currentClientSecret;
|
||||
RequestTokenResponse currentThreepidCreds;
|
||||
|
||||
int get _safeActiveClient {
|
||||
if (widget.clients.isEmpty) {
|
||||
widget.clients.add(getLoginClient());
|
||||
}
|
||||
if (activeClient < 0 || activeClient >= widget.clients.length) {
|
||||
return 0;
|
||||
}
|
||||
return activeClient;
|
||||
}
|
||||
|
||||
void setActiveClient(Client cl) {
|
||||
final i = widget.clients.indexWhere((c) => c == cl);
|
||||
if (i != null) {
|
||||
activeClient = i;
|
||||
_activeClient = i;
|
||||
} else {
|
||||
Logs().w('Tried to set an unknown client ${cl.userID} as active');
|
||||
}
|
||||
|
@ -313,6 +311,16 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
c.onSyncStatus.stream
|
||||
.where((s) => s.status == SyncStatus.error)
|
||||
.listen(_reportSyncError);
|
||||
onRoomKeyRequestSub[name] ??=
|
||||
c.onRoomKeyRequest.stream.listen((RoomKeyRequest request) async {
|
||||
if (widget.clients.any((cl) =>
|
||||
cl.userID == request.requestingDevice.userId &&
|
||||
cl.identityKey == request.requestingDevice.curve25519Key)) {
|
||||
Logs().i(
|
||||
'[Key Request] Request is from one of our own clients, forwarding the key...');
|
||||
await request.forwardKey();
|
||||
}
|
||||
});
|
||||
onKeyVerificationRequestSub[name] ??= c.onKeyVerificationRequest.stream
|
||||
.listen((KeyVerification request) async {
|
||||
var hidPopup = false;
|
||||
|
@ -333,6 +341,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
if (state != LoginState.loggedIn) {
|
||||
_cancelSubs(c.clientName);
|
||||
widget.clients.remove(c);
|
||||
ClientManager.removeClientNameFromStore(c.clientName);
|
||||
}
|
||||
if (loggedInWithMultipleClients && state != LoginState.loggedIn) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
|
|
Loading…
Reference in a new issue