Implement smart notification system with intelligent content analysis

Major improvements to notification handling:
- Replace blanket skip_notifications with content source analysis
- Immediate notifications for external mentions, DMs, and posts from others
- Smart sound selection based on content type (mention/DM/timeline_update)
- Remove focus-based auto-refresh blocking for seamless background updates
- Fix notifications timeline AttributeError from removed skip_notifications
- Track user actions to prevent sound spam from own expected content
- Context-aware suppression only for user's own posts, not external content

User experience improvements:
- Never miss external mentions or DMs due to timing issues
- Auto-refresh works regardless of timeline focus
- Appropriate sounds play immediately for genuine external notifications
- No redundant sounds from user's own post actions

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Storm Dragon
2025-07-23 15:38:39 -04:00
parent cd535aebdf
commit 65f59533cf
4 changed files with 243 additions and 57 deletions

View File

@ -7,6 +7,57 @@ Bifrost is a fully accessible fediverse client built with PySide6, designed spec
- Check for any changes in git project before doing anything else. Make sure the latest changes have been pulled
- See what has changed, use git commands and examine the code to make sure you are up to date with the latest code
## Smart Notification System
Bifrost includes an intelligent notification system that distinguishes between user's own content and external content from others.
### Core Features
1. **Content Source Analysis**: Determines if new content is from current user or external users
2. **Immediate External Notifications**: Never suppresses sounds for genuine mentions, DMs, or posts from others
3. **Smart Sound Selection**: Plays appropriate sounds (mention, direct_message, timeline_update) based on content type
4. **Context-Aware Suppression**: Only suppresses sounds from user's own expected content
5. **No Timeline Switch Delays**: Auto-refresh works immediately without waiting for focus loss
### Implementation Details
#### Timeline Notification Logic (timeline_view.py:541-638)
```python
# Check if notifications should be suppressed (initial load, recent timeline switch)
suppress_all = self.should_suppress_notifications()
if not suppress_all:
# Analyze new content to separate external content from user's own
for post in new_posts:
if self.is_content_from_current_user(post):
user_content_detected = True
else:
external_content_detected = True
# Play sounds and notifications for external content only
if external_content_detected:
# Check for mentions, DMs, then fallback to timeline_update
```
#### User Action Tracking (timeline_view.py:155-175)
```python
def track_user_action(self, action_type: str, expected_content_hint: str = None):
"""Track user actions to avoid sound spam from expected results"""
action_info = {
'type': action_type,
'timestamp': time.time(),
'hint': expected_content_hint
}
self.recent_user_actions.append(action_info)
```
### Migration from Old System
**Removed:** `skip_notifications` blanket suppression flag
**Replaced with:** `should_suppress_notifications()` method that checks:
- Initial load state
- Timeline switch timing (3s delay for most timelines, 1s for notifications)
- But allows immediate external content notifications
## Duplicate Code Prevention Guidelines
### Critical Areas Requiring Attention
@ -14,7 +65,7 @@ Bifrost is a fully accessible fediverse client built with PySide6, designed spec
2. **UI Event Handlers**: Avoid circular event chains (A triggers B which triggers A)
3. **Timeline Operations**: Coordinate refresh calls and state changes to prevent conflicts
4. **Lifecycle Events**: Ensure shutdown, close, and quit events don't overlap
4. **Design**: Ensure single point of truth is used as much as possible through out the code. This means functionality should not be duplicated across files.
5. **Design**: Ensure single point of truth is used as much as possible throughout the code
### Required Patterns for Event-Heavy Operations
@ -690,4 +741,26 @@ content_text.setTextInteractionFlags(Qt.TextSelectableByKeyboard | Qt.TextSelect
- Content tab: Full post details in accessible text widget
- Interaction tabs: Who favorited/boosted in accessible lists
## Recent Major Changes (July 2025)
### Smart Notification System Implementation
**Problem Solved:** The old `skip_notifications` system suppressed ALL sounds for 1-3 seconds after user actions, causing users to miss important external content (mentions, DMs) that arrived during post-action refreshes.
**Solution Implemented:**
1. **Replaced blanket suppression** with content source analysis
2. **Immediate external notifications** - never suppress sounds for genuine mentions/DMs from others
3. **Context-aware sound selection** - different sounds for mentions vs DMs vs timeline updates
4. **Removed focus-based auto-refresh blocking** - auto-refresh now works regardless of timeline focus
5. **Fixed notifications timeline** - resolved AttributeError from removed `skip_notifications` references
**Key Files Modified:**
- `src/widgets/timeline_view.py`: Core notification logic, content analysis, auto-refresh improvements
- `src/main_window.py`: Updated notification suppression checks
**User Experience Impact:**
- Users now get immediate audio feedback for external content even during their own actions
- Auto-refresh works seamlessly without waiting for focus loss
- Notifications timeline properly loads without errors
- No more missed mentions or DMs due to timing issues
This document serves as the comprehensive development guide for Bifrost, ensuring all accessibility, functionality, and architectural decisions are preserved and can be referenced throughout development.