Compare commits
No commits in common. "1aa73bbd7e03e660d2a5c9a203513dc0edaa9593" and "3728172844e1e16e4983f6192a96786c75aebc48" have entirely different histories.
1aa73bbd7e
...
3728172844
|
@ -24,17 +24,23 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
loggingIn = true;
|
loggingIn = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
final provider = Provider.of<ZenithClientProvider>(context, listen: false);
|
|
||||||
final client = Client("zenith");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
final provider =
|
||||||
|
Provider.of<ZenithClientProvider>(context, listen: false);
|
||||||
|
final client = Client("zenith");
|
||||||
await client.checkHomeserver(Uri.parse(serverController.text));
|
await client.checkHomeserver(Uri.parse(serverController.text));
|
||||||
await client.login(
|
final result = await client.login(
|
||||||
LoginType.mLoginPassword,
|
LoginType.mLoginPassword,
|
||||||
password: passwordController.text,
|
password: passwordController.text,
|
||||||
identifier: AuthenticationUserIdentifier(user: usernameController.text),
|
identifier: AuthenticationUserIdentifier(user: usernameController.text),
|
||||||
refreshToken: true,
|
|
||||||
);
|
);
|
||||||
|
provider.setClient(client);
|
||||||
|
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
prefs.setString("homeserver", serverController.text);
|
||||||
|
prefs.setString("username", usernameController.text);
|
||||||
|
prefs.setString("accessToken", result.accessToken);
|
||||||
|
prefs.setString("refreshToken", result.refreshToken ?? "");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
print(error);
|
print(error);
|
||||||
setState(() {
|
setState(() {
|
||||||
|
@ -54,12 +60,6 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
provider.setClient(client);
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
prefs.setString("homeserver", serverController.text);
|
|
||||||
prefs.setString("username", usernameController.text);
|
|
||||||
prefs.setString("password", passwordController.text);
|
|
||||||
|
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
Navigator.pushAndRemoveUntil(
|
Navigator.pushAndRemoveUntil(
|
||||||
context,
|
context,
|
||||||
|
@ -81,7 +81,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
title: const Text("Login"),
|
title: const Text("Login"),
|
||||||
),
|
),
|
||||||
body: Padding(
|
body: Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
|
|
@ -44,24 +44,22 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
final homeserver = prefs.getString("homeserver");
|
final homeserver = prefs.getString("homeserver");
|
||||||
final username = prefs.getString("username");
|
final username = prefs.getString("username");
|
||||||
final password = prefs.getString("password");
|
final accessToken = prefs.getString("accessToken");
|
||||||
|
final refreshToken = prefs.getString("refreshToken");
|
||||||
|
|
||||||
if (homeserver == null || username == null || password == null) return;
|
if (homeserver == null || username == null || accessToken == null) return;
|
||||||
|
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
final provider = Provider.of<ZenithClientProvider>(context, listen: false);
|
final provider = Provider.of<ZenithClientProvider>(context, listen: false);
|
||||||
final client = Client("zenith");
|
final client = Client("zenith");
|
||||||
provider.setClient(client);
|
|
||||||
setState(() {
|
|
||||||
showRooms = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.checkHomeserver(Uri.parse(homeserver));
|
await client.checkHomeserver(Uri.parse(homeserver));
|
||||||
if (!client.isLogged())
|
await client.login(LoginType.mLoginToken, token: accessToken);
|
||||||
await client.login(LoginType.mLoginPassword,
|
provider.setClient(client);
|
||||||
password: password,
|
setState(() {
|
||||||
identifier: AuthenticationUserIdentifier(user: username));
|
showRooms = true;
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
print(error);
|
print(error);
|
||||||
setState(() {
|
setState(() {
|
||||||
|
@ -78,19 +76,6 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (errorMessage.isNotEmpty)
|
|
||||||
return Column(
|
|
||||||
children: [
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
errorMessage = "";
|
|
||||||
});
|
|
||||||
},
|
|
||||||
child: const Text("Clear")),
|
|
||||||
ErrorWidget(errorMessage),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
if (showRooms)
|
if (showRooms)
|
||||||
return const RoomsPage();
|
return const RoomsPage();
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:file_picker/file_picker.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
|
@ -36,16 +34,6 @@ class _RoomPageState extends State<RoomPage> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAvatar() async {
|
|
||||||
final participants = widget.room.getParticipants();
|
|
||||||
final picked = await FilePicker.platform.pickFiles(type: FileType.image);
|
|
||||||
if (picked == null) return;
|
|
||||||
final file = File(picked.files.single.path!);
|
|
||||||
final bytes = await file.readAsBytes();
|
|
||||||
final uri = await widget.room.client.uploadContent(bytes);
|
|
||||||
await widget.room.client.setAvatarUrl(participants[0].id, uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
|
@ -66,9 +54,10 @@ class _RoomPageState extends State<RoomPage> {
|
||||||
itemCount: messages?.length,
|
itemCount: messages?.length,
|
||||||
reverse: true,
|
reverse: true,
|
||||||
itemBuilder: (context, index) => ListTile(
|
itemBuilder: (context, index) => ListTile(
|
||||||
title: Text(
|
title: Text(messages![index]
|
||||||
messages![index].senderFromMemoryOrFallback.displayName ??
|
.senderFromMemoryOrFallback
|
||||||
""),
|
.displayName
|
||||||
|
.toString()),
|
||||||
subtitle: Text(messages![index].body),
|
subtitle: Text(messages![index].body),
|
||||||
leading:
|
leading:
|
||||||
messages![index].senderFromMemoryOrFallback.avatarUrl !=
|
messages![index].senderFromMemoryOrFallback.avatarUrl !=
|
||||||
|
@ -85,12 +74,11 @@ class _RoomPageState extends State<RoomPage> {
|
||||||
),
|
),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: chatController,
|
controller: chatController,
|
||||||
textCapitalization: TextCapitalization.sentences,
|
|
||||||
textInputAction: TextInputAction.send,
|
|
||||||
decoration: const InputDecoration(hintText: 'Message'),
|
decoration: const InputDecoration(hintText: 'Message'),
|
||||||
onFieldSubmitted: (value) async {
|
onFieldSubmitted: (value) async {
|
||||||
chatController.text = '';
|
print("Sending text event $value to room ${widget.room.id}...");
|
||||||
await widget.room.sendTextEvent(value);
|
await widget.room.sendTextEvent(value);
|
||||||
|
chatController.text = '';
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
@ -101,18 +89,18 @@ class _RoomPageState extends State<RoomPage> {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||||
title: Text(widget.room
|
title: Text(widget.room.getLocalizedDisplayname()),
|
||||||
.getLocalizedDisplayname()
|
|
||||||
.replaceFirst(RegExp("Group with "), "")),
|
|
||||||
actions: [
|
|
||||||
IconButton(onPressed: setAvatar, icon: const Icon(Icons.image))
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
body: Padding(
|
body: Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: getChildren(),
|
children: getChildren(),
|
||||||
)),
|
)),
|
||||||
|
floatingActionButton: FloatingActionButton(
|
||||||
|
onPressed: sendMessage,
|
||||||
|
tooltip: 'Send message',
|
||||||
|
child: const Icon(Icons.send),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,22 +28,6 @@ class _RoomsPageState extends State<RoomsPage> {
|
||||||
context, MaterialPageRoute(builder: (context) => RoomPage(room: room)));
|
context, MaterialPageRoute(builder: (context) => RoomPage(room: room)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void fixNames(Client client) async {
|
|
||||||
final rooms = client.rooms
|
|
||||||
.where((element) =>
|
|
||||||
element.getLocalizedDisplayname().contains("Group with"))
|
|
||||||
.toList();
|
|
||||||
for (final room in rooms) {
|
|
||||||
print("Setting power level to 100...");
|
|
||||||
final result = await room.setPower(client.userID!, 100);
|
|
||||||
print("Result=$result");
|
|
||||||
print("Fixing ${room.getLocalizedDisplayname()}...");
|
|
||||||
await room.setName(
|
|
||||||
room.getLocalizedDisplayname().replaceAll(RegExp("Group with"), ""));
|
|
||||||
}
|
|
||||||
print("Fixed all.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
@ -94,45 +78,33 @@ class _RoomsPageState extends State<RoomsPage> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: Padding(
|
body: Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
child: Center(child: Consumer<ZenithClientProvider>(
|
child: Center(child: Consumer<ZenithClientProvider>(
|
||||||
builder: (context, provider, child) {
|
builder: (context, provider, child) {
|
||||||
print(provider.client.rooms
|
provider.client.roomsLoading?.then((value) {
|
||||||
.where((element) =>
|
|
||||||
element.getLocalizedDisplayname().contains("Group with"))
|
|
||||||
.length);
|
|
||||||
|
|
||||||
provider.client.onRoomState.stream.listen((event) {
|
|
||||||
setState(() {
|
setState(() {
|
||||||
loadingRooms = false;
|
loadingRooms = false;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return ElevatedButton(
|
if (provider.client.roomsLoading != null && loadingRooms)
|
||||||
onPressed: () => fixNames(provider.client),
|
|
||||||
child: const Text("Fix names"));
|
|
||||||
|
|
||||||
if (provider.client.rooms.isEmpty)
|
|
||||||
return const CircularProgressIndicator();
|
return const CircularProgressIndicator();
|
||||||
else
|
else
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
itemCount: provider.client.rooms.length,
|
itemCount: provider.client.rooms.length,
|
||||||
itemBuilder: (context, index) => ListTile(
|
itemBuilder: (context, index) => ListTile(
|
||||||
title: Text(provider.client.rooms[index]
|
title: Text(provider.client.rooms[index]
|
||||||
.getLocalizedDisplayname()
|
.getLocalizedDisplayname()),
|
||||||
.replaceFirst(RegExp("Group with "), "")),
|
|
||||||
leading: CircleAvatar(
|
|
||||||
foregroundImage: NetworkImage(provider
|
|
||||||
.client.rooms[index].avatar
|
|
||||||
?.getThumbnail(provider.client,
|
|
||||||
width: 50, height: 50)
|
|
||||||
.toString() ??
|
|
||||||
"")),
|
|
||||||
onTap: () => viewRoom(provider.client.rooms[index]),
|
onTap: () => viewRoom(provider.client.rooms[index]),
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
)),
|
)),
|
||||||
),
|
),
|
||||||
|
floatingActionButton: FloatingActionButton(
|
||||||
|
onPressed: sendMessage,
|
||||||
|
tooltip: 'Send message',
|
||||||
|
child: const Icon(Icons.send),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
pubspec.lock
16
pubspec.lock
|
@ -145,14 +145,6 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "7.0.0"
|
version: "7.0.0"
|
||||||
file_picker:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: file_picker
|
|
||||||
sha256: "4e42aacde3b993c5947467ab640882c56947d9d27342a5b6f2895b23956954a6"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "6.1.1"
|
|
||||||
flutter:
|
flutter:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description: flutter
|
description: flutter
|
||||||
|
@ -182,14 +174,6 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.3.0"
|
version: "0.3.0"
|
||||||
flutter_plugin_android_lifecycle:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: flutter_plugin_android_lifecycle
|
|
||||||
sha256: b068ffc46f82a55844acfa4fdbb61fad72fa2aef0905548419d97f0f95c456da
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.0.17"
|
|
||||||
flutter_test:
|
flutter_test:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description: flutter
|
description: flutter
|
||||||
|
|
|
@ -40,7 +40,6 @@ dependencies:
|
||||||
flutter_openssl_crypto: ^0.3.0
|
flutter_openssl_crypto: ^0.3.0
|
||||||
provider: ^6.1.1
|
provider: ^6.1.1
|
||||||
shared_preferences: ^2.2.2
|
shared_preferences: ^2.2.2
|
||||||
file_picker: ^6.1.1
|
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user