Geohash notifications (#288)

* mention notifications

* notifications

* warning
This commit is contained in:
callebtc
2025-08-23 01:35:46 +02:00
committed by GitHub
parent 65afdfb92e
commit f13f3063c9
6 changed files with 646 additions and 27 deletions
@@ -70,6 +70,9 @@ class MeshDelegateHandler(
} else {
// Public message
messageManager.addMessage(message)
// Check for mentions in mesh chat
checkAndTriggerMeshMentionNotification(message)
}
// Periodic cleanup
@@ -124,6 +127,48 @@ class MeshDelegateHandler(
return privateChatManager.isFavorite(peerID)
}
/**
* Check for mentions in mesh messages and trigger notifications
*/
private fun checkAndTriggerMeshMentionNotification(message: BitchatMessage) {
try {
// Get user's current nickname
val currentNickname = state.getNicknameValue()
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,
senderPeerID = message.senderPeerID
)
}
} catch (e: Exception) {
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)
mentionedUsername.equals(currentNickname, ignoreCase = true)
}
}
/**
* Send read receipts reactively based on UI focus state.
* Uses same logic as notification system - send read receipt if user is currently