mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 08:25:22 +00:00
Add active peer notification (#273)
* adding notification for active peers + tests * adding a recently seen peer set to track if we've seen that peer before * changing back to notificationManager naming * fixing some weird formatting that occurred during merge conflict fix
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
package com.bitchat.android.ui
|
||||
|
||||
import androidx.lifecycle.LifecycleCoroutineScope
|
||||
import com.bitchat.android.mesh.BluetoothMeshDelegate
|
||||
import com.bitchat.android.mesh.BluetoothMeshService
|
||||
import com.bitchat.android.model.BitchatMessage
|
||||
import com.bitchat.android.model.DeliveryStatus
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.*
|
||||
import java.util.Date
|
||||
|
||||
/**
|
||||
* Handles all BluetoothMeshDelegate callbacks and routes them to appropriate managers
|
||||
@@ -70,7 +69,7 @@ class MeshDelegateHandler(
|
||||
} else {
|
||||
// Public message
|
||||
messageManager.addMessage(message)
|
||||
|
||||
|
||||
// Check for mentions in mesh chat
|
||||
checkAndTriggerMeshMentionNotification(message)
|
||||
}
|
||||
@@ -86,9 +85,10 @@ class MeshDelegateHandler(
|
||||
coroutineScope.launch {
|
||||
state.setConnectedPeers(peers)
|
||||
state.setIsConnected(peers.isNotEmpty())
|
||||
notificationManager.showActiveUserNotification(peers)
|
||||
// Flush router outbox for any peers that just connected (and their noiseHex aliases)
|
||||
runCatching { com.bitchat.android.services.MessageRouter.tryGetInstance()?.onPeersUpdated(peers) }
|
||||
|
||||
|
||||
// Clean up channel members who disconnected
|
||||
channelManager.cleanupDisconnectedMembers(peers, getMyPeerID())
|
||||
|
||||
@@ -180,7 +180,7 @@ class MeshDelegateHandler(
|
||||
private fun unifyChatsIntoPeer(targetPeerID: String, keysToMerge: List<String>) {
|
||||
com.bitchat.android.services.ConversationAliasResolver.unifyChatsIntoPeer(state, targetPeerID, keysToMerge)
|
||||
}
|
||||
|
||||
|
||||
override fun didReceiveChannelLeave(channel: String, fromPeer: String) {
|
||||
coroutineScope.launch {
|
||||
channelManager.removeChannelMember(channel, fromPeer)
|
||||
@@ -219,13 +219,13 @@ class MeshDelegateHandler(
|
||||
if (currentNickname.isNullOrEmpty()) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// Check if this message mentions the current user using @username format
|
||||
val isMention = checkForMeshMention(message.content, currentNickname)
|
||||
|
||||
|
||||
if (isMention) {
|
||||
android.util.Log.d("MeshDelegateHandler", "🔔 Triggering mesh mention notification from ${message.sender}")
|
||||
|
||||
|
||||
notificationManager.showMeshMentionNotification(
|
||||
senderNickname = message.sender,
|
||||
messageContent = message.content,
|
||||
@@ -236,14 +236,14 @@ class MeshDelegateHandler(
|
||||
android.util.Log.e("MeshDelegateHandler", "Error checking mesh mentions: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if the content mentions the current user with @username format (simple, no hash suffix)
|
||||
*/
|
||||
private fun checkForMeshMention(content: String, currentNickname: String): Boolean {
|
||||
// Simple mention pattern for mesh: @username (no hash suffix like geohash)
|
||||
val mentionPattern = "@([\\p{L}0-9_]+)".toRegex()
|
||||
|
||||
|
||||
return mentionPattern.findAll(content).any { match ->
|
||||
val mentionedUsername = match.groupValues[1]
|
||||
// Direct comparison for mesh mentions (no hash suffix to remove)
|
||||
|
||||
Reference in New Issue
Block a user