Steps towards better notifications

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2020-02-13 17:47:20 +01:00
parent 550eba9de4
commit e079601dad
No known key found for this signature in database
GPG Key ID: CDE0BBD2738C4CC0
10 changed files with 175 additions and 8 deletions

View File

@ -26,8 +26,10 @@ import com.nextcloud.talk.models.json.capabilities.CapabilitiesOverall
import com.nextcloud.talk.models.json.conversations.Conversation
import com.nextcloud.talk.models.json.conversations.ConversationOverall
import com.nextcloud.talk.models.json.generic.GenericOverall
import com.nextcloud.talk.models.json.notifications.NotificationOverall
import com.nextcloud.talk.models.json.participants.AddParticipantOverall
import com.nextcloud.talk.models.json.participants.Participant
import com.nextcloud.talk.models.json.participants.ParticipantsOverall
import com.nextcloud.talk.models.json.push.PushRegistrationOverall
import com.nextcloud.talk.models.json.signaling.settings.SignalingSettingsOverall
import com.nextcloud.talk.models.json.userprofile.UserProfileOverall
@ -59,16 +61,16 @@ class NextcloudTalkRepositoryImpl(private val apiService: ApiService) : Nextclou
)
}
override suspend fun getConversationForUser(userEntity: UserNgEntity, conversationToken: String): ConversationOverall {
return apiService.getConversation(userEntity.getCredentials(), conversationToken)
override suspend fun getConversationForUser(user: UserNgEntity, conversationToken: String): ConversationOverall {
return apiService.getConversation(user.getCredentials(), conversationToken)
}
override suspend fun joinConversationForUser(userNgEntity: UserNgEntity, conversationToken: String, conversationPassword: String?): ConversationOverall {
return apiService.joinConversation(userNgEntity.getCredentials(), ApiUtils.getUrlForSettingMyselfAsActiveParticipant(userNgEntity.baseUrl, conversationToken), conversationPassword)
override suspend fun joinConversationForUser(user: UserNgEntity, conversationToken: String, conversationPassword: String?): ConversationOverall {
return apiService.joinConversation(user.getCredentials(), ApiUtils.getUrlForSettingMyselfAsActiveParticipant(user.baseUrl, conversationToken), conversationPassword)
}
override suspend fun exitConversationForUser(userNgEntity: UserNgEntity, conversationToken: String): GenericOverall {
return apiService.exitConversation(userNgEntity.getCredentials(), ApiUtils.getUrlForSettingMyselfAsActiveParticipant(userNgEntity.baseUrl, conversationToken))
override suspend fun exitConversationForUser(user: UserNgEntity, conversationToken: String): GenericOverall {
return apiService.exitConversation(user.getCredentials(), ApiUtils.getUrlForSettingMyselfAsActiveParticipant(user.baseUrl, conversationToken))
}
override suspend fun getCapabilitiesForServer(server: String): CapabilitiesOverall {
@ -93,6 +95,14 @@ class NextcloudTalkRepositoryImpl(private val apiService: ApiService) : Nextclou
}
}
override suspend fun getNotificationForUser(user: UserNgEntity, notificationId: String): NotificationOverall {
return apiService.getNotification(user.getCredentials(), ApiUtils.getUrlForNotificationWithId(user.baseUrl, notificationId))
}
override suspend fun getPeersForCall(user: UserNgEntity, conversationToken: String): ParticipantsOverall {
return apiService.getPeersForCall(user.getCredentials(), ApiUtils.getUrlForCall(user.baseUrl, conversationToken))
}
override suspend fun setPasswordForConversation(user: UserNgEntity, conversationToken: String, password: String): GenericOverall {
return apiService.setPasswordForConversation(user.getCredentials(), ApiUtils.getUrlForPassword(user.baseUrl, conversationToken), password)
}

View File

@ -27,13 +27,24 @@ import com.nextcloud.talk.models.json.capabilities.CapabilitiesOverall
import com.nextcloud.talk.models.json.conversations.ConversationOverall
import com.nextcloud.talk.models.json.conversations.RoomsOverall
import com.nextcloud.talk.models.json.generic.GenericOverall
import com.nextcloud.talk.models.json.notifications.NotificationOverall
import com.nextcloud.talk.models.json.participants.AddParticipantOverall
import com.nextcloud.talk.models.json.participants.ParticipantsOverall
import com.nextcloud.talk.models.json.push.PushRegistrationOverall
import com.nextcloud.talk.models.json.signaling.settings.SignalingSettingsOverall
import com.nextcloud.talk.models.json.userprofile.UserProfileOverall
import io.reactivex.Observable
import retrofit2.http.*
interface ApiService {
@GET
suspend fun getPeersForCall(@Header("Authorization") authorization: String,
@Url url: String): ParticipantsOverall
@GET
suspend fun getNotification(@Header("Authorization") authorization: String,
@Url url: String): NotificationOverall
@FormUrlEncoded
@PUT
suspend fun setPasswordForConversation(@Header("Authorization") authorization: String,

View File

@ -46,6 +46,7 @@ import com.nextcloud.talk.newarch.domain.repository.online.NextcloudTalkReposito
import com.nextcloud.talk.newarch.utils.NetworkUtils
import com.nextcloud.talk.newarch.utils.NetworkUtils.GetProxyRunnable
import com.nextcloud.talk.newarch.utils.NetworkUtils.MagicAuthenticator
import com.nextcloud.talk.newarch.utils.NextcloudRepositoryWithNoCookies
import com.nextcloud.talk.utils.LoggingUtils
import com.nextcloud.talk.utils.preferences.AppPreferences
import com.nextcloud.talk.utils.singletons.AvatarStatusCodeHolder
@ -87,10 +88,15 @@ val NetworkModule = module {
single { createOkHttpClient(androidContext(), get(), get(), get(), get(), get(), get(), get()) }
factory { createApiErrorHandler() }
single { createNextcloudTalkRepository(get()) }
single { createNexcloudRepositoryWithNoCookies(get(), get())}
single { createImageLoader(androidApplication(), get()) }
}
fun createNexcloudRepositoryWithNoCookies(okHttpClient: OkHttpClient, retrofit: Retrofit): NextcloudRepositoryWithNoCookies {
return NextcloudRepositoryWithNoCookies(okHttpClient, retrofit)
}
fun createCookieManager(): CookieManager {
val cookieManager = CookieManager()
cookieManager.setCookiePolicy(ACCEPT_ALL)

View File

@ -51,9 +51,22 @@ val UseCasesModule = module {
single { createCreateConversationUseCase(get(), get()) }
single { createAddParticipantToConversationUseCase(get(), get()) }
single { setConversationPasswordUseCase(get(), get()) }
factory { getPeersForCallUseCase(get(), get()) }
factory { getNotificationUseCase(get(), get()) }
factory { createChatViewModelFactory(get(), get(), get(), get(), get(), get()) }
}
fun getNotificationUseCase(nextcloudTalkRepository: NextcloudTalkRepository,
apiErrorHandler: ApiErrorHandler): GetNotificationUseCase {
return GetNotificationUseCase(nextcloudTalkRepository, apiErrorHandler)
}
fun getPeersForCallUseCase(nextcloudTalkRepository: NextcloudTalkRepository,
apiErrorHandler: ApiErrorHandler): GetPeersForCallUseCase {
return GetPeersForCallUseCase(nextcloudTalkRepository, apiErrorHandler)
}
fun setConversationPasswordUseCase(nextcloudTalkRepository: NextcloudTalkRepository,
apiErrorHandler: ApiErrorHandler): SetConversationPasswordUseCase {
return SetConversationPasswordUseCase(nextcloudTalkRepository, apiErrorHandler)

View File

@ -26,14 +26,18 @@ import com.nextcloud.talk.models.json.capabilities.CapabilitiesOverall
import com.nextcloud.talk.models.json.conversations.Conversation
import com.nextcloud.talk.models.json.conversations.ConversationOverall
import com.nextcloud.talk.models.json.generic.GenericOverall
import com.nextcloud.talk.models.json.notifications.NotificationOverall
import com.nextcloud.talk.models.json.participants.AddParticipantOverall
import com.nextcloud.talk.models.json.participants.Participant
import com.nextcloud.talk.models.json.participants.ParticipantsOverall
import com.nextcloud.talk.models.json.push.PushRegistrationOverall
import com.nextcloud.talk.models.json.signaling.settings.SignalingSettingsOverall
import com.nextcloud.talk.models.json.userprofile.UserProfileOverall
import com.nextcloud.talk.newarch.local.models.UserNgEntity
interface NextcloudTalkRepository {
suspend fun getNotificationForUser(user: UserNgEntity, notificationId: String): NotificationOverall
suspend fun getPeersForCall(user: UserNgEntity, conversationToken: String): ParticipantsOverall
suspend fun setPasswordForConversation(user: UserNgEntity, conversationToken: String, password: String): GenericOverall
suspend fun addParticipantToConversation(user: UserNgEntity, conversationToken: String, participantId: String, source: String): AddParticipantOverall
suspend fun createConversationForUser(user: UserNgEntity, conversationType: Int, invite: String?, source: String?, conversationName: String?): ConversationOverall

View File

@ -0,0 +1,39 @@
/*
*
* * Nextcloud Talk application
* *
* * @author Mario Danic
* * Copyright (C) 2017-2020 Mario Danic <mario@lovelyhq.com>
* *
* * This program is free software: you can redistribute it and/or modify
* * it under the terms of the GNU General Public License as published by
* * the Free Software Foundation, either version 3 of the License, or
* * at your option) any later version.
* *
* * This program is distributed in the hope that it will be useful,
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* * GNU General Public License for more details.
* *
* * You should have received a copy of the GNU General Public License
* * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.nextcloud.talk.newarch.domain.usecases
import com.nextcloud.talk.models.json.notifications.NotificationOverall
import com.nextcloud.talk.newarch.data.source.remote.ApiErrorHandler
import com.nextcloud.talk.newarch.domain.repository.online.NextcloudTalkRepository
import com.nextcloud.talk.newarch.domain.usecases.base.UseCase
import org.koin.core.parameter.DefinitionParameters
class GetNotificationUseCase constructor(
private val nextcloudTalkRepository: NextcloudTalkRepository,
apiErrorHandler: ApiErrorHandler?
) : UseCase<NotificationOverall, Any?>(apiErrorHandler) {
override suspend fun run(params: Any?): NotificationOverall {
val definitionParameters = params as DefinitionParameters
return nextcloudTalkRepository.getNotificationForUser(definitionParameters[0], definitionParameters[0])
}
}

View File

@ -0,0 +1,39 @@
/*
*
* * Nextcloud Talk application
* *
* * @author Mario Danic
* * Copyright (C) 2017-2020 Mario Danic <mario@lovelyhq.com>
* *
* * This program is free software: you can redistribute it and/or modify
* * it under the terms of the GNU General Public License as published by
* * the Free Software Foundation, either version 3 of the License, or
* * at your option) any later version.
* *
* * This program is distributed in the hope that it will be useful,
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* * GNU General Public License for more details.
* *
* * You should have received a copy of the GNU General Public License
* * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.nextcloud.talk.newarch.domain.usecases
import com.nextcloud.talk.models.json.participants.ParticipantsOverall
import com.nextcloud.talk.newarch.data.source.remote.ApiErrorHandler
import com.nextcloud.talk.newarch.domain.repository.online.NextcloudTalkRepository
import com.nextcloud.talk.newarch.domain.usecases.base.UseCase
import org.koin.core.parameter.DefinitionParameters
class GetPeersForCallUseCase constructor(
private val nextcloudTalkRepository: NextcloudTalkRepository,
apiErrorHandler: ApiErrorHandler?
) : UseCase<ParticipantsOverall, Any?>(apiErrorHandler) {
override suspend fun run(params: Any?): ParticipantsOverall {
val definitionParameters = params as DefinitionParameters
return nextcloudTalkRepository.getPeersForCall(definitionParameters[0], definitionParameters[1])
}
}

View File

@ -33,6 +33,7 @@ import java.net.Proxy.Type
import java.net.Proxy.Type.SOCKS
class NetworkUtils {
class HeadersInterceptor : Interceptor {
@Throws(IOException::class)

View File

@ -0,0 +1,44 @@
/*
*
* * Nextcloud Talk application
* *
* * @author Mario Danic
* * Copyright (C) 2017-2020 Mario Danic <mario@lovelyhq.com>
* *
* * This program is free software: you can redistribute it and/or modify
* * it under the terms of the GNU General Public License as published by
* * the Free Software Foundation, either version 3 of the License, or
* * at your option) any later version.
* *
* * This program is distributed in the hope that it will be useful,
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* * GNU General Public License for more details.
* *
* * You should have received a copy of the GNU General Public License
* * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.nextcloud.talk.newarch.utils
import com.nextcloud.talk.newarch.data.repository.online.NextcloudTalkRepositoryImpl
import com.nextcloud.talk.newarch.data.source.remote.ApiService
import com.nextcloud.talk.newarch.domain.repository.online.NextcloudTalkRepository
import okhttp3.JavaNetCookieJar
import okhttp3.OkHttpClient
import org.koin.core.KoinComponent
import retrofit2.Retrofit
import java.net.CookieManager
class NextcloudRepositoryWithNoCookies(
private val okHttpClient: OkHttpClient,
private val retrofit: Retrofit
) : KoinComponent {
fun getRepository(): NextcloudTalkRepository {
return NextcloudTalkRepositoryImpl(retrofit.newBuilder().client(
okHttpClient.newBuilder().cookieJar(JavaNetCookieJar(CookieManager())).build())
.build().create(ApiService::class.java))
}
}

View File

@ -91,7 +91,7 @@ object NotificationUtils {
fun getNotificationChannelId(context: Context, channelName: String,
channelDescription: String, enableLights: Boolean,
importance: Int, sound: Uri, audioAttributes: AudioAttributes, vibrationPattern: LongArray?, bypassDnd: Boolean, lockScreenVisibility: Integer?): String {
importance: Int, sound: Uri, audioAttributes: AudioAttributes, vibrationPattern: LongArray?, bypassDnd: Boolean, lockScreenVisibility: Int?): String {
val channelId = Objects.hash(channelName, channelDescription, enableLights, importance, sound, audioAttributes, vibrationPattern, bypassDnd, lockScreenVisibility).toString()
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
@ -106,7 +106,7 @@ object NotificationUtils {
channelId: String, channelName: String,
channelDescription: String, enableLights: Boolean,
importance: Int, sound: Uri, audioAttributes: AudioAttributes,
vibrationPattern: LongArray?, bypassDnd: Boolean = false, lockScreenVisibility: Integer?) {
vibrationPattern: LongArray?, bypassDnd: Boolean = false, lockScreenVisibility: Int?) {
val notificationManagerCompat = NotificationManagerCompat.from(context)
if (notificationManagerCompat.getNotificationChannel(channelId) == null) {