chore: Follow up presences

This commit is contained in:
krille-chan 2023-11-11 19:54:31 +01:00
parent a41dd4c60f
commit bee90019bb
No known key found for this signature in database
4 changed files with 80 additions and 64 deletions

View file

@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/pages/chat/chat.dart'; import 'package:fluffychat/pages/chat/chat.dart';
import 'package:fluffychat/utils/date_time_extension.dart'; import 'package:fluffychat/utils/date_time_extension.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
@ -41,33 +42,43 @@ class ChatAppBarTitle extends StatelessWidget {
), ),
const SizedBox(width: 12), const SizedBox(width: 12),
Expanded( Expanded(
child: ListTile( child: Column(
contentPadding: EdgeInsets.zero, crossAxisAlignment: CrossAxisAlignment.start,
title: Text( children: [
room.getLocalizedDisplayname(MatrixLocals(L10n.of(context)!)), Text(
maxLines: 1, room.getLocalizedDisplayname(MatrixLocals(L10n.of(context)!)),
overflow: TextOverflow.ellipsis, maxLines: 1,
style: const TextStyle( overflow: TextOverflow.ellipsis,
fontSize: 16, style: const TextStyle(
fontSize: 16,
),
), ),
), AnimatedSize(
subtitle: PresenceBuilder( duration: FluffyThemes.animationDuration,
userId: room.directChatMatrixID, child: PresenceBuilder(
builder: (context, presence) { userId: room.directChatMatrixID,
final lastActiveTimestamp = presence?.lastActiveTimestamp; builder: (context, presence) {
if (presence?.currentlyActive == true) { final lastActiveTimestamp = presence?.lastActiveTimestamp;
return Text(L10n.of(context)!.currentlyActive); final style = Theme.of(context).textTheme.bodySmall;
} if (presence?.currentlyActive == true) {
if (lastActiveTimestamp != null) { return Text(
return Text( L10n.of(context)!.currentlyActive,
L10n.of(context)!.lastActiveAgo( style: style,
lastActiveTimestamp.localizedTimeShort(context), );
), }
); if (lastActiveTimestamp != null) {
} return Text(
return const SizedBox.shrink(); L10n.of(context)!.lastActiveAgo(
}, lastActiveTimestamp.localizedTimeShort(context),
), ),
style: style,
);
}
return const SizedBox.shrink();
},
),
),
],
), ),
), ),
], ],

View file

@ -43,7 +43,6 @@ class SeenByRow extends StatelessWidget {
name: user.calcDisplayname(), name: user.calcDisplayname(),
size: 16, size: 16,
fontSize: 9, fontSize: 9,
presenceUserId: user.stateKey,
), ),
), ),
if (seenByUsers.length > maxAvatars) if (seenByUsers.length > maxAvatars)

View file

@ -32,46 +32,52 @@ class UserBottomSheetView extends StatelessWidget {
leading: CloseButton( leading: CloseButton(
onPressed: Navigator.of(context, rootNavigator: false).pop, onPressed: Navigator.of(context, rootNavigator: false).pop,
), ),
title: ListTile( title: Column(
contentPadding: EdgeInsets.zero, crossAxisAlignment: CrossAxisAlignment.start,
title: Text(displayname.trim().split(' ').first), children: [
subtitle: PresenceBuilder( Text(displayname),
userId: userId, PresenceBuilder(
client: client, userId: userId,
builder: (context, presence) { client: client,
if (presence == null) return const SizedBox.shrink(); builder: (context, presence) {
if (presence == null) return const SizedBox.shrink();
final dotColor = presence.presence.isOnline final dotColor = presence.presence.isOnline
? Colors.green ? Colors.green
: presence.presence.isUnavailable : presence.presence.isUnavailable
? Colors.orange ? Colors.red
: Colors.red; : Colors.grey;
final lastActiveTimestamp = presence.lastActiveTimestamp; final lastActiveTimestamp = presence.lastActiveTimestamp;
return Row( return Row(
children: [ children: [
Container( Container(
width: 8, width: 8,
height: 8, height: 8,
margin: const EdgeInsets.only(right: 8), margin: const EdgeInsets.only(right: 8),
decoration: BoxDecoration( decoration: BoxDecoration(
color: dotColor, color: dotColor,
borderRadius: BorderRadius.circular(16), borderRadius: BorderRadius.circular(16),
),
),
if (presence.currentlyActive == true)
Text(L10n.of(context)!.currentlyActive),
if (lastActiveTimestamp != null)
Text(
L10n.of(context)!.lastActiveAgo(
lastActiveTimestamp.localizedTimeShort(context),
), ),
), ),
], if (presence.currentlyActive == true)
); Text(
}, L10n.of(context)!.currentlyActive,
), style: Theme.of(context).textTheme.bodySmall,
),
if (lastActiveTimestamp != null)
Text(
L10n.of(context)!.lastActiveAgo(
lastActiveTimestamp.localizedTimeShort(context),
),
style: Theme.of(context).textTheme.bodySmall,
),
],
);
},
),
],
), ),
actions: [ actions: [
if (userId != client.userID && if (userId != client.userID &&

View file

@ -84,8 +84,8 @@ class Avatar extends StatelessWidget {
final dotColor = presence.presence.isOnline final dotColor = presence.presence.isOnline
? Colors.green ? Colors.green
: presence.presence.isUnavailable : presence.presence.isUnavailable
? Colors.orange ? Colors.red
: Colors.red; : Colors.grey;
return Positioned( return Positioned(
bottom: -4, bottom: -4,
right: -4, right: -4,