Better notifications
This commit is contained in:
parent
2c6a37d37a
commit
c4353bbea6
14 changed files with 296 additions and 25 deletions
|
|
@ -27,6 +27,8 @@ class _ChatState extends State<Chat> {
|
|||
|
||||
Timeline timeline;
|
||||
|
||||
MatrixState matrix;
|
||||
|
||||
String seenByText = "";
|
||||
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
|
|
@ -81,6 +83,7 @@ class _ChatState extends State<Chat> {
|
|||
@override
|
||||
void dispose() {
|
||||
timeline?.sub?.cancel();
|
||||
matrix.activeRoomId = "";
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
|
@ -98,7 +101,7 @@ class _ChatState extends State<Chat> {
|
|||
}
|
||||
File file = await FilePicker.getFile();
|
||||
if (file == null) return;
|
||||
await Matrix.of(context).tryRequestWithLoadingDialog(
|
||||
await matrix.tryRequestWithLoadingDialog(
|
||||
room.sendFileEvent(
|
||||
MatrixFile(bytes: await file.readAsBytes(), path: file.path),
|
||||
),
|
||||
|
|
@ -115,7 +118,7 @@ class _ChatState extends State<Chat> {
|
|||
maxWidth: 1600,
|
||||
maxHeight: 1600);
|
||||
if (file == null) return;
|
||||
await Matrix.of(context).tryRequestWithLoadingDialog(
|
||||
await matrix.tryRequestWithLoadingDialog(
|
||||
room.sendImageEvent(
|
||||
MatrixFile(bytes: await file.readAsBytes(), path: file.path),
|
||||
),
|
||||
|
|
@ -132,7 +135,7 @@ class _ChatState extends State<Chat> {
|
|||
maxWidth: 1600,
|
||||
maxHeight: 1600);
|
||||
if (file == null) return;
|
||||
await Matrix.of(context).tryRequestWithLoadingDialog(
|
||||
await matrix.tryRequestWithLoadingDialog(
|
||||
room.sendImageEvent(
|
||||
MatrixFile(bytes: await file.readAsBytes(), path: file.path),
|
||||
),
|
||||
|
|
@ -141,16 +144,18 @@ class _ChatState extends State<Chat> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Client client = Matrix.of(context).client;
|
||||
matrix = Matrix.of(context);
|
||||
Client client = matrix.client;
|
||||
room ??= client.getRoomById(widget.id);
|
||||
if (room == null) {
|
||||
return Center(
|
||||
child: Text("You are no longer participating in this chat"),
|
||||
);
|
||||
}
|
||||
matrix.activeRoomId = widget.id;
|
||||
|
||||
if (room.membership == Membership.invite) {
|
||||
Matrix.of(context).tryRequestWithLoadingDialog(room.join());
|
||||
matrix.tryRequestWithLoadingDialog(room.join());
|
||||
}
|
||||
|
||||
String typingText = "";
|
||||
|
|
|
|||
|
|
@ -2,8 +2,11 @@ import 'dart:math';
|
|||
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/components/matrix.dart';
|
||||
import 'package:fluffychat/utils/app_route.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'chat_list.dart';
|
||||
|
||||
const String defaultHomeserver = "https://matrix.org";
|
||||
|
||||
class LoginPage extends StatefulWidget {
|
||||
|
|
@ -47,6 +50,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||
}
|
||||
|
||||
try {
|
||||
print("[Login] Check server...");
|
||||
setState(() => loading = true);
|
||||
if (!await matrix.client.checkServer(homeserver)) {
|
||||
setState(() => serverError = "Homeserver is not compatible.");
|
||||
|
|
@ -58,6 +62,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||
return setState(() => loading = false);
|
||||
}
|
||||
try {
|
||||
print("[Login] Try to login...");
|
||||
await matrix.client
|
||||
.login(usernameController.text, passwordController.text);
|
||||
} on MatrixException catch (exception) {
|
||||
|
|
@ -67,8 +72,21 @@ class _LoginPageState extends State<LoginPage> {
|
|||
setState(() => passwordError = exception.toString());
|
||||
return setState(() => loading = false);
|
||||
}
|
||||
try {
|
||||
print("[Login] Setup Firebase...");
|
||||
await matrix.setupFirebase();
|
||||
} catch (exception) {
|
||||
print("[Login] Failed to setup Firebase. Logout now...");
|
||||
await matrix.client.logout();
|
||||
matrix.clean();
|
||||
setState(() => passwordError = exception.toString());
|
||||
return setState(() => loading = false);
|
||||
}
|
||||
print("[Login] Store account and go to ChatListView");
|
||||
await Matrix.of(context).saveAccount();
|
||||
setState(() => loading = false);
|
||||
await Navigator.of(context).pushAndRemoveUntil(
|
||||
AppRoute.defaultRoute(context, ChatListView()), (r) => false);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ import 'package:famedlysdk/famedlysdk.dart';
|
|||
import 'package:fluffychat/components/adaptive_page_layout.dart';
|
||||
import 'package:fluffychat/components/content_banner.dart';
|
||||
import 'package:fluffychat/components/matrix.dart';
|
||||
import 'package:fluffychat/utils/app_route.dart';
|
||||
import 'package:fluffychat/views/chat_list.dart';
|
||||
import 'package:fluffychat/views/login.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
|
@ -31,10 +33,11 @@ class _SettingsState extends State<Settings> {
|
|||
Future<dynamic> profileFuture;
|
||||
dynamic profile;
|
||||
void logoutAction(BuildContext context) async {
|
||||
await Navigator.of(context).popUntil((r) => r.isFirst);
|
||||
MatrixState matrix = Matrix.of(context);
|
||||
await matrix.tryRequestWithErrorToast(matrix.client.logout());
|
||||
await matrix.tryRequestWithLoadingDialog(matrix.client.logout());
|
||||
matrix.clean();
|
||||
await Navigator.of(context).pushAndRemoveUntil(
|
||||
AppRoute.defaultRoute(context, LoginPage()), (r) => false);
|
||||
}
|
||||
|
||||
void setDisplaynameAction(BuildContext context, String displayname) async {
|
||||
|
|
@ -94,7 +97,9 @@ class _SettingsState extends State<Settings> {
|
|||
Widget build(BuildContext context) {
|
||||
final Client client = Matrix.of(context).client;
|
||||
profileFuture ??= client.getProfileFromUserId(client.userID);
|
||||
profileFuture.then((p) => setState(() => profile = p));
|
||||
profileFuture.then((p) {
|
||||
if (mounted) setState(() => profile = p);
|
||||
});
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Settings"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue