mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 02:05:20 +00:00
on focus (#189)
This commit is contained in:
@@ -55,7 +55,8 @@ class ChatViewModel(
|
|||||||
notificationManager = notificationManager,
|
notificationManager = notificationManager,
|
||||||
coroutineScope = viewModelScope,
|
coroutineScope = viewModelScope,
|
||||||
onHapticFeedback = { ChatViewModelUtils.triggerHapticFeedback(application.applicationContext) },
|
onHapticFeedback = { ChatViewModelUtils.triggerHapticFeedback(application.applicationContext) },
|
||||||
getMyPeerID = { meshService.myPeerID }
|
getMyPeerID = { meshService.myPeerID },
|
||||||
|
getMeshService = { meshService }
|
||||||
)
|
)
|
||||||
|
|
||||||
// Expose state through LiveData (maintaining the same interface)
|
// Expose state through LiveData (maintaining the same interface)
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ class MeshDelegateHandler(
|
|||||||
private val notificationManager: NotificationManager,
|
private val notificationManager: NotificationManager,
|
||||||
private val coroutineScope: CoroutineScope,
|
private val coroutineScope: CoroutineScope,
|
||||||
private val onHapticFeedback: () -> Unit,
|
private val onHapticFeedback: () -> Unit,
|
||||||
private val getMyPeerID: () -> String
|
private val getMyPeerID: () -> String,
|
||||||
|
private val getMeshService: () -> Any
|
||||||
) : BluetoothMeshDelegate {
|
) : BluetoothMeshDelegate {
|
||||||
|
|
||||||
override fun didReceiveMessage(message: BitchatMessage) {
|
override fun didReceiveMessage(message: BitchatMessage) {
|
||||||
@@ -47,6 +48,11 @@ class MeshDelegateHandler(
|
|||||||
// Private message
|
// Private message
|
||||||
privateChatManager.handleIncomingPrivateMessage(message)
|
privateChatManager.handleIncomingPrivateMessage(message)
|
||||||
|
|
||||||
|
// Reactive read receipts: Send immediately if user is currently viewing this chat
|
||||||
|
message.senderPeerID?.let { senderPeerID ->
|
||||||
|
sendReadReceiptIfFocused(senderPeerID)
|
||||||
|
}
|
||||||
|
|
||||||
// Show notification with enhanced information - now includes senderPeerID
|
// Show notification with enhanced information - now includes senderPeerID
|
||||||
message.senderPeerID?.let { senderPeerID ->
|
message.senderPeerID?.let { senderPeerID ->
|
||||||
// Use nickname if available, fall back to sender or senderPeerID
|
// Use nickname if available, fall back to sender or senderPeerID
|
||||||
@@ -153,5 +159,26 @@ class MeshDelegateHandler(
|
|||||||
return privateChatManager.isFavorite(peerID)
|
return privateChatManager.isFavorite(peerID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send read receipts reactively based on UI focus state.
|
||||||
|
* Uses same logic as notification system - send read receipt if user is currently
|
||||||
|
* viewing the private chat with this sender AND app is in foreground.
|
||||||
|
*/
|
||||||
|
private fun sendReadReceiptIfFocused(senderPeerID: String) {
|
||||||
|
// Get notification manager's focus state (mirror the notification logic)
|
||||||
|
val isAppInBackground = notificationManager.getAppBackgroundState()
|
||||||
|
val currentPrivateChatPeer = notificationManager.getCurrentPrivateChatPeer()
|
||||||
|
|
||||||
|
// Send read receipt if user is currently focused on this specific chat
|
||||||
|
val shouldSendReadReceipt = !isAppInBackground && currentPrivateChatPeer == senderPeerID
|
||||||
|
|
||||||
|
if (shouldSendReadReceipt) {
|
||||||
|
android.util.Log.d("MeshDelegateHandler", "Sending reactive read receipt for focused chat with $senderPeerID")
|
||||||
|
privateChatManager.sendReadReceiptsForPeer(senderPeerID, getMeshService())
|
||||||
|
} else {
|
||||||
|
android.util.Log.d("MeshDelegateHandler", "Skipping read receipt - chat not focused (background: $isAppInBackground, current peer: $currentPrivateChatPeer, sender: $senderPeerID)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// registerPeerPublicKey REMOVED - fingerprints now handled centrally in PeerManager
|
// registerPeerPublicKey REMOVED - fingerprints now handled centrally in PeerManager
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -306,6 +306,20 @@ class NotificationManager(private val context: Context) {
|
|||||||
return pendingNotifications.values.sumOf { it.size }
|
return pendingNotifications.values.sumOf { it.size }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get app background state for reactive read receipts
|
||||||
|
*/
|
||||||
|
fun getAppBackgroundState(): Boolean {
|
||||||
|
return isAppInBackground
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current private chat peer for reactive read receipts
|
||||||
|
*/
|
||||||
|
fun getCurrentPrivateChatPeer(): String? {
|
||||||
|
return currentPrivateChatPeer
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get pending notifications for debugging
|
* Get pending notifications for debugging
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class PrivateChatManager(
|
|||||||
|
|
||||||
// Initialize chat if needed
|
// Initialize chat if needed
|
||||||
messageManager.initializePrivateChat(peerID)
|
messageManager.initializePrivateChat(peerID)
|
||||||
|
|
||||||
// Send read receipts for all unread messages from this peer
|
// Send read receipts for all unread messages from this peer
|
||||||
sendReadReceiptsForPeer(peerID, meshService)
|
sendReadReceiptsForPeer(peerID, meshService)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user