Compare commits
10 Commits
3728172844
...
1aa73bbd7e
Author | SHA1 | Date | |
---|---|---|---|
1aa73bbd7e | |||
6ca8f646b2 | |||
a40dd74b96 | |||
10b84d1521 | |||
8ca788ccdd | |||
7c1e18c4e8 | |||
76411aa827 | |||
27b7f79d74 | |||
f229c0371b | |||
1cd8ba41ae |
|
@ -24,23 +24,17 @@ class _LoginPageState extends State<LoginPage> {
|
|||
loggingIn = true;
|
||||
});
|
||||
|
||||
try {
|
||||
final provider =
|
||||
Provider.of<ZenithClientProvider>(context, listen: false);
|
||||
final provider = Provider.of<ZenithClientProvider>(context, listen: false);
|
||||
final client = Client("zenith");
|
||||
|
||||
try {
|
||||
await client.checkHomeserver(Uri.parse(serverController.text));
|
||||
final result = await client.login(
|
||||
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(() {
|
||||
|
@ -60,6 +54,12 @@ 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(16.0),
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
|
|
|
@ -44,22 +44,24 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
final prefs = await SharedPreferences.getInstance();
|
||||
final homeserver = prefs.getString("homeserver");
|
||||
final username = prefs.getString("username");
|
||||
final accessToken = prefs.getString("accessToken");
|
||||
final refreshToken = prefs.getString("refreshToken");
|
||||
final password = prefs.getString("password");
|
||||
|
||||
if (homeserver == null || username == null || accessToken == null) return;
|
||||
if (homeserver == null || username == null || password == null) return;
|
||||
|
||||
if (!mounted) return;
|
||||
final provider = Provider.of<ZenithClientProvider>(context, listen: false);
|
||||
final client = Client("zenith");
|
||||
|
||||
try {
|
||||
await client.checkHomeserver(Uri.parse(homeserver));
|
||||
await client.login(LoginType.mLoginToken, token: accessToken);
|
||||
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));
|
||||
} catch (error) {
|
||||
print(error);
|
||||
setState(() {
|
||||
|
@ -76,6 +78,19 @@ 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,5 +1,7 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
|
@ -34,6 +36,16 @@ 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();
|
||||
|
@ -54,10 +66,9 @@ class _RoomPageState extends State<RoomPage> {
|
|||
itemCount: messages?.length,
|
||||
reverse: true,
|
||||
itemBuilder: (context, index) => ListTile(
|
||||
title: Text(messages![index]
|
||||
.senderFromMemoryOrFallback
|
||||
.displayName
|
||||
.toString()),
|
||||
title: Text(
|
||||
messages![index].senderFromMemoryOrFallback.displayName ??
|
||||
""),
|
||||
subtitle: Text(messages![index].body),
|
||||
leading:
|
||||
messages![index].senderFromMemoryOrFallback.avatarUrl !=
|
||||
|
@ -74,11 +85,12 @@ class _RoomPageState extends State<RoomPage> {
|
|||
),
|
||||
TextFormField(
|
||||
controller: chatController,
|
||||
textCapitalization: TextCapitalization.sentences,
|
||||
textInputAction: TextInputAction.send,
|
||||
decoration: const InputDecoration(hintText: 'Message'),
|
||||
onFieldSubmitted: (value) async {
|
||||
print("Sending text event $value to room ${widget.room.id}...");
|
||||
await widget.room.sendTextEvent(value);
|
||||
chatController.text = '';
|
||||
await widget.room.sendTextEvent(value);
|
||||
},
|
||||
),
|
||||
];
|
||||
|
@ -89,18 +101,18 @@ class _RoomPageState extends State<RoomPage> {
|
|||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.room.getLocalizedDisplayname()),
|
||||
title: Text(widget.room
|
||||
.getLocalizedDisplayname()
|
||||
.replaceFirst(RegExp("Group with "), "")),
|
||||
actions: [
|
||||
IconButton(onPressed: setAvatar, icon: const Icon(Icons.image))
|
||||
],
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
children: getChildren(),
|
||||
)),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: sendMessage,
|
||||
tooltip: 'Send message',
|
||||
child: const Icon(Icons.send),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,22 @@ 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(
|
||||
|
@ -78,33 +94,45 @@ class _RoomsPageState extends State<RoomsPage> {
|
|||
],
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Center(child: Consumer<ZenithClientProvider>(
|
||||
builder: (context, provider, child) {
|
||||
provider.client.roomsLoading?.then((value) {
|
||||
print(provider.client.rooms
|
||||
.where((element) =>
|
||||
element.getLocalizedDisplayname().contains("Group with"))
|
||||
.length);
|
||||
|
||||
provider.client.onRoomState.stream.listen((event) {
|
||||
setState(() {
|
||||
loadingRooms = false;
|
||||
});
|
||||
});
|
||||
|
||||
if (provider.client.roomsLoading != null && loadingRooms)
|
||||
return ElevatedButton(
|
||||
onPressed: () => fixNames(provider.client),
|
||||
child: const Text("Fix names"));
|
||||
|
||||
if (provider.client.rooms.isEmpty)
|
||||
return const CircularProgressIndicator();
|
||||
else
|
||||
return ListView.builder(
|
||||
itemCount: provider.client.rooms.length,
|
||||
itemBuilder: (context, index) => ListTile(
|
||||
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]),
|
||||
));
|
||||
},
|
||||
)),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: sendMessage,
|
||||
tooltip: 'Send message',
|
||||
child: const Icon(Icons.send),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
16
pubspec.lock
16
pubspec.lock
|
@ -145,6 +145,14 @@ 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
|
||||
|
@ -174,6 +182,14 @@ 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,6 +40,7 @@ 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