mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-01-23 18:44:10 +01:00
fix: Various multiaccount fixes
This commit is contained in:
parent
b5b3d05f01
commit
81d4f12189
@ -67,6 +67,17 @@ abstract class ClientManager {
|
|||||||
await Store().setItem(clientNamespace, jsonEncode(clientNamesList));
|
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(
|
static Client createClient(String clientName) => Client(
|
||||||
clientName,
|
clientName,
|
||||||
enableE2eeRecovery: true,
|
enableE2eeRecovery: true,
|
||||||
|
@ -63,14 +63,22 @@ class Matrix extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
||||||
int activeClient = 0;
|
int _activeClient = -1;
|
||||||
String activeBundle;
|
String activeBundle;
|
||||||
Store store = Store();
|
Store store = Store();
|
||||||
BuildContext navigatorContext;
|
BuildContext navigatorContext;
|
||||||
|
|
||||||
BackgroundPush _backgroundPush;
|
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;
|
bool get isMultiAccount => widget.clients.length > 1;
|
||||||
|
|
||||||
@ -80,20 +88,10 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||||||
String currentClientSecret;
|
String currentClientSecret;
|
||||||
RequestTokenResponse currentThreepidCreds;
|
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) {
|
void setActiveClient(Client cl) {
|
||||||
final i = widget.clients.indexWhere((c) => c == cl);
|
final i = widget.clients.indexWhere((c) => c == cl);
|
||||||
if (i != null) {
|
if (i != null) {
|
||||||
activeClient = i;
|
_activeClient = i;
|
||||||
} else {
|
} else {
|
||||||
Logs().w('Tried to set an unknown client ${cl.userID} as active');
|
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
|
c.onSyncStatus.stream
|
||||||
.where((s) => s.status == SyncStatus.error)
|
.where((s) => s.status == SyncStatus.error)
|
||||||
.listen(_reportSyncError);
|
.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
|
onKeyVerificationRequestSub[name] ??= c.onKeyVerificationRequest.stream
|
||||||
.listen((KeyVerification request) async {
|
.listen((KeyVerification request) async {
|
||||||
var hidPopup = false;
|
var hidPopup = false;
|
||||||
@ -333,6 +341,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||||||
if (state != LoginState.loggedIn) {
|
if (state != LoginState.loggedIn) {
|
||||||
_cancelSubs(c.clientName);
|
_cancelSubs(c.clientName);
|
||||||
widget.clients.remove(c);
|
widget.clients.remove(c);
|
||||||
|
ClientManager.removeClientNameFromStore(c.clientName);
|
||||||
}
|
}
|
||||||
if (loggedInWithMultipleClients && state != LoginState.loggedIn) {
|
if (loggedInWithMultipleClients && state != LoginState.loggedIn) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
Loading…
Reference in New Issue
Block a user