Minor fixes

This commit is contained in:
Christian Pauly 2020-01-02 22:31:39 +01:00
commit de29800f29
19 changed files with 156 additions and 104 deletions

View file

@ -26,18 +26,17 @@ class _ChatState extends State<Chat> {
Timeline timeline;
final ScrollController _scrollController = new ScrollController();
final ScrollController _scrollController = ScrollController();
@override
void initState() {
_scrollController.addListener(() async {
if (_scrollController.position.pixels ==
_scrollController.position.maxScrollExtent) {
if (timeline.events.length > 0 &&
timeline.events[timeline.events.length - 1].type !=
EventTypes.RoomCreate) {
await timeline.requestHistory(historyCount: 100);
}
_scrollController.position.maxScrollExtent &&
timeline.events.isNotEmpty &&
timeline.events[timeline.events.length - 1].type !=
EventTypes.RoomCreate) {
await timeline.requestHistory(historyCount: 100);
}
});
@ -71,7 +70,7 @@ class _ChatState extends State<Chat> {
}
File file = await FilePicker.getFile();
if (file == null) return;
Matrix.of(context).tryRequestWithLoadingDialog(
await Matrix.of(context).tryRequestWithLoadingDialog(
room.sendFileEvent(
MatrixFile(bytes: await file.readAsBytes(), path: file.path),
),
@ -88,7 +87,7 @@ class _ChatState extends State<Chat> {
maxWidth: 1600,
maxHeight: 1600);
if (file == null) return;
Matrix.of(context).tryRequestWithLoadingDialog(
await Matrix.of(context).tryRequestWithLoadingDialog(
room.sendImageEvent(
MatrixFile(bytes: await file.readAsBytes(), path: file.path),
),
@ -105,7 +104,7 @@ class _ChatState extends State<Chat> {
maxWidth: 1600,
maxHeight: 1600);
if (file == null) return;
Matrix.of(context).tryRequestWithLoadingDialog(
await Matrix.of(context).tryRequestWithLoadingDialog(
room.sendImageEvent(
MatrixFile(bytes: await file.readAsBytes(), path: file.path),
),
@ -136,15 +135,17 @@ class _ChatState extends State<Chat> {
child: FutureBuilder<bool>(
future: getTimeline(),
builder: (BuildContext context, snapshot) {
if (!snapshot.hasData)
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
}
if (room.notificationCount != null &&
room.notificationCount > 0 &&
timeline != null &&
timeline.events.length > 0)
timeline.events.isNotEmpty) {
room.sendReadReceipt(timeline.events[0].eventId);
}
return ListView.builder(
reverse: true,
itemCount: timeline.events.length,
@ -175,10 +176,11 @@ class _ChatState extends State<Chat> {
: PopupMenuButton<String>(
icon: Icon(Icons.add),
onSelected: (String choice) async {
if (choice == "file")
if (choice == "file") {
sendFileAction(context);
else if (choice == "image")
} else if (choice == "image") {
sendImageAction(context);
}
if (choice == "camera") openCameraAction(context);
},
itemBuilder: (BuildContext context) =>

View file

@ -31,7 +31,7 @@ class _ChatDetailsState extends State<ChatDetails> {
await matrix.tryRequestWithLoadingDialog(
widget.room.setName(displayname),
);
if (success != null && success.length == 0) {
if (success != null && success.isEmpty) {
Toast.show(
"Displayname has been changed",
context,
@ -57,7 +57,7 @@ class _ChatDetailsState extends State<ChatDetails> {
),
),
);
if (success != null && success.length == 0) {
if (success != null && success.isEmpty) {
Toast.show(
"Avatar has been changed",
context,

View file

@ -39,8 +39,9 @@ class _ChatListState extends State<ChatList> {
Future<bool> waitForFirstSync(BuildContext context) async {
Client client = Matrix.of(context).client;
if (client.prevBatch?.isEmpty ?? true)
if (client.prevBatch?.isEmpty ?? true) {
await client.onFirstSync.stream.first;
}
sub ??= client.onSync.stream.listen((s) => setState(() => null));
return true;
}
@ -121,10 +122,11 @@ class _ChatListState extends State<ChatList> {
activeChat: widget.activeChat == rooms[i].id,
),
);
} else
} else {
return Center(
child: CircularProgressIndicator(),
);
}
},
),
);

View file

@ -20,8 +20,9 @@ class InvitationSelection extends StatelessWidget {
List<User> roomUsers = client.rooms[i].getParticipants();
for (int j = 0; j < roomUsers.length; j++) {
if (userMap[roomUsers[j].id] != true &&
participants.indexWhere((u) => u.id == roomUsers[j].id) == -1)
participants.indexWhere((u) => u.id == roomUsers[j].id) == -1) {
contacts.add(roomUsers[j]);
}
userMap[roomUsers[j].id] = true;
}
}
@ -32,12 +33,13 @@ class InvitationSelection extends StatelessWidget {
final success = await Matrix.of(context).tryRequestWithLoadingDialog(
room.invite(id),
);
if (success != false)
if (success != false) {
Toast.show(
"Contact has been invited to the group.",
context,
duration: Toast.LENGTH_LONG,
);
}
}
@override
@ -53,10 +55,11 @@ class InvitationSelection extends StatelessWidget {
body: FutureBuilder<List<User>>(
future: getContacts(context),
builder: (BuildContext context, snapshot) {
if (!snapshot.hasData)
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
}
List<User> contacts = snapshot.data;
return ListView.builder(
itemCount: contacts.length,

View file

@ -35,13 +35,15 @@ class _LoginPageState extends State<LoginPage> {
}
serverError = null;
if (usernameController.text.isEmpty || passwordController.text.isEmpty)
if (usernameController.text.isEmpty || passwordController.text.isEmpty) {
return;
}
String homeserver = serverController.text;
if (homeserver.isEmpty) homeserver = defaultHomeserver;
if (!homeserver.startsWith("https://"))
if (!homeserver.startsWith("https://")) {
homeserver = "https://" + homeserver;
}
try {
matrix.showLoadingDialog(context);
@ -64,7 +66,7 @@ class _LoginPageState extends State<LoginPage> {
setState(() => passwordError = exception.toString());
return matrix.hideLoadingDialog();
}
Matrix.of(context).saveAccount();
await Matrix.of(context).saveAccount();
matrix.hideLoadingDialog();
}

View file

@ -33,7 +33,7 @@ class _SettingsState extends State<Settings> {
dynamic profile;
void logoutAction(BuildContext context) async {
MatrixState matrix = Matrix.of(context);
Navigator.of(context).pushAndRemoveUntil(
await Navigator.of(context).pushAndRemoveUntil(
AppRoute.defaultRoute(context, LoginPage()), (r) => false);
await matrix.tryRequestWithLoadingDialog(matrix.client.logout());
matrix.clean();
@ -49,7 +49,7 @@ class _SettingsState extends State<Settings> {
data: {"displayname": displayname},
),
);
if (success != null && success.length == 0) {
if (success != null && success.isEmpty) {
Toast.show(
"Displayname has been changed",
context,
@ -79,7 +79,7 @@ class _SettingsState extends State<Settings> {
),
),
);
if (success != null && success.length == 0) {
if (success != null && success.isEmpty) {
Toast.show(
"Avatar has been changed",
context,