fluffychat/lib/components/list_items/presence_list_item.dart

69 lines
2.1 KiB
Dart
Raw Normal View History

import 'package:famedlysdk/famedlysdk.dart';
2020-06-19 15:10:26 +02:00
import 'package:fluffychat/components/dialogs/presence_dialog.dart';
2020-06-18 13:39:24 +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';
class PresenceListItem extends StatelessWidget {
2020-06-19 15:10:26 +02:00
final Room room;
2020-06-19 15:10:26 +02:00
const PresenceListItem(this.room);
2020-06-18 13:39:24 +02: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 17:45:59 +02:00
}
@override
Widget build(BuildContext context) {
2020-06-19 15:10:26 +02:00
final user = room.getUserByMXIDSync(room.directChatMatrixID);
final presence =
Matrix.of(context).client.presences[room.directChatMatrixID];
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 15:10:26 +02:00
child: Container(
width: 80,
child: Column(
children: <Widget>[
2020-06-24 09:42:28 +02:00
SizedBox(height: 16),
2020-06-19 15:10:26 +02:00
Avatar(user.avatarUrl, user.calcDisplayname()),
Padding(
2020-06-24 09:42:28 +02:00
padding: const EdgeInsets.only(left: 6.0, top: 6.0, right: 6.0),
2020-06-19 15:10:26 +02:00
child: Text(
user.calcDisplayname(),
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: TextStyle(
2020-06-24 09:42:28 +02:00
color: Color(0xFF555555),
fontSize: 13,
2020-06-19 15:10:26 +02:00
fontWeight: presence?.presence?.statusMsg == null
? null
: FontWeight.bold,
),
),
),
],
),
),
);
}
}