diff --git a/lib/frontend/screens/chats/chat/view/chat_header.dart b/lib/frontend/screens/chats/chat/view/chat_header.dart index f460400..3f3de97 100644 --- a/lib/frontend/screens/chats/chat/view/chat_header.dart +++ b/lib/frontend/screens/chats/chat/view/chat_header.dart @@ -19,6 +19,7 @@ class ChatHeaderRow extends StatelessWidget { final ValueListenable headerStatus; final ValueListenable scheduledCount; final ValueListenable otherUnread; + final bool showCall; final VoidCallback? onClose; final VoidCallback onOpenInfo; final VoidCallback onOpenScheduled; @@ -39,6 +40,7 @@ class ChatHeaderRow extends StatelessWidget { required this.headerStatus, required this.scheduledCount, required this.otherUnread, + required this.showCall, required this.onClose, required this.onOpenInfo, required this.onOpenScheduled, @@ -191,10 +193,11 @@ class ChatHeaderRow extends StatelessWidget { ) : const SizedBox.shrink(), ), - IconButton( - icon: Icon(Symbols.call, weight: 500, color: cs.onSurface), - onPressed: onCall, - ), + if (showCall) + IconButton( + icon: Icon(Symbols.call, weight: 500, color: cs.onSurface), + onPressed: onCall, + ), Builder( builder: (btnContext) => IconButton( icon: Icon( @@ -335,10 +338,11 @@ class ChatHeaderRow extends StatelessWidget { ) : const SizedBox.shrink(), ), - IconButton( - icon: Icon(Symbols.call, weight: 400, color: cs.onSurface), - onPressed: onCall, - ), + if (showCall) + IconButton( + icon: Icon(Symbols.call, weight: 400, color: cs.onSurface), + onPressed: onCall, + ), Builder( builder: (btnContext) => IconButton( icon: Icon(Symbols.more_vert, weight: 400, color: cs.onSurface), diff --git a/lib/frontend/screens/chats/chat_screen.dart b/lib/frontend/screens/chats/chat_screen.dart index 14b4814..31630cc 100644 --- a/lib/frontend/screens/chats/chat_screen.dart +++ b/lib/frontend/screens/chats/chat_screen.dart @@ -311,6 +311,7 @@ class _ChatScreenState extends State int get _myId => _chatController.myId; set _myId(int v) => _chatController.myId = v; CachedChat? chat; + bool _peerIsBot = false; ChatWallpaper? _wallpaper; final ValueNotifier _composerHeight = ValueNotifier(96); @@ -425,11 +426,27 @@ class _ChatScreenState extends State } } + Future _loadPeerKind() async { + if (widget.chatType != 'DIALOG' || _myId == 0) return; + final peerId = widget.chatId ^ _myId; + if (peerId <= 0) return; + final cached = ContactInfoFetch.peek(peerId); + if (cached != null) _applyPeerKind(cached.isBot); + final info = await ContactInfoFetch.get(peerId); + if (info != null) _applyPeerKind(info.isBot); + } + + void _applyPeerKind(bool isBot) { + if (!mounted || _peerIsBot == isBot) return; + setState(() => _peerIsBot = isBot); + } + Future _fastPreloadCache() async { final p = await AppDatabase.loadActiveProfile(); if (!mounted) return; _myId = p?.id ?? 0; _restoreDraft(); + unawaited(_loadPeerKind()); unawaited(_loadWallpaper()); unawaited(_refreshBadge()); @@ -1744,6 +1761,8 @@ class _ChatScreenState extends State headerStatus: _headerStatusNotifier, scheduledCount: _scheduledCount, otherUnread: _otherUnread, + showCall: + widget.chatType == 'DIALOG' && !_peerIsBot, onClose: widget.onClose, onOpenInfo: () => Navigator.push( context, @@ -1981,7 +2000,7 @@ class _ChatScreenState extends State } Future _startCall() async { - if (widget.chatType != 'DIALOG') { + if (widget.chatType != 'DIALOG' || _peerIsBot) { showCustomNotification(context, 'Звонки доступны только в диалогах'); return; } diff --git a/lib/models/contact_info.dart b/lib/models/contact_info.dart index 4e02ac4..a938c78 100644 --- a/lib/models/contact_info.dart +++ b/lib/models/contact_info.dart @@ -67,5 +67,7 @@ class ContactInfo { return o is List ? o.whereType().toList() : const []; } + bool get isBot => options.contains('BOT'); + int? get id => raw['id'] as int?; }