2023-10-10 03:53:34 -04:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
2023-10-03 13:00:59 -04:00
|
|
|
import 'package:recon/auxiliary.dart';
|
|
|
|
import 'package:recon/clients/messaging_client.dart';
|
|
|
|
import 'package:recon/models/message.dart';
|
|
|
|
import 'package:recon/models/users/friend.dart';
|
2023-11-10 19:23:25 -04:00
|
|
|
import 'package:recon/models/users/online_status.dart';
|
2023-10-03 13:00:59 -04:00
|
|
|
import 'package:recon/widgets/formatted_text.dart';
|
|
|
|
import 'package:recon/widgets/friends/friend_online_status_indicator.dart';
|
|
|
|
import 'package:recon/widgets/generic_avatar.dart';
|
|
|
|
import 'package:recon/widgets/messages/messages_list.dart';
|
2023-04-30 09:43:59 -04:00
|
|
|
|
|
|
|
class FriendListTile extends StatelessWidget {
|
2023-11-11 07:00:01 -04:00
|
|
|
const FriendListTile({required this.friend, required this.unreads, this.onTap, super.key});
|
2023-04-30 09:43:59 -04:00
|
|
|
|
|
|
|
final Friend friend;
|
2023-05-12 13:29:23 -04:00
|
|
|
final int unreads;
|
2023-05-03 14:03:46 -04:00
|
|
|
final Function? onTap;
|
2023-04-30 09:43:59 -04:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-09-29 03:51:46 -04:00
|
|
|
final imageUri = Aux.resdbToHttp(friend.userProfile.iconUrl);
|
2023-05-03 14:03:46 -04:00
|
|
|
final theme = Theme.of(context);
|
2023-10-01 15:14:38 -04:00
|
|
|
final mClient = Provider.of<MessagingClient>(context, listen: false);
|
2023-10-03 12:20:02 -04:00
|
|
|
final currentSession = friend.userStatus.currentSessionIndex == -1
|
|
|
|
? null
|
2023-11-11 07:00:01 -04:00
|
|
|
: friend.userStatus.decodedSessions.elementAtOrNull(friend.userStatus.currentSessionIndex);
|
2023-04-30 09:43:59 -04:00
|
|
|
return ListTile(
|
2023-05-29 10:14:07 -04:00
|
|
|
leading: GenericAvatar(
|
|
|
|
imageUri: imageUri,
|
|
|
|
),
|
2023-05-12 13:29:23 -04:00
|
|
|
trailing: unreads != 0
|
2023-05-29 10:14:07 -04:00
|
|
|
? Text(
|
|
|
|
"+$unreads",
|
2023-11-11 07:00:01 -04:00
|
|
|
style: theme.textTheme.bodyMedium?.copyWith(color: theme.colorScheme.primary),
|
2023-05-29 10:14:07 -04:00
|
|
|
)
|
2023-05-03 14:03:46 -04:00
|
|
|
: null,
|
2023-05-12 13:29:23 -04:00
|
|
|
title: Row(
|
|
|
|
children: [
|
|
|
|
Text(friend.username),
|
2023-05-29 10:14:07 -04:00
|
|
|
if (friend.isHeadless)
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 8),
|
|
|
|
child: Icon(
|
|
|
|
Icons.dns,
|
|
|
|
size: 12,
|
|
|
|
color: theme.colorScheme.onSecondaryContainer.withAlpha(150),
|
|
|
|
),
|
|
|
|
),
|
2023-05-12 13:29:23 -04:00
|
|
|
],
|
|
|
|
),
|
2023-05-07 07:38:45 -04:00
|
|
|
subtitle: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
FriendOnlineStatusIndicator(userStatus: friend.userStatus),
|
2023-05-29 10:14:07 -04:00
|
|
|
const SizedBox(
|
|
|
|
width: 4,
|
|
|
|
),
|
2023-11-11 07:00:01 -04:00
|
|
|
Text(toBeginningOfSentenceCase(friend.userStatus.onlineStatus.name) ?? "Unknown"),
|
2023-11-10 19:23:25 -04:00
|
|
|
if (!(friend.userStatus.onlineStatus == OnlineStatus.offline ||
|
|
|
|
friend.userStatus.onlineStatus == OnlineStatus.invisible))
|
|
|
|
if (currentSession != null) ...[
|
|
|
|
const Text(" in "),
|
|
|
|
if (currentSession.name.isNotEmpty)
|
|
|
|
Expanded(
|
|
|
|
child: FormattedText(
|
|
|
|
currentSession.formattedName,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
maxLines: 1,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
else
|
|
|
|
Expanded(
|
|
|
|
child: Text(
|
|
|
|
"${currentSession.accessLevel.toReadableString()} World",
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
maxLines: 1,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
] else if (friend.userStatus.appVersion.isNotEmpty)
|
2023-10-10 03:53:34 -04:00
|
|
|
Expanded(
|
|
|
|
child: Text(
|
2023-11-10 19:23:25 -04:00
|
|
|
" on version ${friend.userStatus.appVersion}",
|
2023-10-10 03:53:34 -04:00
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
maxLines: 1,
|
|
|
|
),
|
2023-11-10 19:23:25 -04:00
|
|
|
),
|
2023-05-07 07:38:45 -04:00
|
|
|
],
|
|
|
|
),
|
2023-05-03 14:03:46 -04:00
|
|
|
onTap: () async {
|
2023-05-06 11:47:36 -04:00
|
|
|
onTap?.call();
|
|
|
|
mClient.loadUserMessageCache(friend.id);
|
|
|
|
final unreads = mClient.getUnreadsForFriend(friend);
|
|
|
|
if (unreads.isNotEmpty) {
|
|
|
|
final readBatch = MarkReadBatch(
|
2023-05-06 13:24:28 -04:00
|
|
|
senderId: friend.id,
|
2023-05-06 11:47:36 -04:00
|
|
|
ids: unreads.map((e) => e.id).toList(),
|
|
|
|
readTime: DateTime.now(),
|
|
|
|
);
|
|
|
|
mClient.markMessagesRead(readBatch);
|
|
|
|
}
|
|
|
|
mClient.selectedFriend = friend;
|
|
|
|
await Navigator.of(context).push(
|
|
|
|
MaterialPageRoute(
|
2023-05-29 10:14:07 -04:00
|
|
|
builder: (context) => ChangeNotifierProvider<MessagingClient>.value(
|
2023-05-06 11:47:36 -04:00
|
|
|
value: mClient,
|
2023-05-29 14:16:23 -04:00
|
|
|
child: const MessagesList(),
|
2023-05-06 11:47:36 -04:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
mClient.selectedFriend = null;
|
2023-04-30 09:43:59 -04:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2023-05-07 07:38:45 -04:00
|
|
|
}
|