hide buttons if accounced user was set to be hidden

This commit is contained in:
otsmr 2026-06-16 17:44:04 +02:00
parent d528913e84
commit be74a94f50
2 changed files with 62 additions and 45 deletions

View file

@ -234,6 +234,12 @@ class UserDiscoveryDao extends DatabaseAccessor<TwonlyDB>
)..where((tbl) => tbl.announcedUserId.equals(id))).getSingleOrNull(); )..where((tbl) => tbl.announcedUserId.equals(id))).getSingleOrNull();
} }
Stream<UserDiscoveryAnnouncedUser?> watchAnnouncedUser(int id) {
return (select(userDiscoveryAnnouncedUsers)
..where((tbl) => tbl.announcedUserId.equals(id)))
.watchSingleOrNull();
}
Stream<List<UserDiscoveryAnnouncedUser>> watchAllAnnouncedUsers() => Stream<List<UserDiscoveryAnnouncedUser>> watchAllAnnouncedUsers() =>
select(userDiscoveryAnnouncedUsers).watch(); select(userDiscoveryAnnouncedUsers).watch();

View file

@ -256,8 +256,8 @@ class _ChatAskAFriendEntryState extends State<ChatAskAFriendEntry> {
] else ...[ ] else ...[
StreamBuilder<Contact?>( StreamBuilder<Contact?>(
stream: twonlyDB.contactsDao.watchContact(userId), stream: twonlyDB.contactsDao.watchContact(userId),
builder: (context, snapshot) { builder: (context, contactSnapshot) {
final contactInDb = snapshot.data; final contactInDb = contactSnapshot.data;
if (contactInDb != null) { if (contactInDb != null) {
return Text( return Text(
context.lang.chatAskAFriendAddedDescription, context.lang.chatAskAFriendAddedDescription,
@ -268,50 +268,61 @@ class _ChatAskAFriendEntryState extends State<ChatAskAFriendEntry> {
); );
} }
return Row( return StreamBuilder<UserDiscoveryAnnouncedUser?>(
mainAxisAlignment: MainAxisAlignment.end, stream:
children: [ twonlyDB.userDiscoveryDao.watchAnnouncedUser(userId),
TextButton( builder: (context, userSnapshot) {
onPressed: _isLoading ? null : _hideUser, final announcedUser = userSnapshot.data;
style: TextButton.styleFrom( if (announcedUser != null && announcedUser.isHidden) {
minimumSize: Size.zero, return const SizedBox.shrink();
padding: const EdgeInsets.symmetric( }
horizontal: 12,
vertical: 6, return Row(
), mainAxisAlignment: MainAxisAlignment.end,
), children: [
child: Text( TextButton(
context.lang.chatAskAFriendHide, onPressed: _isLoading ? null : _hideUser,
style: TextStyle( style: TextButton.styleFrom(
fontSize: 12, minimumSize: Size.zero,
color: widget.info.textColor, padding: const EdgeInsets.symmetric(
), horizontal: 12,
), vertical: 6,
),
const SizedBox(width: 8),
FilledButton(
style: FilledButton.styleFrom(
minimumSize: Size.zero,
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 6,
),
).merge(secondaryGreyButtonStyle(context)),
onPressed: _isLoading ? null : _requestUser,
child: _isLoading
? const SizedBox(
width: 12,
height: 12,
child: CircularProgressIndicator.adaptive(
strokeWidth: 2,
),
)
: Text(
context.lang.chatAskAFriendRequest,
style: const TextStyle(fontSize: 12),
), ),
), ),
], child: Text(
context.lang.chatAskAFriendHide,
style: TextStyle(
fontSize: 12,
color: widget.info.textColor,
),
),
),
const SizedBox(width: 8),
FilledButton(
style: FilledButton.styleFrom(
minimumSize: Size.zero,
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 6,
),
).merge(secondaryGreyButtonStyle(context)),
onPressed: _isLoading ? null : _requestUser,
child: _isLoading
? const SizedBox(
width: 12,
height: 12,
child: CircularProgressIndicator.adaptive(
strokeWidth: 2,
),
)
: Text(
context.lang.chatAskAFriendRequest,
style: const TextStyle(fontSize: 12),
),
),
],
);
},
); );
}, },
), ),