android: add mention override for muted chat notifications
Some checks failed
CI / test (push) Failing after 2m18s
Some checks failed
CI / test (push) Failing after 2m18s
This commit is contained in:
@@ -84,6 +84,9 @@ interface ChatDao {
|
||||
@Query("SELECT display_title FROM chats WHERE id = :chatId LIMIT 1")
|
||||
suspend fun getChatDisplayTitle(chatId: Long): String?
|
||||
|
||||
@Query("SELECT muted FROM chats WHERE id = :chatId LIMIT 1")
|
||||
suspend fun isChatMuted(chatId: Long): Boolean?
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun upsertChats(chats: List<ChatEntity>)
|
||||
|
||||
|
||||
@@ -37,6 +37,11 @@ class RealtimeEventParser @Inject constructor(
|
||||
text = messageObject?.get("text").stringOrNull(),
|
||||
type = messageObject?.get("type").stringOrNull(),
|
||||
createdAt = messageObject?.get("created_at").stringOrNull(),
|
||||
isMention = messageObject?.get("is_mention").boolOrNull()
|
||||
?: payload["is_mention"].boolOrNull()
|
||||
?: messageObject?.get("mentions_me").boolOrNull()
|
||||
?: payload["mentions_me"].boolOrNull()
|
||||
?: false,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -119,4 +124,13 @@ class RealtimeEventParser @Inject constructor(
|
||||
private fun JsonElement?.longOrNull(): Long? {
|
||||
return this?.jsonPrimitive?.contentOrNull?.toLongOrNull()
|
||||
}
|
||||
|
||||
private fun JsonElement?.boolOrNull(): Boolean? {
|
||||
val raw = this?.jsonPrimitive?.contentOrNull?.trim()?.lowercase() ?: return null
|
||||
return when (raw) {
|
||||
"true", "1" -> true
|
||||
"false", "0" -> false
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ sealed interface RealtimeEvent {
|
||||
val text: String?,
|
||||
val type: String?,
|
||||
val createdAt: String?,
|
||||
val isMention: Boolean,
|
||||
) : RealtimeEvent
|
||||
|
||||
data class MessageUpdated(
|
||||
|
||||
@@ -75,7 +75,8 @@ class HandleRealtimeEventsUseCase @Inject constructor(
|
||||
)
|
||||
chatDao.incrementUnread(chatId = event.chatId)
|
||||
val activeChatId = activeChatTracker.activeChatId.value
|
||||
if (activeChatId != event.chatId) {
|
||||
val muted = chatDao.isChatMuted(event.chatId) == true
|
||||
if (activeChatId != event.chatId && (!muted || event.isMention)) {
|
||||
val title = chatDao.getChatDisplayTitle(event.chatId) ?: "New message"
|
||||
val body = event.text?.takeIf { it.isNotBlank() }
|
||||
?: when (event.type?.lowercase()) {
|
||||
@@ -92,6 +93,7 @@ class HandleRealtimeEventsUseCase @Inject constructor(
|
||||
messageId = event.messageId,
|
||||
title = title,
|
||||
body = body,
|
||||
isMention = event.isMention,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user