Minor fixes

This commit is contained in:
Christian Pauly 2020-05-09 09:30:03 +02:00
parent 61c0b986f8
commit 02675911db
6 changed files with 111 additions and 62 deletions

View File

@ -435,6 +435,8 @@ class L10n extends MatrixLocalizations {
String get loadingPleaseWait => Intl.message("Loading... Please wait"); String get loadingPleaseWait => Intl.message("Loading... Please wait");
String get loadMore => Intl.message('Load more...');
String loadCountMoreParticipants(String count) => Intl.message( String loadCountMoreParticipants(String count) => Intl.message(
"Load $count more participants", "Load $count more participants",
name: "loadCountMoreParticipants", name: "loadCountMoreParticipants",

View File

@ -2,9 +2,9 @@ import 'package:famedlysdk/famedlysdk.dart';
extension ClientPresenceExtension on Client { extension ClientPresenceExtension on Client {
List<Presence> get statusList { List<Presence> get statusList {
final statusList = presences.values.toList(); final statusList = presences.values.toList().reversed.toList();
statusList.removeWhere((p) => p.statusMsg?.isEmpty ?? true); statusList.removeWhere((p) => p.statusMsg?.isEmpty ?? true);
statusList.sort((a, b) => b.time.compareTo(a.time)); statusList.reversed.toList();
return statusList; return statusList;
} }
} }

View File

@ -496,6 +496,10 @@ class ExtendedStore extends Store implements ExtendedStoreAPI {
Future<void> forgetRoom(String roomID) async { Future<void> forgetRoom(String roomID) async {
await _db.rawDelete("DELETE FROM Rooms WHERE room_id=?", [roomID]); await _db.rawDelete("DELETE FROM Rooms WHERE room_id=?", [roomID]);
await _db.rawDelete("DELETE FROM Events WHERE room_id=?", [roomID]);
await _db.rawDelete("DELETE FROM RoomStates WHERE room_id=?", [roomID]);
await _db
.rawDelete("DELETE FROM RoomAccountData WHERE room_id=?", [roomID]);
return; return;
} }
@ -528,7 +532,7 @@ class ExtendedStore extends Store implements ExtendedStoreAPI {
"sender": rawPresences[i]["sender"], "sender": rawPresences[i]["sender"],
"content": json.decode(rawPresences[i]["content"]), "content": json.decode(rawPresences[i]["content"]),
}; };
newPresences[rawPresences[i]["type"]] = Presence.fromJson(rawPresence); newPresences[rawPresences[i]["sender"]] = Presence.fromJson(rawPresence);
} }
return newPresences; return newPresences;
} }

View File

@ -79,8 +79,10 @@ class _ChatState extends State<_Chat> {
String inputText = ""; String inputText = "";
bool get _canLoadMore => timeline.events.last.type != EventTypes.RoomCreate;
void requestHistory() async { void requestHistory() async {
if (timeline.events.last.type != EventTypes.RoomCreate) { if (_canLoadMore) {
setState(() => this._loadingHistory = true); setState(() => this._loadingHistory = true);
await timeline.requestHistory(historyCount: _loadHistoryCount); await timeline.requestHistory(historyCount: _loadHistoryCount);
if (mounted) setState(() => this._loadingHistory = false); if (mounted) setState(() => this._loadingHistory = false);
@ -450,58 +452,79 @@ class _ChatState extends State<_Chat> {
return ListView.builder( return ListView.builder(
reverse: true, reverse: true,
itemCount: timeline.events.length + 1, itemCount: timeline.events.length + 2,
controller: _scrollController, controller: _scrollController,
itemBuilder: (BuildContext context, int i) { itemBuilder: (BuildContext context, int i) {
return i == 0 return i == timeline.events.length + 1
? AnimatedContainer( ? _canLoadMore
height: seenByText.isEmpty ? 0 : 24, ? FlatButton(
duration: seenByText.isEmpty child: Text(
? Duration(milliseconds: 0) L10n.of(context).loadMore,
: Duration(milliseconds: 500), style: TextStyle(
alignment: timeline.events.first.senderId == color:
client.userID Theme.of(context).primaryColor,
? Alignment.topRight fontWeight: FontWeight.bold,
: Alignment.topLeft, decoration:
child: Text( TextDecoration.underline,
seenByText, ),
maxLines: 1, ),
overflow: TextOverflow.ellipsis, onPressed: requestHistory,
style: TextStyle( )
color: Theme.of(context).primaryColor, : Container()
), : i == 0
), ? AnimatedContainer(
padding: EdgeInsets.only( height: seenByText.isEmpty ? 0 : 24,
left: 8, duration: seenByText.isEmpty
right: 8, ? Duration(milliseconds: 0)
bottom: 8, : Duration(milliseconds: 500),
), alignment:
) timeline.events.first.senderId ==
: Message(timeline.events[i - 1], client.userID
onAvatarTab: (Event event) { ? Alignment.topRight
sendController.text += ' ${event.senderId}'; : Alignment.topLeft,
}, onSelect: (Event event) { child: Text(
if (!event.redacted) { seenByText,
if (selectedEvents.contains(event)) { maxLines: 1,
setState( overflow: TextOverflow.ellipsis,
() => selectedEvents.remove(event), style: TextStyle(
); color:
} else { Theme.of(context).primaryColor,
setState( ),
() => selectedEvents.add(event), ),
); padding: EdgeInsets.only(
} left: 8,
selectedEvents.sort( right: 8,
(a, b) => a.time.compareTo(b.time), bottom: 8,
); ),
} )
}, : Message(timeline.events[i - 1],
longPressSelect: selectedEvents.isEmpty, onAvatarTab: (Event event) {
selected: selectedEvents sendController.text +=
.contains(timeline.events[i - 1]), ' ${event.senderId}';
timeline: timeline, }, onSelect: (Event event) {
nextEvent: if (!event.redacted) {
i >= 2 ? timeline.events[i - 2] : null); if (selectedEvents.contains(event)) {
setState(
() =>
selectedEvents.remove(event),
);
} else {
setState(
() => selectedEvents.add(event),
);
}
selectedEvents.sort(
(a, b) => a.time.compareTo(b.time),
);
}
},
longPressSelect: selectedEvents.isEmpty,
selected: selectedEvents
.contains(timeline.events[i - 1]),
timeline: timeline,
nextEvent: i >= 2
? timeline.events[i - 2]
: null);
}); });
}, },
), ),

View File

@ -58,6 +58,8 @@ class _ChatListState extends State<ChatList> {
bool loadingPublicRooms = false; bool loadingPublicRooms = false;
String searchServer; String searchServer;
final ScrollController _scrollController = ScrollController();
Future<void> waitForFirstSync(BuildContext context) async { Future<void> 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) {
@ -66,8 +68,17 @@ class _ChatListState extends State<ChatList> {
return true; return true;
} }
bool _scrolledToTop = true;
@override @override
void initState() { void initState() {
_scrollController.addListener(() async {
if (_scrollController.position.pixels > 0 && _scrolledToTop) {
setState(() => _scrolledToTop = false);
} else if (_scrollController.position.pixels == 0 && !_scrolledToTop) {
setState(() => _scrolledToTop = true);
}
});
searchController.addListener(() { searchController.addListener(() {
coolDown?.cancel(); coolDown?.cancel();
if (searchController.text.isEmpty) { if (searchController.text.isEmpty) {
@ -272,6 +283,7 @@ class _ChatListState extends State<ChatList> {
), ),
), ),
appBar: AppBar( appBar: AppBar(
elevation: _scrolledToTop ? 0 : null,
leading: selectMode != SelectMode.share leading: selectMode != SelectMode.share
? null ? null
: IconButton( : IconButton(
@ -381,6 +393,7 @@ class _ChatListState extends State<ChatList> {
(publicRoomsResponse?.publicRooms?.length ?? 0); (publicRoomsResponse?.publicRooms?.length ?? 0);
final int totalCount = rooms.length + publicRoomsCount; final int totalCount = rooms.length + publicRoomsCount;
return ListView.separated( return ListView.separated(
controller: _scrollController,
separatorBuilder: (BuildContext context, int i) => separatorBuilder: (BuildContext context, int i) =>
i == totalCount - publicRoomsCount i == totalCount - publicRoomsCount
? Material( ? Material(

View File

@ -64,6 +64,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.3" version: "1.1.3"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
collection: collection:
dependency: transitive dependency: transitive
description: description:
@ -113,6 +120,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.3" version: "1.3.3"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
famedlysdk: famedlysdk:
dependency: "direct main" dependency: "direct main"
description: description:
@ -432,7 +446,7 @@ packages:
name: path name: path
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.6.4" version: "1.7.0"
path_drawing: path_drawing:
dependency: transitive dependency: transitive
description: description:
@ -510,13 +524,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.4.2" version: "1.4.2"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
receive_sharing_intent: receive_sharing_intent:
dependency: "direct main" dependency: "direct main"
description: description: