Fix top list

This commit is contained in:
Christian Pauly 2020-06-19 15:10:26 +02:00
parent 0b22e9ea82
commit bcda0bbd5f
6 changed files with 65 additions and 72 deletions

View file

@ -34,15 +34,6 @@ class PresenceDialog extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
Text(presence.getLocalizedStatusMessage(context)), Text(presence.getLocalizedStatusMessage(context)),
if (presence.presence != null)
Text(
presence.presence.toString().split('.').last,
style: TextStyle(
color: presence.presence.currentlyActive == true
? Colors.green
: Theme.of(context).primaryColor,
),
)
], ],
), ),
actions: <Widget>[ actions: <Widget>[

View file

@ -1,15 +1,15 @@
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/dialogs/presence_dialog.dart';
import 'package:fluffychat/utils/app_route.dart'; import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/views/chat.dart'; import 'package:fluffychat/views/chat.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../utils/client_presence_extension.dart';
import '../avatar.dart'; import '../avatar.dart';
import '../matrix.dart'; import '../matrix.dart';
class PresenceListItem extends StatelessWidget { class PresenceListItem extends StatelessWidget {
final Presence presence; final Room room;
const PresenceListItem(this.presence); const PresenceListItem(this.room);
void _startChatAction(BuildContext context, String userId) async { void _startChatAction(BuildContext context, String userId) async {
final roomId = await User(userId, final roomId = await User(userId,
@ -25,37 +25,42 @@ class PresenceListItem extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return FutureBuilder<Profile>( final user = room.getUserByMXIDSync(room.directChatMatrixID);
future: final presence =
Matrix.of(context).client.requestProfileCached(presence.senderId), Matrix.of(context).client.presences[room.directChatMatrixID];
builder: (context, snapshot) { return InkWell(
Uri avatarUrl; onTap: () => presence?.presence?.statusMsg == null
var displayname = presence.senderId.localpart; ? _startChatAction(context, user.id)
if (snapshot.hasData) { : showDialog(
avatarUrl = snapshot.data.avatarUrl; context: context,
displayname = builder: (_) => PresenceDialog(
snapshot.data.displayname ?? presence.senderId.localpart; presence,
} avatarUrl: user.avatarUrl,
return InkWell( displayname: user.calcDisplayname(),
onTap: () => _startChatAction(context, presence.senderId),
child: Container(
width: 80,
child: Column(
children: <Widget>[
SizedBox(height: 9),
Avatar(avatarUrl, displayname),
Padding(
padding: const EdgeInsets.all(6.0),
child: Text(
displayname,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
),
],
), ),
), ),
); child: Container(
}); width: 80,
child: Column(
children: <Widget>[
SizedBox(height: 9),
Avatar(user.avatarUrl, user.calcDisplayname()),
Padding(
padding: const EdgeInsets.all(6.0),
child: Text(
user.calcDisplayname(),
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: TextStyle(
fontWeight: presence?.presence?.statusMsg == null
? null
: FontWeight.bold,
),
),
),
],
),
),
);
} }
} }

View file

@ -1,16 +1,6 @@
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
extension ClientPresenceExtension on Client { extension ClientPresenceExtension on Client {
List<Presence> get statusList {
final statusList = presences.values.toList().reversed.toList();
final directRooms = rooms.where((r) => r.isDirectChat).toList();
statusList.removeWhere((p) =>
directRooms.indexWhere((r) => r.directChatMatrixID == p.senderId) ==
-1);
statusList.reversed.toList();
return statusList;
}
static final Map<String, Profile> presencesCache = {}; static final Map<String, Profile> presencesCache = {};
Future<Profile> requestProfileCached(String senderId) async { Future<Profile> requestProfileCached(String senderId) async {

View file

@ -8,8 +8,11 @@ extension PresenceExtension on Presence {
if (presence.statusMsg?.isNotEmpty ?? false) { if (presence.statusMsg?.isNotEmpty ?? false) {
return presence.statusMsg; return presence.statusMsg;
} }
return L10n.of(context).lastActiveAgo( if (presence.lastActiveAgo != null) {
DateTime.fromMillisecondsSinceEpoch(presence.lastActiveAgo) return L10n.of(context).lastActiveAgo(
.localizedTimeShort(context)); DateTime.fromMillisecondsSinceEpoch(presence.lastActiveAgo)
.localizedTimeShort(context));
}
return L10n.of(context).lastSeenLongTimeAgo;
} }
} }

View file

@ -9,7 +9,10 @@ extension RoomStatusExtension on Room {
String getLocalizedStatus(BuildContext context) { String getLocalizedStatus(BuildContext context) {
if (isDirectChat) { if (isDirectChat) {
if (directChatPresence != null) { if (directChatPresence != null &&
directChatPresence.presence != null &&
(directChatPresence.presence.lastActiveAgo != null ||
directChatPresence.presence.currentlyActive != null)) {
if (directChatPresence.presence.currentlyActive == true) { if (directChatPresence.presence.currentlyActive == true) {
return L10n.of(context).currentlyActive; return L10n.of(context).currentlyActive;
} }

View file

@ -19,7 +19,6 @@ import '../components/matrix.dart';
import '../l10n/l10n.dart'; import '../l10n/l10n.dart';
import '../utils/app_route.dart'; import '../utils/app_route.dart';
import '../utils/url_launcher.dart'; import '../utils/url_launcher.dart';
import '../utils/client_presence_extension.dart';
import 'archive.dart'; import 'archive.dart';
import 'homeserver_picker.dart'; import 'homeserver_picker.dart';
import 'new_group.dart'; import 'new_group.dart';
@ -436,6 +435,16 @@ class _ChatListState extends State<ChatList> {
(publicRoomsResponse?.chunk?.length ?? 0); (publicRoomsResponse?.chunk?.length ?? 0);
final totalCount = final totalCount =
rooms.length + publicRoomsCount; rooms.length + publicRoomsCount;
final directChats =
rooms.where((r) => r.isDirectChat).toList();
directChats.sort((a, b) => Matrix.of(context)
.client
.presences[b.directChatMatrixID]
?.presence
?.statusMsg !=
null
? 1
: -1);
return ListView.separated( return ListView.separated(
controller: _scrollController, controller: _scrollController,
separatorBuilder: separatorBuilder:
@ -452,10 +461,7 @@ class _ChatListState extends State<ChatList> {
itemCount: totalCount + 1, itemCount: totalCount + 1,
itemBuilder: (BuildContext context, int i) { itemBuilder: (BuildContext context, int i) {
if (i == 0) { if (i == 0) {
return (Matrix.of(context) return (directChats.isEmpty ||
.client
.statusList
.isEmpty ||
selectMode == SelectMode.share) selectMode == SelectMode.share)
? Container() ? Container()
: PreferredSize( : PreferredSize(
@ -466,17 +472,12 @@ class _ChatListState extends State<ChatList> {
child: ListView.builder( child: ListView.builder(
scrollDirection: scrollDirection:
Axis.horizontal, Axis.horizontal,
itemCount: Matrix.of(context) itemCount: directChats.length,
.client itemBuilder:
.statusList (BuildContext context,
.length, int i) =>
itemBuilder: (BuildContext PresenceListItem(
context, directChats[i]),
int i) =>
PresenceListItem(
Matrix.of(context)
.client
.statusList[i]),
), ),
), ),
); );