FurryChat/lib/components/list_items/presence_list_item.dart

100 lines
3.2 KiB
Dart
Raw Normal View History

import 'package:famedlysdk/famedlysdk.dart';
2020-06-19 13:10:26 +00:00
import 'package:fluffychat/components/dialogs/presence_dialog.dart';
2020-06-18 11:39:24 +00: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';
class PresenceListItem extends StatelessWidget {
2020-06-19 13:10:26 +00:00
final Room room;
2020-06-19 13:10:26 +00:00
const PresenceListItem(this.room);
2020-06-18 11:39:24 +00:00
void _startChatAction(BuildContext context, String userId) async {
final roomId = await User(userId,
room: Room(client: Matrix.of(context).client, id: ''))
.startDirectChat();
await Navigator.of(context).pushAndRemoveUntil(
AppRoute.defaultRoute(
context,
ChatView(roomId),
),
(Route r) => r.isFirst);
2020-05-06 15:45:59 +00:00
}
@override
Widget build(BuildContext context) {
2020-06-19 13:10:26 +00:00
final user = room.getUserByMXIDSync(room.directChatMatrixID);
final presence =
Matrix.of(context).client.presences[room.directChatMatrixID];
2020-08-23 16:10:33 +00:00
final hasStatus = presence?.presence?.statusMsg != null;
2020-06-19 13:10:26 +00:00
return InkWell(
onTap: () => presence?.presence?.statusMsg == null
? _startChatAction(context, user.id)
: showDialog(
context: context,
builder: (_) => PresenceDialog(
presence,
avatarUrl: user.avatarUrl,
displayname: user.calcDisplayname(),
),
),
2020-06-19 13:10:26 +00:00
child: Container(
width: 80,
child: Column(
children: <Widget>[
2020-06-24 07:42:28 +00:00
SizedBox(height: 16),
2020-06-27 11:09:21 +00:00
Container(
2020-08-23 16:10:33 +00:00
child: Stack(
children: [
Avatar(user.avatarUrl, user.calcDisplayname()),
if (presence?.presence?.currentlyActive == true)
Positioned(
bottom: 0,
right: 0,
child: Container(
width: 10,
height: 10,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.green,
),
),
),
],
),
2020-06-27 11:09:21 +00:00
decoration: BoxDecoration(
border: Border.all(
width: 1,
2020-08-23 16:10:33 +00:00
color: !hasStatus
? Theme.of(context).secondaryHeaderColor
2020-06-27 11:09:21 +00:00
: Theme.of(context).primaryColor,
),
borderRadius: BorderRadius.circular(80),
),
padding: EdgeInsets.all(2),
),
2020-06-19 13:10:26 +00:00
Padding(
2020-06-27 11:09:21 +00:00
padding: const EdgeInsets.only(left: 6.0, top: 0.0, right: 6.0),
2020-06-19 13:10:26 +00:00
child: Text(
2020-06-27 11:09:21 +00:00
user.calcDisplayname().trim().split(' ').first,
overflow: TextOverflow.clip,
2020-06-19 13:10:26 +00:00
maxLines: 1,
style: TextStyle(
2020-06-27 11:09:21 +00:00
color: Theme.of(context)
.textTheme
.bodyText2
.color
2020-08-23 16:10:33 +00:00
.withOpacity(hasStatus ? 1 : 0.66),
2020-06-24 07:42:28 +00:00
fontSize: 13,
2020-06-19 13:10:26 +00:00
),
),
),
],
),
),
);
}
}