Query Notification Tray Item

Flexible Filtering

Query notifications with advanced filtering options for targeted retrieval

Pagination Support

Efficiently handle large notification sets with built-in pagination

Real-time Updates

Live collection updates for dynamic notification experiences

Multi-platform SDK

Consistent querying across iOS, Android, and Web platforms

Overview

The Query Notification Tray Item feature allows you to retrieve and filter notification tray items with powerful querying capabilities. This functionality is essential for building dynamic notification interfaces that can display relevant notifications based on user preferences, seen status, and notification types.

Architecture Overview

Key Features

Query Configuration

Pagination Implementation

class NotificationListViewController: UIViewController, UITableViewDataSource {
    private var notifications: [AmityNotificationTrayItem] = []
    private var liveCollection: AmityCollection<AmityNotificationTrayItem>?
    private var isLoading = false
    
    func loadMoreIfNeeded(at indexPath: IndexPath) {
        guard !isLoading,
              indexPath.row >= notifications.count - 5, // Load more when 5 items from end
              liveCollection?.hasNext == true else { return }
        
        isLoading = true
        liveCollection?.nextPage { [weak self] result in
            DispatchQueue.main.async {
                self?.isLoading = false
                switch result {
                case .success:
                    // Collection will update automatically through observer
                    break
                case .failure(let error):
                    self?.handlePaginationError(error)
                }
            }
        }
    }
    
    // MARK: - UITableViewDataSource
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return notifications.count + (liveCollection?.hasNext == true ? 1 : 0) // +1 for loading cell
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if indexPath.row >= notifications.count {
            // Return loading cell
            return tableView.dequeueReusableCell(withIdentifier: "LoadingCell", for: indexPath)
        }
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "NotificationCell", for: indexPath)
        configureCell(cell, with: notifications[indexPath.row])
        return cell
    }
}

Best Practices

Use Cases

Notification Feed

Display a chronological list of all user notifications with filtering optionsImplementation:
  • Use basic query with time-based sorting
  • Enable real-time updates for live experience
  • Implement pagination for performance

Unread Badge Counter

Show count of unseen notifications for UI badge indicatorsImplementation:
  • Query with seenStatus: 'unseen'
  • Use count from collection metadata
  • Refresh on app foreground/resume

Category-specific Views

Create separate views for different notification typesImplementation:
  • Filter by specific categories
  • Create dedicated UI for each type
  • Optimize queries for targeted content

User Activity Timeline

Show notifications from specific users or user groupsImplementation:
  • Use actor-based filtering
  • Combine with time range filters
  • Enable cross-referencing with user profiles

Error Handling