Soru/moor

This commit is contained in:
Sorunome 2020-05-13 13:58:59 +00:00 committed by Christian Pauly
commit f594c7005d
55 changed files with 1034 additions and 1133 deletions

View file

@ -24,14 +24,17 @@ class Matrix extends StatefulWidget {
final Client client;
Matrix({this.child, this.clientName, this.client, Key key}) : super(key: key);
final Store store;
Matrix({this.child, this.clientName, this.client, this.store, Key key})
: super(key: key);
@override
MatrixState createState() => MatrixState();
/// Returns the (nearest) Client instance of your application.
static MatrixState of(BuildContext context) {
MatrixState newState =
var newState =
(context.dependOnInheritedWidgetOfExactType<_InheritedMatrix>()).data;
newState.context = FirebaseController.context = context;
return newState;
@ -40,6 +43,8 @@ class Matrix extends StatefulWidget {
class MatrixState extends State<Matrix> {
Client client;
Store store;
@override
BuildContext context;
Map<String, dynamic> get shareContent => _shareContent;
@ -62,16 +67,15 @@ class MatrixState extends State<Matrix> {
void clean() async {
if (!kIsWeb) return;
final LocalStorage storage = LocalStorage('LocalStorage');
final storage = LocalStorage('LocalStorage');
await storage.ready;
await storage.deleteItem(widget.clientName);
}
void _initWithStore() async {
Future<LoginState> initLoginState = client.onLoginStateChanged.stream.first;
client.storeAPI = kIsWeb ? Store(client) : ExtendedStore(client);
debugPrint(
"[Store] Store is extended: ${client.storeAPI.extended.toString()}");
var initLoginState = client.onLoginStateChanged.stream.first;
client.database = await getDatabase(client, store);
client.connect();
if (await initLoginState == LoginState.logged && !kIsWeb) {
await FirebaseController.setupFirebase(
client,
@ -81,14 +85,14 @@ class MatrixState extends State<Matrix> {
}
Map<String, dynamic> getAuthByPassword(String password, String session) => {
"type": "m.login.password",
"identifier": {
"type": "m.id.user",
"user": client.userID,
'type': 'm.login.password',
'identifier': {
'type': 'm.id.user',
'user': client.userID,
},
"user": client.userID,
"password": password,
"session": session,
'user': client.userID,
'password': password,
'session': session,
};
StreamSubscription onRoomKeyRequestSub;
@ -151,8 +155,9 @@ class MatrixState extends State<Matrix> {
@override
void initState() {
store = widget.store ?? Store();
if (widget.client == null) {
debugPrint("[Matrix] Init matrix client");
debugPrint('[Matrix] Init matrix client');
client = Client(widget.clientName, debug: false);
onJitsiCallSub ??= client.onEvent.stream
.where((e) =>
@ -163,12 +168,12 @@ class MatrixState extends State<Matrix> {
.listen(onJitsiCall);
onRoomKeyRequestSub ??=
client.onRoomKeyRequest.stream.listen((RoomKeyRequest request) async {
final Room room = request.room;
final User sender = room.getUserByMXIDSync(request.sender);
final room = request.room;
final sender = room.getUserByMXIDSync(request.sender);
if (await SimpleDialogs(context).askConfirmation(
titleText: L10n.of(context).requestToReadOlderMessages,
contentText:
"${sender.id}\n\n${L10n.of(context).device}:\n${request.requestingDevice.deviceId}\n\n${L10n.of(context).identity}:\n${request.requestingDevice.curve25519Key.beautified}",
'${sender.id}\n\n${L10n.of(context).device}:\n${request.requestingDevice.deviceId}\n\n${L10n.of(context).identity}:\n${request.requestingDevice.curve25519Key.beautified}',
confirmText: L10n.of(context).verify,
cancelText: L10n.of(context).deny,
)) {
@ -178,20 +183,21 @@ class MatrixState extends State<Matrix> {
_initWithStore();
} else {
client = widget.client;
client.connect();
}
if (client.storeAPI != null) {
client.storeAPI
.getItem("chat.fluffy.jitsi_instance")
if (store != null) {
store
.getItem('chat.fluffy.jitsi_instance')
.then((final instance) => jitsiInstance = instance ?? jitsiInstance);
client.storeAPI.getItem("chat.fluffy.wallpaper").then((final path) async {
store.getItem('chat.fluffy.wallpaper').then((final path) async {
if (path == null) return;
final file = File(path);
if (await file.exists()) {
wallpaper = file;
}
});
client.storeAPI.getItem("chat.fluffy.renderHtml").then((final render) async {
renderHtml = render == "1";
store.getItem('chat.fluffy.renderHtml').then((final render) async {
renderHtml = render == '1';
});
}
super.initState();
@ -221,12 +227,11 @@ class _InheritedMatrix extends InheritedWidget {
@override
bool updateShouldNotify(_InheritedMatrix old) {
bool update = old.data.client.accessToken != this.data.client.accessToken ||
old.data.client.userID != this.data.client.userID ||
old.data.client.matrixVersions != this.data.client.matrixVersions ||
old.data.client.deviceID != this.data.client.deviceID ||
old.data.client.deviceName != this.data.client.deviceName ||
old.data.client.homeserver != this.data.client.homeserver;
var update = old.data.client.accessToken != data.client.accessToken ||
old.data.client.userID != data.client.userID ||
old.data.client.deviceID != data.client.deviceID ||
old.data.client.deviceName != data.client.deviceName ||
old.data.client.homeserver != data.client.homeserver;
return update;
}
}