From be74a94f50498b1be48a2bc98dba609a38ec415e Mon Sep 17 00:00:00 2001 From: otsmr Date: Tue, 16 Jun 2026 17:44:04 +0200 Subject: [PATCH] hide buttons if accounced user was set to be hidden --- lib/src/database/daos/user_discovery.dao.dart | 6 ++ .../entries/chat_ask_a_friend.entry.dart | 101 ++++++++++-------- 2 files changed, 62 insertions(+), 45 deletions(-) diff --git a/lib/src/database/daos/user_discovery.dao.dart b/lib/src/database/daos/user_discovery.dao.dart index fdffed46..07104a01 100644 --- a/lib/src/database/daos/user_discovery.dao.dart +++ b/lib/src/database/daos/user_discovery.dao.dart @@ -234,6 +234,12 @@ class UserDiscoveryDao extends DatabaseAccessor )..where((tbl) => tbl.announcedUserId.equals(id))).getSingleOrNull(); } + Stream watchAnnouncedUser(int id) { + return (select(userDiscoveryAnnouncedUsers) + ..where((tbl) => tbl.announcedUserId.equals(id))) + .watchSingleOrNull(); + } + Stream> watchAllAnnouncedUsers() => select(userDiscoveryAnnouncedUsers).watch(); diff --git a/lib/src/visual/views/chats/chat_messages_components/entries/chat_ask_a_friend.entry.dart b/lib/src/visual/views/chats/chat_messages_components/entries/chat_ask_a_friend.entry.dart index 83c31467..b3f84610 100644 --- a/lib/src/visual/views/chats/chat_messages_components/entries/chat_ask_a_friend.entry.dart +++ b/lib/src/visual/views/chats/chat_messages_components/entries/chat_ask_a_friend.entry.dart @@ -256,8 +256,8 @@ class _ChatAskAFriendEntryState extends State { ] else ...[ StreamBuilder( stream: twonlyDB.contactsDao.watchContact(userId), - builder: (context, snapshot) { - final contactInDb = snapshot.data; + builder: (context, contactSnapshot) { + final contactInDb = contactSnapshot.data; if (contactInDb != null) { return Text( context.lang.chatAskAFriendAddedDescription, @@ -268,50 +268,61 @@ class _ChatAskAFriendEntryState extends State { ); } - return Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - TextButton( - onPressed: _isLoading ? null : _hideUser, - style: TextButton.styleFrom( - minimumSize: Size.zero, - padding: const EdgeInsets.symmetric( - horizontal: 12, - vertical: 6, - ), - ), - 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), + return StreamBuilder( + stream: + twonlyDB.userDiscoveryDao.watchAnnouncedUser(userId), + builder: (context, userSnapshot) { + final announcedUser = userSnapshot.data; + if (announcedUser != null && announcedUser.isHidden) { + return const SizedBox.shrink(); + } + + return Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + TextButton( + onPressed: _isLoading ? null : _hideUser, + style: TextButton.styleFrom( + minimumSize: Size.zero, + padding: const EdgeInsets.symmetric( + horizontal: 12, + vertical: 6, ), - ), - ], + ), + 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), + ), + ), + ], + ); + }, ); }, ),