mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-26 14:45:22 +00:00
Implement favorites, notifications, and improve fragment handling
- Add favorites functionality for peers with persistent storage - Star icon to toggle favorites in sidebar - Favorites appear at top of peer list - Storage persists across app launches using peer ID - Add local notifications for mentions and private messages - Notifications appear when app is in background - Separate notification types for mentions vs private messages - Request notification permissions on app launch - Fix sidebar header alignment to match main toolbar (44pt) - Add background color to sidebar header for visual consistency - Improve voice note fragment transmission - Send fragments in batches of 5 with delays to prevent congestion - Better logging to debug fragment transmission issues - Reduce delay between fragments from 50ms to batch-based timing - Fix other UI issues - Ensure mic recording ripples originate from mic button - Update sidebar to swipe from right edge smoothly
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import Foundation
|
||||
#if os(iOS)
|
||||
import UIKit
|
||||
import UserNotifications
|
||||
#else
|
||||
import UserNotifications
|
||||
#endif
|
||||
|
||||
class NotificationService {
|
||||
static let shared = NotificationService()
|
||||
|
||||
private init() {}
|
||||
|
||||
func requestAuthorization() {
|
||||
#if os(iOS)
|
||||
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
|
||||
if granted {
|
||||
print("[NOTIFICATIONS] Permission granted")
|
||||
} else if let error = error {
|
||||
print("[NOTIFICATIONS] Permission error: \(error)")
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
func sendLocalNotification(title: String, body: String, identifier: String) {
|
||||
#if os(iOS)
|
||||
guard UIApplication.shared.applicationState == .background else {
|
||||
print("[NOTIFICATIONS] App is in foreground, skipping notification")
|
||||
return
|
||||
}
|
||||
|
||||
let content = UNMutableNotificationContent()
|
||||
content.title = title
|
||||
content.body = body
|
||||
content.sound = .default
|
||||
|
||||
let request = UNNotificationRequest(
|
||||
identifier: identifier,
|
||||
content: content,
|
||||
trigger: nil // Deliver immediately
|
||||
)
|
||||
|
||||
UNUserNotificationCenter.current().add(request) { error in
|
||||
if let error = error {
|
||||
print("[NOTIFICATIONS] Error sending notification: \(error)")
|
||||
} else {
|
||||
print("[NOTIFICATIONS] Notification sent: \(title)")
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
func sendMentionNotification(from sender: String, message: String) {
|
||||
let title = "Mentioned by \(sender)"
|
||||
let body = message
|
||||
let identifier = "mention-\(UUID().uuidString)"
|
||||
|
||||
sendLocalNotification(title: title, body: body, identifier: identifier)
|
||||
}
|
||||
|
||||
func sendPrivateMessageNotification(from sender: String, message: String) {
|
||||
let title = "Private message from \(sender)"
|
||||
let body = message
|
||||
let identifier = "private-\(UUID().uuidString)"
|
||||
|
||||
sendLocalNotification(title: title, body: body, identifier: identifier)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user