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;
|
||||
});
|
||||
|
||||
final provider = Provider.of<ZenithClientProvider>(context, listen: false);
|
||||
final client = Client("zenith");
|
||||
|
||||
try {
|
||||
final provider =
|
||||
Provider.of<ZenithClientProvider>(context, listen: false);
|
||||
final client = Client("zenith");
|
||||
await client.checkHomeserver(Uri.parse(serverController.text));
|
||||
await client.login(
|
||||
final result = await client.login(
|
||||
LoginType.mLoginPassword,
|
||||
password: passwordController.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) {
|
||||
print(error);
|
||||
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;
|
||||
Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
|
@ -81,7 +81,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||
title: const Text("Login"),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
|
|
|
@ -44,24 +44,22 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
final prefs = await SharedPreferences.getInstance();
|
||||
final homeserver = prefs.getString("homeserver");
|
||||
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;
|
||||
final provider = Provider.of<ZenithClientProvider>(context, listen: false);
|
||||
final client = Client("zenith");
|
||||
provider.setClient(client);
|
||||
setState(() {
|
||||
showRooms = true;
|
||||
});
|
||||
|
||||
try {
|
||||
await client.checkHomeserver(Uri.parse(homeserver));
|
||||
if (!client.isLogged())
|
||||
await client.login(LoginType.mLoginPassword,
|
||||
password: password,
|
||||
identifier: AuthenticationUserIdentifier(user: username));
|
||||
await client.login(LoginType.mLoginToken, token: accessToken);
|
||||
provider.setClient(client);
|
||||
setState(() {
|
||||
showRooms = true;
|
||||
});
|
||||
} catch (error) {
|
||||
print(error);
|
||||
setState(() {
|
||||
|
@ -78,19 +76,6 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (errorMessage.isNotEmpty)
|
||||
return Column(
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
errorMessage = "";
|
||||
});
|
||||
},
|
||||
child: const Text("Clear")),
|
||||
ErrorWidget(errorMessage),
|
||||
],
|
||||
);
|
||||
if (showRooms)
|
||||
return const RoomsPage();
|
||||
else
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.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
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
|
@ -66,9 +54,10 @@ class _RoomPageState extends State<RoomPage> {
|
|||
itemCount: messages?.length,
|
||||
reverse: true,
|
||||
itemBuilder: (context, index) => ListTile(
|
||||
title: Text(
|
||||
messages![index].senderFromMemoryOrFallback.displayName ??
|
||||
""),
|
||||
title: Text(messages![index]
|
||||
.senderFromMemoryOrFallback
|
||||
.displayName
|
||||
.toString()),
|
||||
subtitle: Text(messages![index].body),
|
||||
leading:
|
||||
messages![index].senderFromMemoryOrFallback.avatarUrl !=
|
||||
|
@ -85,12 +74,11 @@ class _RoomPageState extends State<RoomPage> {
|
|||
),
|
||||
TextFormField(
|
||||
controller: chatController,
|
||||
textCapitalization: TextCapitalization.sentences,
|
||||
textInputAction: TextInputAction.send,
|
||||
decoration: const InputDecoration(hintText: 'Message'),
|
||||
onFieldSubmitted: (value) async {
|
||||
chatController.text = '';
|
||||
print("Sending text event $value to room ${widget.room.id}...");
|
||||
await widget.room.sendTextEvent(value);
|
||||
chatController.text = '';
|
||||
},
|
||||
),
|
||||
];
|
||||
|
@ -101,18 +89,18 @@ class _RoomPageState extends State<RoomPage> {
|
|||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.room
|
||||
.getLocalizedDisplayname()
|
||||
.replaceFirst(RegExp("Group with "), "")),
|
||||
actions: [
|
||||
IconButton(onPressed: setAvatar, icon: const Icon(Icons.image))
|
||||
],
|
||||
title: Text(widget.room.getLocalizedDisplayname()),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
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)));
|
||||
}
|
||||
|
||||
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
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
|
@ -94,45 +78,33 @@ class _RoomsPageState extends State<RoomsPage> {
|
|||
],
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Center(child: Consumer<ZenithClientProvider>(
|
||||
builder: (context, provider, child) {
|
||||
print(provider.client.rooms
|
||||
.where((element) =>
|
||||
element.getLocalizedDisplayname().contains("Group with"))
|
||||
.length);
|
||||
|
||||
provider.client.onRoomState.stream.listen((event) {
|
||||
provider.client.roomsLoading?.then((value) {
|
||||
setState(() {
|
||||
loadingRooms = false;
|
||||
});
|
||||
});
|
||||
|
||||
return ElevatedButton(
|
||||
onPressed: () => fixNames(provider.client),
|
||||
child: const Text("Fix names"));
|
||||
|
||||
if (provider.client.rooms.isEmpty)
|
||||
if (provider.client.roomsLoading != null && loadingRooms)
|
||||
return const CircularProgressIndicator();
|
||||
else
|
||||
return ListView.builder(
|
||||
itemCount: provider.client.rooms.length,
|
||||
itemBuilder: (context, index) => ListTile(
|
||||
title: Text(provider.client.rooms[index]
|
||||
.getLocalizedDisplayname()
|
||||
.replaceFirst(RegExp("Group with "), "")),
|
||||
leading: CircleAvatar(
|
||||
foregroundImage: NetworkImage(provider
|
||||
.client.rooms[index].avatar
|
||||
?.getThumbnail(provider.client,
|
||||
width: 50, height: 50)
|
||||
.toString() ??
|
||||
"")),
|
||||
.getLocalizedDisplayname()),
|
||||
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"
|
||||
source: hosted
|
||||
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:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
|
@ -182,14 +174,6 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
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:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
|
|
|
@ -40,7 +40,6 @@ dependencies:
|
|||
flutter_openssl_crypto: ^0.3.0
|
||||
provider: ^6.1.1
|
||||
shared_preferences: ^2.2.2
|
||||
file_picker: ^6.1.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Reference in New Issue
Block a user