2020-04-26 18:15:48 +02:00
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
2020-05-07 07:52:40 +02:00
|
|
|
import 'package:fluffychat/l10n/l10n.dart';
|
2020-04-26 18:15:48 +02:00
|
|
|
import 'package:fluffychat/utils/app_route.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);
|
|
|
|
|
2020-05-13 15:58:59 +02:00
|
|
|
static final Map<String, Profile> _presences = {};
|
2020-05-06 19:03:57 +02:00
|
|
|
|
2020-05-06 17:45:59 +02:00
|
|
|
Future<Profile> _requestProfile(BuildContext context) async {
|
2020-05-06 19:03:57 +02:00
|
|
|
_presences[presence.sender] ??=
|
|
|
|
await Matrix.of(context).client.getProfileFromUserId(presence.sender);
|
|
|
|
return _presences[presence.sender];
|
2020-05-06 17:45:59 +02:00
|
|
|
}
|
|
|
|
|
2020-04-26 18:15:48 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return FutureBuilder<Profile>(
|
2020-05-06 17:45:59 +02:00
|
|
|
future: _requestProfile(context),
|
2020-04-26 18:15:48 +02:00
|
|
|
builder: (context, snapshot) {
|
2020-05-06 18:31:38 +02:00
|
|
|
if (!snapshot.hasData) return Container();
|
2020-04-28 14:11:56 +02:00
|
|
|
Uri avatarUrl;
|
2020-05-13 15:58:59 +02:00
|
|
|
var displayname = presence.sender.localpart;
|
2020-04-26 18:15:48 +02:00
|
|
|
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>[
|
2020-05-06 18:31:38 +02:00
|
|
|
Text(presence.getLocalizedStatusMessage(context)),
|
2020-05-06 17:45:59 +02:00
|
|
|
if (presence.presence != null)
|
|
|
|
Text(
|
|
|
|
presence.presence.toString().split('.').last,
|
|
|
|
style: TextStyle(
|
|
|
|
color: presence.currentlyActive == true
|
|
|
|
? Colors.green
|
|
|
|
: Theme.of(context).primaryColor,
|
|
|
|
),
|
|
|
|
)
|
2020-04-26 18:15:48 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
actions: <Widget>[
|
|
|
|
if (presence.sender != Matrix.of(context).client.userID)
|
|
|
|
FlatButton(
|
2020-05-07 07:52:40 +02:00
|
|
|
child: Text(L10n.of(context).sendAMessage),
|
2020-04-26 18:15:48 +02:00
|
|
|
onPressed: () async {
|
2020-05-13 15:58:59 +02:00
|
|
|
final roomId = await User(
|
2020-04-26 18:15:48 +02:00
|
|
|
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(
|
2020-05-07 07:52:40 +02:00
|
|
|
child: Text(L10n.of(context).close),
|
2020-04-26 18:15:48 +02:00
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: Container(
|
|
|
|
width: 80,
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
2020-04-27 13:36:39 +02:00
|
|
|
SizedBox(height: 9),
|
2020-04-26 18:15:48 +02:00
|
|
|
Avatar(avatarUrl, displayname),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(6.0),
|
|
|
|
child: Text(
|
|
|
|
displayname,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
maxLines: 1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|