mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 19:49:33 +01:00
Modify ViewModel and Repository
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
8fdd1478bf
commit
24ca0d6def
@ -13,6 +13,7 @@ import com.nextcloud.talk.models.json.generic.GenericOverall
|
||||
import com.nextcloud.talk.models.json.participants.AddParticipantOverall
|
||||
import com.nextcloud.talk.models.json.participants.TalkBan
|
||||
import com.nextcloud.talk.models.json.participants.TalkBanOverall
|
||||
import com.nextcloud.talk.models.json.userAbsence.UserAbsenceOverall
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
import retrofit2.http.Body
|
||||
@ -197,4 +198,12 @@ interface NcApiCoroutines {
|
||||
@Url url: String,
|
||||
@Field("seconds") seconds: Int
|
||||
): GenericOverall
|
||||
|
||||
@GET
|
||||
suspend fun getOutOfOfficeStatusForUser(
|
||||
@Header("Authorization") authorization:String,
|
||||
@Url url:String
|
||||
): UserAbsenceOverall
|
||||
|
||||
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import com.nextcloud.talk.models.json.conversations.RoomOverall
|
||||
import com.nextcloud.talk.models.json.conversations.RoomsOverall
|
||||
import com.nextcloud.talk.models.json.generic.GenericOverall
|
||||
import com.nextcloud.talk.models.json.reminder.Reminder
|
||||
import com.nextcloud.talk.models.json.userAbsence.UserAbsenceOverall
|
||||
import io.reactivex.Observable
|
||||
import retrofit2.Response
|
||||
|
||||
@ -63,4 +64,6 @@ interface ChatNetworkDataSource {
|
||||
fun createRoom(credentials: String, url: String, map: Map<String, String>): Observable<RoomOverall>
|
||||
fun setChatReadMarker(credentials: String, url: String, previousMessageId: Int): Observable<GenericOverall>
|
||||
fun editChatMessage(credentials: String, url: String, text: String): Observable<ChatOverallSingleMessage>
|
||||
suspend fun getOutOfOfficeStatusForUser (credentials:String,baseUrl:String, userId:String): UserAbsenceOverall
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
package com.nextcloud.talk.chat.data.network
|
||||
|
||||
import com.nextcloud.talk.api.NcApi
|
||||
import com.nextcloud.talk.api.NcApiCoroutines
|
||||
import com.nextcloud.talk.data.user.model.User
|
||||
import com.nextcloud.talk.models.domain.ConversationModel
|
||||
import com.nextcloud.talk.models.json.capabilities.SpreedCapability
|
||||
@ -15,11 +16,12 @@ import com.nextcloud.talk.models.json.conversations.RoomOverall
|
||||
import com.nextcloud.talk.models.json.conversations.RoomsOverall
|
||||
import com.nextcloud.talk.models.json.generic.GenericOverall
|
||||
import com.nextcloud.talk.models.json.reminder.Reminder
|
||||
import com.nextcloud.talk.models.json.userAbsence.UserAbsenceOverall
|
||||
import com.nextcloud.talk.utils.ApiUtils
|
||||
import io.reactivex.Observable
|
||||
import retrofit2.Response
|
||||
|
||||
class RetrofitChatNetwork(private val ncApi: NcApi) : ChatNetworkDataSource {
|
||||
class RetrofitChatNetwork(private val ncApi: NcApi, private val ncApiCoroutines:NcApiCoroutines) : ChatNetworkDataSource {
|
||||
override fun getRoom(user: User, roomToken: String): Observable<ConversationModel> {
|
||||
val credentials: String = ApiUtils.getCredentials(user.username, user.token)!!
|
||||
val apiVersion = ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V3, 1))
|
||||
@ -178,4 +180,10 @@ class RetrofitChatNetwork(private val ncApi: NcApi) : ChatNetworkDataSource {
|
||||
override fun editChatMessage(credentials: String, url: String, text: String): Observable<ChatOverallSingleMessage> {
|
||||
return ncApi.editChatMessage(credentials, url, text).map { it }
|
||||
}
|
||||
|
||||
override suspend fun getOutOfOfficeStatusForUser(credentials: String, baseUrl: String, userId:String):
|
||||
UserAbsenceOverall {
|
||||
return ncApiCoroutines.getOutOfOfficeStatusForUser(credentials,
|
||||
ApiUtils.getUrlForOutOfOffice(baseUrl,userId))
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.nextcloud.talk.chat.data.ChatMessageRepository
|
||||
import com.nextcloud.talk.chat.data.io.AudioFocusRequestManager
|
||||
import com.nextcloud.talk.chat.data.io.MediaRecorderManager
|
||||
@ -33,6 +34,7 @@ import com.nextcloud.talk.models.json.conversations.RoomOverall
|
||||
import com.nextcloud.talk.models.json.conversations.RoomsOverall
|
||||
import com.nextcloud.talk.models.json.generic.GenericOverall
|
||||
import com.nextcloud.talk.models.json.reminder.Reminder
|
||||
import com.nextcloud.talk.models.json.userAbsence.UserAbsenceData
|
||||
import com.nextcloud.talk.repositories.reactions.ReactionsRepository
|
||||
import com.nextcloud.talk.ui.PlaybackSpeed
|
||||
import com.nextcloud.talk.utils.ConversationUtils
|
||||
@ -47,6 +49,7 @@ import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -109,6 +112,10 @@ class ChatViewModel @Inject constructor(
|
||||
val getVoiceRecordingLocked: LiveData<Boolean>
|
||||
get() = _getVoiceRecordingLocked
|
||||
|
||||
private val _outOfOfficeViewState = MutableLiveData<OutOfOfficeUIState>(OutOfOfficeUIState.None)
|
||||
val outOfOfficeViewState: LiveData<OutOfOfficeUIState>
|
||||
get() = _outOfOfficeViewState
|
||||
|
||||
private val _voiceMessagePlaybackSpeedPreferences: MutableLiveData<Map<String, PlaybackSpeed>> = MutableLiveData()
|
||||
val voiceMessagePlaybackSpeedPreferences: LiveData<Map<String, PlaybackSpeed>>
|
||||
get() = _voiceMessagePlaybackSpeedPreferences
|
||||
@ -764,8 +771,26 @@ class ChatViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun outOfOfficeStatusOfUser(credentials:String, baseUrl: String, userId: String) {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
val response = chatNetworkDataSource.getOutOfOfficeStatusForUser(credentials, baseUrl, userId)
|
||||
_outOfOfficeViewState.value = OutOfOfficeUIState.Success(response.ocs?.data!!)
|
||||
} catch (exception: Exception) {
|
||||
_outOfOfficeViewState.value = OutOfOfficeUIState.Error(exception)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = ChatViewModel::class.simpleName
|
||||
const val JOIN_ROOM_RETRY_COUNT: Long = 3
|
||||
}
|
||||
|
||||
|
||||
sealed class OutOfOfficeUIState {
|
||||
data object None : OutOfOfficeUIState()
|
||||
data class Success(val userAbsence: UserAbsenceData) : OutOfOfficeUIState()
|
||||
data class Error(val exception: Exception) : OutOfOfficeUIState()
|
||||
}
|
||||
}
|
||||
|
@ -147,8 +147,8 @@ class RepositoryModule {
|
||||
}
|
||||
|
||||
@Provides
|
||||
fun provideChatNetworkDataSource(ncApi: NcApi): ChatNetworkDataSource {
|
||||
return RetrofitChatNetwork(ncApi)
|
||||
fun provideChatNetworkDataSource(ncApi: NcApi, ncApiCoroutines: NcApiCoroutines): ChatNetworkDataSource {
|
||||
return RetrofitChatNetwork(ncApi,ncApiCoroutines)
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -601,4 +601,8 @@ object ApiUtils {
|
||||
fun getUrlForArchive(version: Int, baseUrl: String?, token: String?): String {
|
||||
return "${getUrlForRoom(version, baseUrl, token)}/archive"
|
||||
}
|
||||
|
||||
fun getUrlForOutOfOffice(baseUrl:String, userId:String):String{
|
||||
return "$baseUrl$OCS_API_VERSION/apps/dav/api/v1/outOfOffice/$userId/now"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user