Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ androidComponents {
}
}

configurations.configureEach {
val tink = "com.google.crypto.tink:tink-android:1.21.0"
resolutionStrategy {
force(tink)
dependencySubstitution {
substitute(module("com.google.crypto.tink:tink")).using(module(tink))
}
}
}

dependencies {
implementation(platform(libs.androidx.compose.bom))
implementation(libs.bundles.androidx.compose)
Expand All @@ -126,6 +136,7 @@ dependencies {

implementation(platform(libs.firebase.bom))
implementation(libs.firebase.messaging)
implementation(libs.unifiedpush.connector)

implementation(libs.maplibre.compose)

Expand Down
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />

<queries>
<intent>
<action android:name="org.unifiedpush.android.connector.REGISTER" />
</intent>
</queries>

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/java/org/monogram/app/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import org.monogram.presentation.di.AppContainer
import org.monogram.presentation.di.KoinAppContainer
import java.io.PrintWriter
import java.io.StringWriter
import kotlin.jvm.java
import kotlin.system.exitProcess

class App : Application(), SingletonImageLoader.Factory {
Expand Down Expand Up @@ -86,10 +85,18 @@ class App : Application(), SingletonImageLoader.Factory {
val distrManager = get<DistrManager>()
val isGmsAvailable = distrManager.isGmsAvailable()
val isFcmAvailable = distrManager.isFcmAvailable()
val isUnifiedPushAvailable = distrManager.isUnifiedPushDistributorAvailable()

val prefs = get<AppPreferencesProvider>()
if (!(isGmsAvailable && isFcmAvailable) && prefs.pushProvider.value == PushProvider.FCM) {
prefs.setPushProvider(PushProvider.GMS_LESS)
val currentProvider = prefs.pushProvider.value
if (currentProvider == PushProvider.FCM && !(isGmsAvailable && isFcmAvailable)) {
val fallback =
if (isUnifiedPushAvailable) PushProvider.UNIFIED_PUSH else PushProvider.GMS_LESS
prefs.setPushProvider(fallback)
} else if (currentProvider == PushProvider.UNIFIED_PUSH && !isUnifiedPushAvailable) {
val fallback =
if (isGmsAvailable && isFcmAvailable) PushProvider.FCM else PushProvider.GMS_LESS
prefs.setPushProvider(fallback)
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/monogram/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class MainActivity : FragmentActivity() {
}

private fun startNotificationService() {
if (appPreferences.pushProvider.value == PushProvider.FCM) return
if (appPreferences.pushProvider.value != PushProvider.GMS_LESS) return
val intent = Intent(this, TdNotificationService::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(intent)
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/org/monogram/app/di/DistrManagerImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.google.android.gms.common.ConnectionResult
import com.google.android.gms.common.GoogleApiAvailability
import com.google.firebase.FirebaseApp
import org.monogram.domain.managers.DistrManager
import org.unifiedpush.android.connector.UnifiedPush

class DistrManagerImpl(private val context: Context) : DistrManager {
override fun isGmsAvailable(): Boolean {
Expand All @@ -16,6 +17,10 @@ class DistrManagerImpl(private val context: Context) : DistrManager {
return FirebaseApp.getApps(context).isNotEmpty()
}

override fun isUnifiedPushDistributorAvailable(): Boolean {
return UnifiedPush.getDistributors(context).isNotEmpty()
}

override fun isInstalledFromGooglePlay(): Boolean {
val installer = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
context.packageManager.getInstallSourceInfo(context.packageName).installingPackageName
Expand Down
1 change: 1 addition & 0 deletions data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ dependencies {
implementation(libs.androidx.media3.datasource)
implementation(platform(libs.firebase.bom))
implementation(libs.firebase.messaging)
implementation(libs.unifiedpush.connector)

implementation(libs.androidx.room.runtime)
implementation(libs.androidx.room.ktx)
Expand Down
8 changes: 8 additions & 0 deletions data/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
android:exported="false" />
<receiver android:name=".service.NotificationDismissReceiver" android:exported="false" />
<receiver android:name=".service.NotificationReadReceiver" android:exported="false"/>

<service
android:name=".service.UnifiedPushService"
android:exported="false">
<intent-filter>
<action android:name="org.unifiedpush.android.connector.PUSH_EVENT" />
</intent-filter>
</service>
<receiver android:name=".service.UpdateInstallReceiver" android:exported="false"/>
</application>

Expand Down
37 changes: 27 additions & 10 deletions data/src/main/java/org/monogram/data/chats/ChatModelFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ import org.monogram.core.DispatcherProvider
import org.monogram.data.core.coRunCatching
import org.monogram.data.db.dao.UserFullInfoDao
import org.monogram.data.gateway.TelegramGateway
import org.monogram.data.mapper.*
import org.monogram.data.mapper.ChatMapper
import org.monogram.data.mapper.isForcedVerifiedChat
import org.monogram.data.mapper.isForcedVerifiedUser
import org.monogram.data.mapper.isSponsoredUser
import org.monogram.data.mapper.isValidFilePath
import org.monogram.data.mapper.user.toEntity
import org.monogram.data.mapper.user.toTdApi
import org.monogram.data.notifications.NotificationMuteResolver
import org.monogram.data.notifications.NotificationScopeState
import org.monogram.domain.models.ChatModel
import org.monogram.domain.models.UsernamesModel
import org.monogram.domain.repository.AppPreferencesProvider
import org.monogram.domain.repository.NotificationSettingsRepository.TdNotificationScope
import java.util.concurrent.ConcurrentHashMap

class ChatModelFactory(
Expand All @@ -27,6 +34,7 @@ class ChatModelFactory(
private val typingManager: ChatTypingManager,
private val appPreferences: AppPreferencesProvider,
private val userFullInfoDao: UserFullInfoDao,
private val muteResolver: NotificationMuteResolver = NotificationMuteResolver(),
private val triggerUpdate: (Long?) -> Unit,
private val fetchUser: (Long) -> Unit
) {
Expand Down Expand Up @@ -260,15 +268,24 @@ class ChatModelFactory(
cache.usersCache[userId]?.firstName ?: run { fetchUser(userId); null }
}

val isMuted = when {
chat.notificationSettings.muteFor > 0 -> true
chat.notificationSettings.useDefaultMuteFor -> when {
isChannel -> !appPreferences.channelsNotifications.value
isSupergroup || chat.type is TdApi.ChatTypeBasicGroup -> !appPreferences.groupsNotifications.value
else -> !appPreferences.privateChatsNotifications.value
}
else -> false
}
val scopeState = NotificationScopeState(
loadedScopes = setOf(
TdNotificationScope.PRIVATE_CHATS,
TdNotificationScope.GROUPS,
TdNotificationScope.CHANNELS
),
enabledByScope = mapOf(
TdNotificationScope.PRIVATE_CHATS to appPreferences.privateChatsNotifications.value,
TdNotificationScope.GROUPS to appPreferences.groupsNotifications.value,
TdNotificationScope.CHANNELS to appPreferences.channelsNotifications.value
)
)

val isMuted = muteResolver.resolve(
chat = chat,
cachedSettings = null,
scopeState = scopeState
).isMuted

return chatMapper.mapChatToModel(
chat = chat,
Expand Down
Loading