Implement status feature and new design
parent
a361ee53f0
commit
a4d34cb0b1
@ -0,0 +1,93 @@
|
||||
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';
|
||||
|
||||
import '../avatar.dart';
|
||||
import '../matrix.dart';
|
||||
import 'package:fluffychat/utils/presence_extension.dart';
|
||||
|
||||
class PresenceListItem extends StatelessWidget {
|
||||
final Presence presence;
|
||||
|
||||
const PresenceListItem(this.presence);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder<Profile>(
|
||||
future: Matrix.of(context).client.getProfileFromUserId(presence.sender),
|
||||
builder: (context, snapshot) {
|
||||
MxContent avatarUrl = MxContent('');
|
||||
String displayname = presence.sender.localpart;
|
||||
if (snapshot.hasData) {
|
||||
avatarUrl = snapshot.data.avatarUrl;
|
||||
displayname = snapshot.data.displayname;
|
||||
}
|
||||
return InkWell(
|
||||
onTap: () => showDialog(
|
||||
context: context,
|
||||
builder: (c) => AlertDialog(
|
||||
title: ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: Avatar(avatarUrl, displayname),
|
||||
title: Text(displayname),
|
||||
subtitle: Text(presence.sender),
|
||||
),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(presence.getLocalizedStatusMessage(context)),
|
||||
Text(
|
||||
presence.time.localizedTime(context),
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: <Widget>[
|
||||
if (presence.sender != Matrix.of(context).client.userID)
|
||||
FlatButton(
|
||||
child: Text(I18n.of(context).sendAMessage),
|
||||
onPressed: () async {
|
||||
final String roomId = await User(
|
||||
presence.sender,
|
||||
room: Room(id: '', client: Matrix.of(context).client),
|
||||
).startDirectChat();
|
||||
await Navigator.of(context).pushAndRemoveUntil(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
ChatView(roomId),
|
||||
),
|
||||
(Route r) => r.isFirst);
|
||||
},
|
||||
),
|
||||
FlatButton(
|
||||
child: Text(I18n.of(context).close),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
child: Container(
|
||||
width: 80,
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
SizedBox(height: 6),
|
||||
Avatar(avatarUrl, displayname),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(6.0),
|
||||
child: Text(
|
||||
displayname,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/i18n/i18n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
extension PresenceExtension on Presence {
|
||||
bool get isStatus =>
|
||||
(statusMsg?.isNotEmpty ?? false) ||
|
||||
this.displayname != null ||
|
||||
this.avatarUrl != null;
|
||||
|
||||
String getLocalizedStatusMessage(BuildContext context) {
|
||||
if (!isStatus) return null;
|
||||
if (statusMsg?.isNotEmpty ?? false) {
|
||||
return statusMsg;
|
||||
}
|
||||
if (displayname != null) {
|
||||
return I18n.of(context)
|
||||
.changedTheDisplaynameTo(sender.localpart, displayname);
|
||||
}
|
||||
if (avatarUrl != null) {
|
||||
return I18n.of(context).changedTheProfileAvatar(sender.localpart);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue