Minor fixes

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

View File

@ -2,7 +2,7 @@ include: package:pedantic/analysis_options.yaml
linter: linter:
rules: rules:
# - camel_case_types - camel_case_types
analyzer: analyzer:
errors: errors:

View File

@ -23,11 +23,13 @@ class AdaptivePageLayout extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return OrientationBuilder(builder: (context, orientation) { return OrientationBuilder(builder: (context, orientation) {
if (orientation == Orientation.portrait || if (orientation == Orientation.portrait || columnMode(context)) {
columnMode(context)) if (primaryPage == FocusPage.FIRST) if (primaryPage == FocusPage.FIRST) {
return firstScaffold; return firstScaffold;
else } else {
return secondScaffold; return secondScaffold;
}
}
return Row( return Row(
children: <Widget>[ children: <Widget>[
Container( Container(

View File

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/utils/app_route.dart'; import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/views/chat_details.dart'; import 'package:fluffychat/views/chat_details.dart';
@ -6,16 +8,37 @@ import 'package:flutter/material.dart';
import 'matrix.dart'; import 'matrix.dart';
class ChatSettingsPopupMenu extends StatelessWidget { class ChatSettingsPopupMenu extends StatefulWidget {
final Room room; final Room room;
final bool displayChatDetails; final bool displayChatDetails;
const ChatSettingsPopupMenu(this.room, this.displayChatDetails, {Key key}) const ChatSettingsPopupMenu(this.room, this.displayChatDetails, {Key key})
: super(key: key); : super(key: key);
@override
_ChatSettingsPopupMenuState createState() => _ChatSettingsPopupMenuState();
}
class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
StreamSubscription notificationChangeSub;
@override
void dispose() {
notificationChangeSub?.cancel();
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
notificationChangeSub ??= Matrix.of(context)
.client
.onUserEvent
.stream
.where((u) => u.type == 'account_data' && u.eventType == "m.push_rules")
.listen(
(u) => setState(() => null),
);
List<PopupMenuEntry<String>> items = <PopupMenuEntry<String>>[ List<PopupMenuEntry<String>> items = <PopupMenuEntry<String>>[
room.pushRuleState == PushRuleState.notify widget.room.pushRuleState == PushRuleState.notify
? const PopupMenuItem<String>( ? const PopupMenuItem<String>(
value: "mute", value: "mute",
child: Text('Mute chat'), child: Text('Mute chat'),
@ -29,7 +52,7 @@ class ChatSettingsPopupMenu extends StatelessWidget {
child: Text('Leave'), child: Text('Leave'),
), ),
]; ];
if (displayChatDetails) if (widget.displayChatDetails) {
items.insert( items.insert(
0, 0,
const PopupMenuItem<String>( const PopupMenuItem<String>(
@ -37,28 +60,30 @@ class ChatSettingsPopupMenu extends StatelessWidget {
child: Text('Chat details'), child: Text('Chat details'),
), ),
); );
}
return PopupMenuButton( return PopupMenuButton(
onSelected: (String choice) async { onSelected: (String choice) async {
switch (choice) { switch (choice) {
case "leave": case "leave":
await Matrix.of(context).tryRequestWithLoadingDialog(room.leave()); await Matrix.of(context)
Navigator.of(context).pushAndRemoveUntil( .tryRequestWithLoadingDialog(widget.room.leave());
await Navigator.of(context).pushAndRemoveUntil(
AppRoute.defaultRoute(context, ChatListView()), AppRoute.defaultRoute(context, ChatListView()),
(Route r) => false); (Route r) => false);
break; break;
case "mute": case "mute":
await Matrix.of(context).tryRequestWithLoadingDialog( await Matrix.of(context).tryRequestWithLoadingDialog(
room.setPushRuleState(PushRuleState.mentions_only)); widget.room.setPushRuleState(PushRuleState.mentions_only));
break; break;
case "unmute": case "unmute":
await Matrix.of(context).tryRequestWithLoadingDialog( await Matrix.of(context).tryRequestWithLoadingDialog(
room.setPushRuleState(PushRuleState.notify)); widget.room.setPushRuleState(PushRuleState.notify));
break; break;
case "details": case "details":
Navigator.of(context).push( await Navigator.of(context).push(
AppRoute.defaultRoute( AppRoute.defaultRoute(
context, context,
ChatDetails(room), ChatDetails(widget.room),
), ),
); );
break; break;

View File

@ -14,11 +14,12 @@ class NewGroupDialog extends StatelessWidget {
matrix.client.createRoom(params: params), matrix.client.createRoom(params: params),
); );
Navigator.of(context).pop(); Navigator.of(context).pop();
if (roomID != null) if (roomID != null) {
Navigator.push( await Navigator.push(
context, context,
MaterialPageRoute(builder: (context) => Chat(roomID)), MaterialPageRoute(builder: (context) => Chat(roomID)),
); );
}
} }
@override @override

View File

@ -18,11 +18,12 @@ class NewPrivateChatDialog extends StatelessWidget {
await matrix.tryRequestWithLoadingDialog(user.startDirectChat()); await matrix.tryRequestWithLoadingDialog(user.startDirectChat());
Navigator.of(context).pop(); Navigator.of(context).pop();
if (roomID != null) if (roomID != null) {
Navigator.push( await Navigator.push(
context, context,
MaterialPageRoute(builder: (context) => Chat(roomID)), MaterialPageRoute(builder: (context) => Chat(roomID)),
); );
}
} }
@override @override

View File

@ -22,16 +22,17 @@ class ChatListItem extends StatelessWidget {
title: Text(room.displayname), title: Text(room.displayname),
subtitle: MessageContent(room.lastEvent, textOnly: true), subtitle: MessageContent(room.lastEvent, textOnly: true),
onTap: () { onTap: () {
if (activeChat) if (activeChat) {
Navigator.pushReplacement( Navigator.pushReplacement(
context, context,
AppRoute.defaultRoute(context, Chat(room.id)), AppRoute.defaultRoute(context, Chat(room.id)),
); );
else } else {
Navigator.push( Navigator.push(
context, context,
AppRoute.defaultRoute(context, Chat(room.id)), AppRoute.defaultRoute(context, Chat(room.id)),
); );
}
}, },
onLongPress: () {}, onLongPress: () {},
trailing: Container( trailing: Container(

View File

@ -31,13 +31,14 @@ class Message extends StatelessWidget {
color = event.status == -1 ? Colors.redAccent : Color(0xFF5625BA); color = event.status == -1 ? Colors.redAccent : Color(0xFF5625BA);
} }
List<PopupMenuEntry<String>> popupMenuList = []; List<PopupMenuEntry<String>> popupMenuList = [];
if (event.canRedact && !event.redacted && event.status > 1) if (event.canRedact && !event.redacted && event.status > 1) {
popupMenuList.add( popupMenuList.add(
const PopupMenuItem<String>( const PopupMenuItem<String>(
value: "remove", value: "remove",
child: Text('Remove message'), child: Text('Remove message'),
), ),
); );
}
if (ownMessage && event.status == -1) { if (ownMessage && event.status == -1) {
popupMenuList.add( popupMenuList.add(
const PopupMenuItem<String>( const PopupMenuItem<String>(
@ -59,16 +60,16 @@ class Message extends StatelessWidget {
onSelected: (String choice) async { onSelected: (String choice) async {
switch (choice) { switch (choice) {
case "remove": case "remove":
showDialog( await showDialog(
context: context, context: context,
builder: (BuildContext context) => RedactMessageDialog(event), builder: (BuildContext context) => RedactMessageDialog(event),
); );
break; break;
case "resend": case "resend":
event.sendAgain(); await event.sendAgain();
break; break;
case "delete": case "delete":
event.remove(); await event.remove();
break; break;
} }
}, },
@ -113,10 +114,11 @@ class Message extends StatelessWidget {
), ),
), ),
]; ];
if (ownMessage) if (ownMessage) {
rowChildren.add(Avatar(event.sender.avatarUrl)); rowChildren.add(Avatar(event.sender.avatarUrl));
else } else {
rowChildren.insert(0, Avatar(event.sender.avatarUrl)); rowChildren.insert(0, Avatar(event.sender.avatarUrl));
}
return Padding( return Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: Row( child: Row(

View File

@ -15,23 +15,23 @@ class ParticipantListItem extends StatelessWidget {
final MatrixState matrix = Matrix.of(context); final MatrixState matrix = Matrix.of(context);
switch (action) { switch (action) {
case "ban": case "ban":
matrix.tryRequestWithLoadingDialog(user.ban()); await matrix.tryRequestWithLoadingDialog(user.ban());
break; break;
case "unban": case "unban":
matrix.tryRequestWithLoadingDialog(user.unban()); await matrix.tryRequestWithLoadingDialog(user.unban());
break; break;
case "kick": case "kick":
matrix.tryRequestWithLoadingDialog(user.kick()); await matrix.tryRequestWithLoadingDialog(user.kick());
break; break;
case "admin": case "admin":
matrix.tryRequestWithLoadingDialog(user.setPower(100)); await matrix.tryRequestWithLoadingDialog(user.setPower(100));
break; break;
case "user": case "user":
matrix.tryRequestWithLoadingDialog(user.setPower(100)); await matrix.tryRequestWithLoadingDialog(user.setPower(100));
break; break;
case "message": case "message":
final String roomId = await user.startDirectChat(); final String roomId = await user.startDirectChat();
Navigator.of(context).pushAndRemoveUntil( await Navigator.of(context).pushAndRemoveUntil(
AppRoute.defaultRoute( AppRoute.defaultRoute(
context, context,
Chat(roomId), Chat(roomId),
@ -55,30 +55,35 @@ class ParticipantListItem extends StatelessWidget {
List<PopupMenuEntry<String>> items = <PopupMenuEntry<String>>[]; List<PopupMenuEntry<String>> items = <PopupMenuEntry<String>>[];
if (user.canChangePowerLevel && if (user.canChangePowerLevel &&
user.room.ownPowerLevel == 100 && user.room.ownPowerLevel == 100 &&
user.powerLevel != 100) user.powerLevel != 100) {
items.add( items.add(
PopupMenuItem(child: Text("Make an admin"), value: "admin"), PopupMenuItem(child: Text("Make an admin"), value: "admin"),
); );
if (user.canChangePowerLevel && user.powerLevel != 0) }
if (user.canChangePowerLevel && user.powerLevel != 0) {
items.add( items.add(
PopupMenuItem(child: Text("Revoke all permissions"), value: "user"), PopupMenuItem(child: Text("Revoke all permissions"), value: "user"),
); );
if (user.canKick) }
if (user.canKick) {
items.add( items.add(
PopupMenuItem(child: Text("Kick from group"), value: "kick"), PopupMenuItem(child: Text("Kick from group"), value: "kick"),
); );
if (user.canBan && user.membership != Membership.ban) }
if (user.canBan && user.membership != Membership.ban) {
items.add( items.add(
PopupMenuItem(child: Text("Ban from group"), value: "ban"), PopupMenuItem(child: Text("Ban from group"), value: "ban"),
); );
else if (user.canBan && user.membership == Membership.ban) } else if (user.canBan && user.membership == Membership.ban) {
items.add( items.add(
PopupMenuItem(child: Text("Remove exile"), value: "unban"), PopupMenuItem(child: Text("Remove exile"), value: "unban"),
); );
if (user.id != Matrix.of(context).client.userID) }
if (user.id != Matrix.of(context).client.userID) {
items.add( items.add(
PopupMenuItem(child: Text("Send a message"), value: "message"), PopupMenuItem(child: Text("Send a message"), value: "message"),
); );
}
return PopupMenuButton( return PopupMenuButton(
onSelected: (action) => participantAction(context, action), onSelected: (action) => participantAction(context, action),
itemBuilder: (c) => items, itemBuilder: (c) => items,

View File

@ -80,7 +80,7 @@ class MatrixState extends State<Matrix> {
final LocalStorage storage = LocalStorage('LocalStorage'); final LocalStorage storage = LocalStorage('LocalStorage');
await storage.ready; await storage.ready;
storage.deleteItem(widget.clientName); await storage.deleteItem(widget.clientName);
} }
BuildContext _loadingDialogContext; BuildContext _loadingDialogContext;
@ -128,10 +128,11 @@ class MatrixState extends State<Matrix> {
void initState() { void initState() {
if (widget.client == null) { if (widget.client == null) {
client = Client(widget.clientName, debug: false); client = Client(widget.clientName, debug: false);
if (!kIsWeb) if (!kIsWeb) {
client.store = Store(client); client.store = Store(client);
else } else {
loadAccount(); loadAccount();
}
} else { } else {
client = widget.client; client = widget.client;
} }

View File

@ -14,7 +14,7 @@ class MessageContent extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final int maxLines = textOnly ? 1 : null; final int maxLines = textOnly ? 1 : null;
if (textOnly) if (textOnly) {
return Text( return Text(
event.getBody(), event.getBody(),
style: TextStyle( style: TextStyle(
@ -23,6 +23,7 @@ class MessageContent extends StatelessWidget {
), ),
maxLines: maxLines, maxLines: maxLines,
); );
}
switch (event.type) { switch (event.type) {
case EventTypes.Audio: case EventTypes.Audio:
case EventTypes.Image: case EventTypes.Image:

View File

@ -1,13 +1,19 @@
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'components/matrix.dart'; import 'components/matrix.dart';
import 'views/chat_list.dart'; import 'views/chat_list.dart';
import 'views/login.dart'; import 'views/login.dart';
void main() => runApp(MyApp()); void main() {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(statusBarColor: Colors.white),
);
runApp(App());
}
class MyApp extends StatelessWidget { class App extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Matrix( return Matrix(
@ -41,12 +47,13 @@ class MyApp extends StatelessWidget {
builder: (BuildContext context) => StreamBuilder<LoginState>( builder: (BuildContext context) => StreamBuilder<LoginState>(
stream: Matrix.of(context).client.onLoginStateChanged.stream, stream: Matrix.of(context).client.onLoginStateChanged.stream,
builder: (context, snapshot) { builder: (context, snapshot) {
if (!snapshot.hasData) if (!snapshot.hasData) {
return Scaffold( return Scaffold(
body: Center( body: Center(
child: CircularProgressIndicator(), child: CircularProgressIndicator(),
), ),
); );
}
if (Matrix.of(context).client.isLogged()) return ChatListView(); if (Matrix.of(context).client.isLogged()) return ChatListView();
return LoginPage(); return LoginPage();
}, },

View File

@ -53,9 +53,10 @@ class Store extends StoreAPI {
onCreate: (Database db, int version) async { onCreate: (Database db, int version) async {
await createTables(db); await createTables(db);
}, onUpgrade: (Database db, int oldVersion, int newVersion) async { }, onUpgrade: (Database db, int oldVersion, int newVersion) async {
if (client.debug) if (client.debug) {
print( print(
"[Store] Migrate databse from version $oldVersion to $newVersion"); "[Store] Migrate databse from version $oldVersion to $newVersion");
}
if (oldVersion != newVersion) { if (oldVersion != newVersion) {
schemes.forEach((String name, String scheme) async { schemes.forEach((String name, String scheme) async {
if (name != "Clients") await db.execute("DROP TABLE IF EXISTS $name"); if (name != "Clients") await db.execute("DROP TABLE IF EXISTS $name");
@ -84,10 +85,12 @@ class Store extends StoreAPI {
? null ? null
: clientList["prev_batch"], : clientList["prev_batch"],
); );
if (client.debug) if (client.debug) {
print("[Store] Restore client credentials of ${client.userID}"); print("[Store] Restore client credentials of ${client.userID}");
} else }
} else {
client.onLoginStateChanged.add(LoginState.loggedOut); client.onLoginStateChanged.add(LoginState.loggedOut);
}
} }
Future<void> createTables(Database db) async { Future<void> createTables(Database db) async {
@ -155,11 +158,11 @@ class Store extends StoreAPI {
Future<void> storeRoomUpdate(RoomUpdate roomUpdate) { Future<void> storeRoomUpdate(RoomUpdate roomUpdate) {
if (txn == null) return null; if (txn == null) return null;
// Insert the chat into the database if not exists // Insert the chat into the database if not exists
if (roomUpdate.membership != Membership.leave) if (roomUpdate.membership != Membership.leave) {
txn.rawInsert( txn.rawInsert(
"INSERT OR IGNORE INTO Rooms " + "VALUES(?, ?, 0, 0, '', 0, 0, '') ", "INSERT OR IGNORE INTO Rooms " + "VALUES(?, ?, 0, 0, '', 0, 0, '') ",
[roomUpdate.id, roomUpdate.membership.toString().split('.').last]); [roomUpdate.id, roomUpdate.membership.toString().split('.').last]);
else { } else {
txn.rawDelete("DELETE FROM Rooms WHERE room_id=? ", [roomUpdate.id]); txn.rawDelete("DELETE FROM Rooms WHERE room_id=? ", [roomUpdate.id]);
return null; return null;
} }
@ -202,17 +205,18 @@ class Store extends StoreAPI {
/// [transaction]. /// [transaction].
Future<void> storeUserEventUpdate(UserUpdate userUpdate) { Future<void> storeUserEventUpdate(UserUpdate userUpdate) {
if (txn == null) return null; if (txn == null) return null;
if (userUpdate.type == "account_data") if (userUpdate.type == "account_data") {
txn.rawInsert("INSERT OR REPLACE INTO AccountData VALUES(?, ?)", [ txn.rawInsert("INSERT OR REPLACE INTO AccountData VALUES(?, ?)", [
userUpdate.eventType, userUpdate.eventType,
json.encode(userUpdate.content["content"]), json.encode(userUpdate.content["content"]),
]); ]);
else if (userUpdate.type == "presence") } else if (userUpdate.type == "presence") {
txn.rawInsert("INSERT OR REPLACE INTO Presences VALUES(?, ?, ?)", [ txn.rawInsert("INSERT OR REPLACE INTO Presences VALUES(?, ?, ?)", [
userUpdate.eventType, userUpdate.eventType,
userUpdate.content["sender"], userUpdate.content["sender"],
json.encode(userUpdate.content["content"]), json.encode(userUpdate.content["content"]),
]); ]);
}
return null; return null;
} }
@ -272,14 +276,14 @@ class Store extends StoreAPI {
// Save the event in the database // Save the event in the database
if ((status == 1 || status == -1) && if ((status == 1 || status == -1) &&
eventContent["unsigned"] is Map<String, dynamic> && eventContent["unsigned"] is Map<String, dynamic> &&
eventContent["unsigned"]["transaction_id"] is String) eventContent["unsigned"]["transaction_id"] is String) {
txn.rawUpdate( txn.rawUpdate(
"UPDATE Events SET status=?, event_id=? WHERE event_id=?", [ "UPDATE Events SET status=?, event_id=? WHERE event_id=?", [
status, status,
eventContent["event_id"], eventContent["event_id"],
eventContent["unsigned"]["transaction_id"] eventContent["unsigned"]["transaction_id"]
]); ]);
else } else {
txn.rawInsert( txn.rawInsert(
"INSERT OR REPLACE INTO Events VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", "INSERT OR REPLACE INTO Events VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
[ [
@ -294,13 +298,15 @@ class Store extends StoreAPI {
eventContent["state_key"], eventContent["state_key"],
status status
]); ]);
}
// Is there a transaction id? Then delete the event with this id. // Is there a transaction id? Then delete the event with this id.
if (status != -1 && if (status != -1 &&
eventUpdate.content.containsKey("unsigned") && eventUpdate.content.containsKey("unsigned") &&
eventUpdate.content["unsigned"]["transaction_id"] is String) eventUpdate.content["unsigned"]["transaction_id"] is String) {
txn.rawDelete("DELETE FROM Events WHERE event_id=?", txn.rawDelete("DELETE FROM Events WHERE event_id=?",
[eventUpdate.content["unsigned"]["transaction_id"]]); [eventUpdate.content["unsigned"]["transaction_id"]]);
}
} }
if (type == "history") return null; if (type == "history") return null;
@ -321,12 +327,13 @@ class Store extends StoreAPI {
eventContent["type"], eventContent["type"],
json.encode(eventContent["content"]), json.encode(eventContent["content"]),
]); ]);
} else } else {
txn.rawInsert("INSERT OR REPLACE INTO RoomAccountData VALUES(?, ?, ?)", [ txn.rawInsert("INSERT OR REPLACE INTO RoomAccountData VALUES(?, ?, ?)", [
eventContent["type"], eventContent["type"],
chatId, chatId,
json.encode(eventContent["content"]), json.encode(eventContent["content"]),
]); ]);
}
return null; return null;
} }
@ -347,8 +354,9 @@ class Store extends StoreAPI {
"SELECT * FROM RoomStates WHERE state_key LIKE '@%:%' AND state_key!=? AND room_id!=? GROUP BY state_key ORDER BY state_key", "SELECT * FROM RoomStates WHERE state_key LIKE '@%:%' AND state_key!=? AND room_id!=? GROUP BY state_key ORDER BY state_key",
[client.userID, exceptRoomID]); [client.userID, exceptRoomID]);
List<User> userList = []; List<User> userList = [];
for (int i = 0; i < res.length; i++) for (int i = 0; i < res.length; i++) {
userList.add(Event.fromJson(res[i], Room(id: "", client: client)).asUser); userList.add(Event.fromJson(res[i], Room(id: "", client: client)).asUser);
}
return userList; return userList;
} }
@ -382,8 +390,9 @@ class Store extends StoreAPI {
List<Event> eventList = []; List<Event> eventList = [];
for (num i = 0; i < eventRes.length; i++) for (num i = 0; i < eventRes.length; i++) {
eventList.add(Event.fromJson(eventRes[i], room)); eventList.add(Event.fromJson(eventRes[i], room));
}
return eventList; return eventList;
} }
@ -444,7 +453,7 @@ class Store extends StoreAPI {
List<Map<String, dynamic>> res = await _db.rawQuery( List<Map<String, dynamic>> res = await _db.rawQuery(
"SELECT * FROM Events WHERE event_id=? AND room_id=?", "SELECT * FROM Events WHERE event_id=? AND room_id=?",
[eventID, room.id]); [eventID, room.id]);
if (res.length == 0) return null; if (res.isEmpty) return null;
return Event.fromJson(res[0], room); return Event.fromJson(res[0], room);
} }
@ -452,9 +461,10 @@ class Store extends StoreAPI {
Map<String, AccountData> newAccountData = {}; Map<String, AccountData> newAccountData = {};
List<Map<String, dynamic>> rawAccountData = List<Map<String, dynamic>> rawAccountData =
await _db.rawQuery("SELECT * FROM AccountData"); await _db.rawQuery("SELECT * FROM AccountData");
for (int i = 0; i < rawAccountData.length; i++) for (int i = 0; i < rawAccountData.length; i++) {
newAccountData[rawAccountData[i]["type"]] = newAccountData[rawAccountData[i]["type"]] =
AccountData.fromJson(rawAccountData[i]); AccountData.fromJson(rawAccountData[i]);
}
return newAccountData; return newAccountData;
} }
@ -502,7 +512,7 @@ class Store extends StoreAPI {
assert(roomId != ""); assert(roomId != "");
List<Map<String, dynamic>> res = await _db List<Map<String, dynamic>> res = await _db
.rawQuery("SELECT * FROM NotificationsCache WHERE chat_id=?", [roomId]); .rawQuery("SELECT * FROM NotificationsCache WHERE chat_id=?", [roomId]);
if (res.length == 0) return null; if (res.isEmpty) return null;
return res; return res;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -5,26 +5,13 @@
// gestures. You can also use WidgetTester to find child widgets in the widget // gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct. // tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:fluffychat/main.dart'; import 'package:fluffychat/main.dart';
void main() { void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async { testWidgets('Test if the app starts', (WidgetTester tester) async {
// Build our app and trigger a frame. // Build our app and trigger a frame.
await tester.pumpWidget(MyApp()); await tester.pumpWidget(App());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
}); });
} }