Minor fixes
This commit is contained in:
parent
7e6212ff8a
commit
de29800f29
|
@ -2,7 +2,7 @@ include: package:pedantic/analysis_options.yaml
|
|||
|
||||
linter:
|
||||
rules:
|
||||
# - camel_case_types
|
||||
- camel_case_types
|
||||
|
||||
analyzer:
|
||||
errors:
|
||||
|
|
|
@ -23,11 +23,13 @@ class AdaptivePageLayout extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return OrientationBuilder(builder: (context, orientation) {
|
||||
if (orientation == Orientation.portrait ||
|
||||
columnMode(context)) if (primaryPage == FocusPage.FIRST)
|
||||
return firstScaffold;
|
||||
else
|
||||
return secondScaffold;
|
||||
if (orientation == Orientation.portrait || columnMode(context)) {
|
||||
if (primaryPage == FocusPage.FIRST) {
|
||||
return firstScaffold;
|
||||
} else {
|
||||
return secondScaffold;
|
||||
}
|
||||
}
|
||||
return Row(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/utils/app_route.dart';
|
||||
import 'package:fluffychat/views/chat_details.dart';
|
||||
|
@ -6,16 +8,37 @@ import 'package:flutter/material.dart';
|
|||
|
||||
import 'matrix.dart';
|
||||
|
||||
class ChatSettingsPopupMenu extends StatelessWidget {
|
||||
class ChatSettingsPopupMenu extends StatefulWidget {
|
||||
final Room room;
|
||||
final bool displayChatDetails;
|
||||
const ChatSettingsPopupMenu(this.room, this.displayChatDetails, {Key key})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
_ChatSettingsPopupMenuState createState() => _ChatSettingsPopupMenuState();
|
||||
}
|
||||
|
||||
class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
|
||||
StreamSubscription notificationChangeSub;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
notificationChangeSub?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
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>>[
|
||||
room.pushRuleState == PushRuleState.notify
|
||||
widget.room.pushRuleState == PushRuleState.notify
|
||||
? const PopupMenuItem<String>(
|
||||
value: "mute",
|
||||
child: Text('Mute chat'),
|
||||
|
@ -29,7 +52,7 @@ class ChatSettingsPopupMenu extends StatelessWidget {
|
|||
child: Text('Leave'),
|
||||
),
|
||||
];
|
||||
if (displayChatDetails)
|
||||
if (widget.displayChatDetails) {
|
||||
items.insert(
|
||||
0,
|
||||
const PopupMenuItem<String>(
|
||||
|
@ -37,28 +60,30 @@ class ChatSettingsPopupMenu extends StatelessWidget {
|
|||
child: Text('Chat details'),
|
||||
),
|
||||
);
|
||||
}
|
||||
return PopupMenuButton(
|
||||
onSelected: (String choice) async {
|
||||
switch (choice) {
|
||||
case "leave":
|
||||
await Matrix.of(context).tryRequestWithLoadingDialog(room.leave());
|
||||
Navigator.of(context).pushAndRemoveUntil(
|
||||
await Matrix.of(context)
|
||||
.tryRequestWithLoadingDialog(widget.room.leave());
|
||||
await Navigator.of(context).pushAndRemoveUntil(
|
||||
AppRoute.defaultRoute(context, ChatListView()),
|
||||
(Route r) => false);
|
||||
break;
|
||||
case "mute":
|
||||
await Matrix.of(context).tryRequestWithLoadingDialog(
|
||||
room.setPushRuleState(PushRuleState.mentions_only));
|
||||
widget.room.setPushRuleState(PushRuleState.mentions_only));
|
||||
break;
|
||||
case "unmute":
|
||||
await Matrix.of(context).tryRequestWithLoadingDialog(
|
||||
room.setPushRuleState(PushRuleState.notify));
|
||||
widget.room.setPushRuleState(PushRuleState.notify));
|
||||
break;
|
||||
case "details":
|
||||
Navigator.of(context).push(
|
||||
await Navigator.of(context).push(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
ChatDetails(room),
|
||||
ChatDetails(widget.room),
|
||||
),
|
||||
);
|
||||
break;
|
||||
|
|
|
@ -14,11 +14,12 @@ class NewGroupDialog extends StatelessWidget {
|
|||
matrix.client.createRoom(params: params),
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
if (roomID != null)
|
||||
Navigator.push(
|
||||
if (roomID != null) {
|
||||
await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => Chat(roomID)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -18,11 +18,12 @@ class NewPrivateChatDialog extends StatelessWidget {
|
|||
await matrix.tryRequestWithLoadingDialog(user.startDirectChat());
|
||||
Navigator.of(context).pop();
|
||||
|
||||
if (roomID != null)
|
||||
Navigator.push(
|
||||
if (roomID != null) {
|
||||
await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => Chat(roomID)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -22,16 +22,17 @@ class ChatListItem extends StatelessWidget {
|
|||
title: Text(room.displayname),
|
||||
subtitle: MessageContent(room.lastEvent, textOnly: true),
|
||||
onTap: () {
|
||||
if (activeChat)
|
||||
if (activeChat) {
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
AppRoute.defaultRoute(context, Chat(room.id)),
|
||||
);
|
||||
else
|
||||
} else {
|
||||
Navigator.push(
|
||||
context,
|
||||
AppRoute.defaultRoute(context, Chat(room.id)),
|
||||
);
|
||||
}
|
||||
},
|
||||
onLongPress: () {},
|
||||
trailing: Container(
|
||||
|
|
|
@ -31,13 +31,14 @@ class Message extends StatelessWidget {
|
|||
color = event.status == -1 ? Colors.redAccent : Color(0xFF5625BA);
|
||||
}
|
||||
List<PopupMenuEntry<String>> popupMenuList = [];
|
||||
if (event.canRedact && !event.redacted && event.status > 1)
|
||||
if (event.canRedact && !event.redacted && event.status > 1) {
|
||||
popupMenuList.add(
|
||||
const PopupMenuItem<String>(
|
||||
value: "remove",
|
||||
child: Text('Remove message'),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (ownMessage && event.status == -1) {
|
||||
popupMenuList.add(
|
||||
const PopupMenuItem<String>(
|
||||
|
@ -59,16 +60,16 @@ class Message extends StatelessWidget {
|
|||
onSelected: (String choice) async {
|
||||
switch (choice) {
|
||||
case "remove":
|
||||
showDialog(
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) => RedactMessageDialog(event),
|
||||
);
|
||||
break;
|
||||
case "resend":
|
||||
event.sendAgain();
|
||||
await event.sendAgain();
|
||||
break;
|
||||
case "delete":
|
||||
event.remove();
|
||||
await event.remove();
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
@ -113,10 +114,11 @@ class Message extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
];
|
||||
if (ownMessage)
|
||||
if (ownMessage) {
|
||||
rowChildren.add(Avatar(event.sender.avatarUrl));
|
||||
else
|
||||
} else {
|
||||
rowChildren.insert(0, Avatar(event.sender.avatarUrl));
|
||||
}
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
|
|
|
@ -15,23 +15,23 @@ class ParticipantListItem extends StatelessWidget {
|
|||
final MatrixState matrix = Matrix.of(context);
|
||||
switch (action) {
|
||||
case "ban":
|
||||
matrix.tryRequestWithLoadingDialog(user.ban());
|
||||
await matrix.tryRequestWithLoadingDialog(user.ban());
|
||||
break;
|
||||
case "unban":
|
||||
matrix.tryRequestWithLoadingDialog(user.unban());
|
||||
await matrix.tryRequestWithLoadingDialog(user.unban());
|
||||
break;
|
||||
case "kick":
|
||||
matrix.tryRequestWithLoadingDialog(user.kick());
|
||||
await matrix.tryRequestWithLoadingDialog(user.kick());
|
||||
break;
|
||||
case "admin":
|
||||
matrix.tryRequestWithLoadingDialog(user.setPower(100));
|
||||
await matrix.tryRequestWithLoadingDialog(user.setPower(100));
|
||||
break;
|
||||
case "user":
|
||||
matrix.tryRequestWithLoadingDialog(user.setPower(100));
|
||||
await matrix.tryRequestWithLoadingDialog(user.setPower(100));
|
||||
break;
|
||||
case "message":
|
||||
final String roomId = await user.startDirectChat();
|
||||
Navigator.of(context).pushAndRemoveUntil(
|
||||
await Navigator.of(context).pushAndRemoveUntil(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
Chat(roomId),
|
||||
|
@ -55,30 +55,35 @@ class ParticipantListItem extends StatelessWidget {
|
|||
List<PopupMenuEntry<String>> items = <PopupMenuEntry<String>>[];
|
||||
if (user.canChangePowerLevel &&
|
||||
user.room.ownPowerLevel == 100 &&
|
||||
user.powerLevel != 100)
|
||||
user.powerLevel != 100) {
|
||||
items.add(
|
||||
PopupMenuItem(child: Text("Make an admin"), value: "admin"),
|
||||
);
|
||||
if (user.canChangePowerLevel && user.powerLevel != 0)
|
||||
}
|
||||
if (user.canChangePowerLevel && user.powerLevel != 0) {
|
||||
items.add(
|
||||
PopupMenuItem(child: Text("Revoke all permissions"), value: "user"),
|
||||
);
|
||||
if (user.canKick)
|
||||
}
|
||||
if (user.canKick) {
|
||||
items.add(
|
||||
PopupMenuItem(child: Text("Kick from group"), value: "kick"),
|
||||
);
|
||||
if (user.canBan && user.membership != Membership.ban)
|
||||
}
|
||||
if (user.canBan && user.membership != Membership.ban) {
|
||||
items.add(
|
||||
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(
|
||||
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(
|
||||
PopupMenuItem(child: Text("Send a message"), value: "message"),
|
||||
);
|
||||
}
|
||||
return PopupMenuButton(
|
||||
onSelected: (action) => participantAction(context, action),
|
||||
itemBuilder: (c) => items,
|
||||
|
|
|
@ -80,7 +80,7 @@ class MatrixState extends State<Matrix> {
|
|||
|
||||
final LocalStorage storage = LocalStorage('LocalStorage');
|
||||
await storage.ready;
|
||||
storage.deleteItem(widget.clientName);
|
||||
await storage.deleteItem(widget.clientName);
|
||||
}
|
||||
|
||||
BuildContext _loadingDialogContext;
|
||||
|
@ -128,10 +128,11 @@ class MatrixState extends State<Matrix> {
|
|||
void initState() {
|
||||
if (widget.client == null) {
|
||||
client = Client(widget.clientName, debug: false);
|
||||
if (!kIsWeb)
|
||||
if (!kIsWeb) {
|
||||
client.store = Store(client);
|
||||
else
|
||||
} else {
|
||||
loadAccount();
|
||||
}
|
||||
} else {
|
||||
client = widget.client;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ class MessageContent extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final int maxLines = textOnly ? 1 : null;
|
||||
if (textOnly)
|
||||
if (textOnly) {
|
||||
return Text(
|
||||
event.getBody(),
|
||||
style: TextStyle(
|
||||
|
@ -23,6 +23,7 @@ class MessageContent extends StatelessWidget {
|
|||
),
|
||||
maxLines: maxLines,
|
||||
);
|
||||
}
|
||||
switch (event.type) {
|
||||
case EventTypes.Audio:
|
||||
case EventTypes.Image:
|
||||
|
|
|
@ -1,13 +1,19 @@
|
|||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'components/matrix.dart';
|
||||
import 'views/chat_list.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
|
||||
Widget build(BuildContext context) {
|
||||
return Matrix(
|
||||
|
@ -41,12 +47,13 @@ class MyApp extends StatelessWidget {
|
|||
builder: (BuildContext context) => StreamBuilder<LoginState>(
|
||||
stream: Matrix.of(context).client.onLoginStateChanged.stream,
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData)
|
||||
if (!snapshot.hasData) {
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (Matrix.of(context).client.isLogged()) return ChatListView();
|
||||
return LoginPage();
|
||||
},
|
||||
|
|
|
@ -53,9 +53,10 @@ class Store extends StoreAPI {
|
|||
onCreate: (Database db, int version) async {
|
||||
await createTables(db);
|
||||
}, onUpgrade: (Database db, int oldVersion, int newVersion) async {
|
||||
if (client.debug)
|
||||
if (client.debug) {
|
||||
print(
|
||||
"[Store] Migrate databse from version $oldVersion to $newVersion");
|
||||
}
|
||||
if (oldVersion != newVersion) {
|
||||
schemes.forEach((String name, String scheme) async {
|
||||
if (name != "Clients") await db.execute("DROP TABLE IF EXISTS $name");
|
||||
|
@ -84,10 +85,12 @@ class Store extends StoreAPI {
|
|||
? null
|
||||
: clientList["prev_batch"],
|
||||
);
|
||||
if (client.debug)
|
||||
if (client.debug) {
|
||||
print("[Store] Restore client credentials of ${client.userID}");
|
||||
} else
|
||||
}
|
||||
} else {
|
||||
client.onLoginStateChanged.add(LoginState.loggedOut);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> createTables(Database db) async {
|
||||
|
@ -155,11 +158,11 @@ class Store extends StoreAPI {
|
|||
Future<void> storeRoomUpdate(RoomUpdate roomUpdate) {
|
||||
if (txn == null) return null;
|
||||
// Insert the chat into the database if not exists
|
||||
if (roomUpdate.membership != Membership.leave)
|
||||
if (roomUpdate.membership != Membership.leave) {
|
||||
txn.rawInsert(
|
||||
"INSERT OR IGNORE INTO Rooms " + "VALUES(?, ?, 0, 0, '', 0, 0, '') ",
|
||||
[roomUpdate.id, roomUpdate.membership.toString().split('.').last]);
|
||||
else {
|
||||
} else {
|
||||
txn.rawDelete("DELETE FROM Rooms WHERE room_id=? ", [roomUpdate.id]);
|
||||
return null;
|
||||
}
|
||||
|
@ -202,17 +205,18 @@ class Store extends StoreAPI {
|
|||
/// [transaction].
|
||||
Future<void> storeUserEventUpdate(UserUpdate userUpdate) {
|
||||
if (txn == null) return null;
|
||||
if (userUpdate.type == "account_data")
|
||||
if (userUpdate.type == "account_data") {
|
||||
txn.rawInsert("INSERT OR REPLACE INTO AccountData VALUES(?, ?)", [
|
||||
userUpdate.eventType,
|
||||
json.encode(userUpdate.content["content"]),
|
||||
]);
|
||||
else if (userUpdate.type == "presence")
|
||||
} else if (userUpdate.type == "presence") {
|
||||
txn.rawInsert("INSERT OR REPLACE INTO Presences VALUES(?, ?, ?)", [
|
||||
userUpdate.eventType,
|
||||
userUpdate.content["sender"],
|
||||
json.encode(userUpdate.content["content"]),
|
||||
]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -272,14 +276,14 @@ class Store extends StoreAPI {
|
|||
// Save the event in the database
|
||||
if ((status == 1 || status == -1) &&
|
||||
eventContent["unsigned"] is Map<String, dynamic> &&
|
||||
eventContent["unsigned"]["transaction_id"] is String)
|
||||
eventContent["unsigned"]["transaction_id"] is String) {
|
||||
txn.rawUpdate(
|
||||
"UPDATE Events SET status=?, event_id=? WHERE event_id=?", [
|
||||
status,
|
||||
eventContent["event_id"],
|
||||
eventContent["unsigned"]["transaction_id"]
|
||||
]);
|
||||
else
|
||||
} else {
|
||||
txn.rawInsert(
|
||||
"INSERT OR REPLACE INTO Events VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
[
|
||||
|
@ -294,13 +298,15 @@ class Store extends StoreAPI {
|
|||
eventContent["state_key"],
|
||||
status
|
||||
]);
|
||||
}
|
||||
|
||||
// Is there a transaction id? Then delete the event with this id.
|
||||
if (status != -1 &&
|
||||
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=?",
|
||||
[eventUpdate.content["unsigned"]["transaction_id"]]);
|
||||
}
|
||||
}
|
||||
|
||||
if (type == "history") return null;
|
||||
|
@ -321,12 +327,13 @@ class Store extends StoreAPI {
|
|||
eventContent["type"],
|
||||
json.encode(eventContent["content"]),
|
||||
]);
|
||||
} else
|
||||
} else {
|
||||
txn.rawInsert("INSERT OR REPLACE INTO RoomAccountData VALUES(?, ?, ?)", [
|
||||
eventContent["type"],
|
||||
chatId,
|
||||
json.encode(eventContent["content"]),
|
||||
]);
|
||||
}
|
||||
|
||||
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",
|
||||
[client.userID, exceptRoomID]);
|
||||
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);
|
||||
}
|
||||
return userList;
|
||||
}
|
||||
|
||||
|
@ -382,8 +390,9 @@ class Store extends StoreAPI {
|
|||
|
||||
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));
|
||||
}
|
||||
|
||||
return eventList;
|
||||
}
|
||||
|
@ -444,7 +453,7 @@ class Store extends StoreAPI {
|
|||
List<Map<String, dynamic>> res = await _db.rawQuery(
|
||||
"SELECT * FROM Events WHERE event_id=? AND room_id=?",
|
||||
[eventID, room.id]);
|
||||
if (res.length == 0) return null;
|
||||
if (res.isEmpty) return null;
|
||||
return Event.fromJson(res[0], room);
|
||||
}
|
||||
|
||||
|
@ -452,9 +461,10 @@ class Store extends StoreAPI {
|
|||
Map<String, AccountData> newAccountData = {};
|
||||
List<Map<String, dynamic>> rawAccountData =
|
||||
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"]] =
|
||||
AccountData.fromJson(rawAccountData[i]);
|
||||
}
|
||||
return newAccountData;
|
||||
}
|
||||
|
||||
|
@ -502,7 +512,7 @@ class Store extends StoreAPI {
|
|||
assert(roomId != "");
|
||||
List<Map<String, dynamic>> res = await _db
|
||||
.rawQuery("SELECT * FROM NotificationsCache WHERE chat_id=?", [roomId]);
|
||||
if (res.length == 0) return null;
|
||||
if (res.isEmpty) return null;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -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) =>
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -5,26 +5,13 @@
|
|||
// 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.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:fluffychat/main.dart';
|
||||
|
||||
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.
|
||||
await tester.pumpWidget(MyApp());
|
||||
|
||||
// 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);
|
||||
await tester.pumpWidget(App());
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue