Fix presence list

This commit is contained in:
Christian Pauly 2020-05-06 17:45:59 +02:00
parent 59e6e3c397
commit 7a8c22c376
3 changed files with 23 additions and 10 deletions

View file

@ -1,7 +1,6 @@
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/i18n/i18n.dart'; import 'package:fluffychat/i18n/i18n.dart';
import 'package:fluffychat/utils/app_route.dart'; import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/utils/date_time_extension.dart';
import 'package:fluffychat/views/chat.dart'; import 'package:fluffychat/views/chat.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -14,10 +13,20 @@ class PresenceListItem extends StatelessWidget {
const PresenceListItem(this.presence); const PresenceListItem(this.presence);
Future<Profile> _requestProfile(BuildContext context) async {
if (presence.avatarUrl != null) {
return Profile.fromJson({
'avatar_url': presence.avatarUrl.toString(),
'displayname': presence.displayname ?? presence.sender.localpart,
});
}
return Matrix.of(context).client.getProfileFromUserId(presence.sender);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return FutureBuilder<Profile>( return FutureBuilder<Profile>(
future: Matrix.of(context).client.getProfileFromUserId(presence.sender), future: _requestProfile(context),
builder: (context, snapshot) { builder: (context, snapshot) {
Uri avatarUrl; Uri avatarUrl;
String displayname = presence.sender.localpart; String displayname = presence.sender.localpart;
@ -39,11 +48,17 @@ class PresenceListItem extends StatelessWidget {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
Text(presence.getLocalizedStatusMessage(context)), if (presence.isStatus)
Text( Text(presence.getLocalizedStatusMessage(context)),
presence.time.localizedTime(context), if (presence.presence != null)
style: TextStyle(fontSize: 12), Text(
), presence.presence.toString().split('.').last,
style: TextStyle(
color: presence.currentlyActive == true
? Colors.green
: Theme.of(context).primaryColor,
),
)
], ],
), ),
actions: <Widget>[ actions: <Widget>[

View file

@ -1,10 +1,8 @@
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'presence_extension.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();
statusList.removeWhere((Presence p) => !p.isStatus);
statusList.sort((a, b) => b.time.compareTo(a.time)); statusList.sort((a, b) => b.time.compareTo(a.time));
return statusList; return statusList;
} }

View file

@ -7,7 +7,7 @@ extension PresenceExtension on Presence {
(statusMsg?.isNotEmpty ?? false) || this.displayname != null; (statusMsg?.isNotEmpty ?? false) || this.displayname != null;
String getLocalizedStatusMessage(BuildContext context) { String getLocalizedStatusMessage(BuildContext context) {
if (!isStatus) return null; if (!isStatus) return '';
if (statusMsg?.isNotEmpty ?? false) { if (statusMsg?.isNotEmpty ?? false) {
return statusMsg; return statusMsg;
} }