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

View file

@ -1,10 +1,8 @@
import 'package:famedlysdk/famedlysdk.dart';
import 'presence_extension.dart';
extension ClientPresenceExtension on Client {
List<Presence> get statusList {
final statusList = presences.values.toList();
statusList.removeWhere((Presence p) => !p.isStatus);
statusList.sort((a, b) => b.time.compareTo(a.time));
return statusList;
}

View file

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