mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-21 20:45:29 +03:00
use repository in MessageInputViewModel instead datasource
(as datasources should be only used in repositories) use coroutines instead RxJava for api calls triggered by MessageInputViewModel Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
c5c55e8c32
commit
d335f4f371
10 changed files with 171 additions and 149 deletions
|
@ -388,12 +388,6 @@ public interface NcApi {
|
||||||
@Field("referenceId") String referenceId
|
@Field("referenceId") String referenceId
|
||||||
);
|
);
|
||||||
|
|
||||||
@FormUrlEncoded
|
|
||||||
@PUT
|
|
||||||
Observable<ChatOverallSingleMessage> editChatMessage(@Header("Authorization") String authorization,
|
|
||||||
@Url String url,
|
|
||||||
@Field("message") String message);
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
Observable<Response<ChatShareOverall>> getSharedItems(
|
Observable<Response<ChatShareOverall>> getSharedItems(
|
||||||
@Header("Authorization") String authorization,
|
@Header("Authorization") String authorization,
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
package com.nextcloud.talk.api
|
package com.nextcloud.talk.api
|
||||||
|
|
||||||
import com.nextcloud.talk.models.json.autocomplete.AutocompleteOverall
|
import com.nextcloud.talk.models.json.autocomplete.AutocompleteOverall
|
||||||
|
import com.nextcloud.talk.models.json.chat.ChatOverallSingleMessage
|
||||||
import com.nextcloud.talk.models.json.conversations.RoomOverall
|
import com.nextcloud.talk.models.json.conversations.RoomOverall
|
||||||
import com.nextcloud.talk.models.json.generic.GenericOverall
|
import com.nextcloud.talk.models.json.generic.GenericOverall
|
||||||
import com.nextcloud.talk.models.json.participants.AddParticipantOverall
|
import com.nextcloud.talk.models.json.participants.AddParticipantOverall
|
||||||
|
@ -116,4 +117,24 @@ interface NcApiCoroutines {
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
suspend fun unarchiveConversation(@Header("Authorization") authorization: String, @Url url: String): GenericOverall
|
suspend fun unarchiveConversation(@Header("Authorization") authorization: String, @Url url: String): GenericOverall
|
||||||
|
|
||||||
|
@FormUrlEncoded
|
||||||
|
@POST
|
||||||
|
suspend fun sendChatMessage(
|
||||||
|
@Header("Authorization") authorization: String,
|
||||||
|
@Url url: String,
|
||||||
|
@Field("message") message: CharSequence,
|
||||||
|
@Field("actorDisplayName") actorDisplayName: String,
|
||||||
|
@Field("replyTo") replyTo: Int,
|
||||||
|
@Field("silent") sendWithoutNotification: Boolean,
|
||||||
|
@Field("referenceId") referenceId: String
|
||||||
|
): ChatOverallSingleMessage
|
||||||
|
|
||||||
|
@FormUrlEncoded
|
||||||
|
@PUT
|
||||||
|
suspend fun editChatMessage(
|
||||||
|
@Header("Authorization") authorization: String,
|
||||||
|
@Url url: String,
|
||||||
|
@Field("message") message: String
|
||||||
|
): ChatOverallSingleMessage
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,7 +194,6 @@ import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.greenrobot.eventbus.Subscribe
|
import org.greenrobot.eventbus.Subscribe
|
||||||
import org.greenrobot.eventbus.ThreadMode
|
import org.greenrobot.eventbus.ThreadMode
|
||||||
import retrofit2.HttpException
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.net.HttpURLConnection
|
import java.net.HttpURLConnection
|
||||||
|
@ -762,18 +761,18 @@ class ChatActivity :
|
||||||
}
|
}
|
||||||
|
|
||||||
is MessageInputViewModel.SendChatMessageErrorState -> {
|
is MessageInputViewModel.SendChatMessageErrorState -> {
|
||||||
if (state.e is HttpException) {
|
// if (state.e is HttpException) {
|
||||||
val code = state.e.code()
|
// val code = state.e.code()
|
||||||
if (code.toString().startsWith("2")) {
|
// if (code.toString().startsWith("2")) {
|
||||||
myFirstMessage = state.message
|
// myFirstMessage = state.message
|
||||||
|
//
|
||||||
if (binding.unreadMessagesPopup.isShown) {
|
// if (binding.unreadMessagesPopup.isShown) {
|
||||||
binding.unreadMessagesPopup.visibility = View.GONE
|
// binding.unreadMessagesPopup.visibility = View.GONE
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
binding.messagesListView.smoothScrollToPosition(0)
|
// binding.messagesListView.smoothScrollToPosition(0)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {}
|
else -> {}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import android.os.Bundle
|
||||||
import com.nextcloud.talk.chat.data.io.LifecycleAwareManager
|
import com.nextcloud.talk.chat.data.io.LifecycleAwareManager
|
||||||
import com.nextcloud.talk.chat.data.model.ChatMessage
|
import com.nextcloud.talk.chat.data.model.ChatMessage
|
||||||
import com.nextcloud.talk.models.domain.ConversationModel
|
import com.nextcloud.talk.models.domain.ConversationModel
|
||||||
|
import com.nextcloud.talk.models.json.chat.ChatOverallSingleMessage
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
@ -69,4 +70,16 @@ interface ChatMessageRepository : LifecycleAwareManager {
|
||||||
* Destroys unused resources.
|
* Destroys unused resources.
|
||||||
*/
|
*/
|
||||||
fun handleChatOnBackPress()
|
fun handleChatOnBackPress()
|
||||||
|
|
||||||
|
suspend fun sendChatMessage(
|
||||||
|
credentials: String,
|
||||||
|
url: String,
|
||||||
|
message: CharSequence,
|
||||||
|
displayName: String,
|
||||||
|
replyTo: Int,
|
||||||
|
sendWithoutNotification: Boolean,
|
||||||
|
referenceId: String
|
||||||
|
): Flow<Result<ChatOverallSingleMessage>>
|
||||||
|
|
||||||
|
suspend fun editChatMessage(credentials: String, url: String, text: String): Flow<Result<ChatOverallSingleMessage>>
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ interface ChatNetworkDataSource {
|
||||||
): Observable<GenericOverall>
|
): Observable<GenericOverall>
|
||||||
|
|
||||||
fun leaveRoom(credentials: String, url: String): Observable<GenericOverall>
|
fun leaveRoom(credentials: String, url: String): Observable<GenericOverall>
|
||||||
fun sendChatMessage(
|
suspend fun sendChatMessage(
|
||||||
credentials: String,
|
credentials: String,
|
||||||
url: String,
|
url: String,
|
||||||
message: CharSequence,
|
message: CharSequence,
|
||||||
|
@ -58,13 +58,15 @@ interface ChatNetworkDataSource {
|
||||||
replyTo: Int,
|
replyTo: Int,
|
||||||
sendWithoutNotification: Boolean,
|
sendWithoutNotification: Boolean,
|
||||||
referenceId: String
|
referenceId: String
|
||||||
): Observable<ChatOverallSingleMessage>
|
): ChatOverallSingleMessage
|
||||||
|
|
||||||
fun pullChatMessages(credentials: String, url: String, fieldMap: HashMap<String, Int>): Observable<Response<*>>
|
fun pullChatMessages(credentials: String, url: String, fieldMap: HashMap<String, Int>): Observable<Response<*>>
|
||||||
fun deleteChatMessage(credentials: String, url: String): Observable<ChatOverallSingleMessage>
|
fun deleteChatMessage(credentials: String, url: String): Observable<ChatOverallSingleMessage>
|
||||||
fun createRoom(credentials: String, url: String, map: Map<String, String>): Observable<RoomOverall>
|
fun createRoom(credentials: String, url: String, map: Map<String, String>): Observable<RoomOverall>
|
||||||
fun setChatReadMarker(credentials: String, url: String, previousMessageId: Int): Observable<GenericOverall>
|
fun setChatReadMarker(credentials: String, url: String, previousMessageId: Int): Observable<GenericOverall>
|
||||||
fun editChatMessage(credentials: String, url: String, text: String): Observable<ChatOverallSingleMessage>
|
|
||||||
|
suspend fun editChatMessage(credentials: String, url: String, text: String): ChatOverallSingleMessage
|
||||||
|
|
||||||
fun listBans(credentials: String, url: String): Observable<List<TalkBan>>
|
fun listBans(credentials: String, url: String): Observable<List<TalkBan>>
|
||||||
fun banActor(
|
fun banActor(
|
||||||
credentials: String,
|
credentials: String,
|
||||||
|
|
|
@ -23,6 +23,7 @@ import com.nextcloud.talk.data.user.model.User
|
||||||
import com.nextcloud.talk.models.domain.ConversationModel
|
import com.nextcloud.talk.models.domain.ConversationModel
|
||||||
import com.nextcloud.talk.models.json.chat.ChatMessageJson
|
import com.nextcloud.talk.models.json.chat.ChatMessageJson
|
||||||
import com.nextcloud.talk.models.json.chat.ChatOverall
|
import com.nextcloud.talk.models.json.chat.ChatOverall
|
||||||
|
import com.nextcloud.talk.models.json.chat.ChatOverallSingleMessage
|
||||||
import com.nextcloud.talk.utils.bundle.BundleKeys
|
import com.nextcloud.talk.utils.bundle.BundleKeys
|
||||||
import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew
|
import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew
|
||||||
import com.nextcloud.talk.utils.preferences.AppPreferences
|
import com.nextcloud.talk.utils.preferences.AppPreferences
|
||||||
|
@ -36,6 +37,7 @@ import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
|
import kotlinx.coroutines.flow.flow
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -731,6 +733,50 @@ class OfflineFirstChatRepository @Inject constructor(
|
||||||
scope.cancel()
|
scope.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun sendChatMessage(
|
||||||
|
credentials: String,
|
||||||
|
url: String,
|
||||||
|
message: CharSequence,
|
||||||
|
displayName: String,
|
||||||
|
replyTo: Int,
|
||||||
|
sendWithoutNotification: Boolean,
|
||||||
|
referenceId: String
|
||||||
|
): Flow<Result<ChatOverallSingleMessage>> =
|
||||||
|
flow {
|
||||||
|
try {
|
||||||
|
val response = network.sendChatMessage(
|
||||||
|
credentials,
|
||||||
|
url,
|
||||||
|
message,
|
||||||
|
displayName,
|
||||||
|
replyTo,
|
||||||
|
sendWithoutNotification,
|
||||||
|
referenceId
|
||||||
|
)
|
||||||
|
emit(Result.success(response))
|
||||||
|
} catch (e: Exception) {
|
||||||
|
emit(Result.failure(e))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun editChatMessage(
|
||||||
|
credentials: String,
|
||||||
|
url: String,
|
||||||
|
text: String
|
||||||
|
): Flow<Result<ChatOverallSingleMessage>> =
|
||||||
|
flow {
|
||||||
|
try {
|
||||||
|
val response = network.editChatMessage(
|
||||||
|
credentials,
|
||||||
|
url,
|
||||||
|
text
|
||||||
|
)
|
||||||
|
emit(Result.success(response))
|
||||||
|
} catch (e: Exception) {
|
||||||
|
emit(Result.failure(e))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val TAG = OfflineFirstChatRepository::class.simpleName
|
val TAG = OfflineFirstChatRepository::class.simpleName
|
||||||
private const val HTTP_CODE_OK: Int = 200
|
private const val HTTP_CODE_OK: Int = 200
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
package com.nextcloud.talk.chat.data.network
|
package com.nextcloud.talk.chat.data.network
|
||||||
|
|
||||||
import com.nextcloud.talk.api.NcApi
|
import com.nextcloud.talk.api.NcApi
|
||||||
|
import com.nextcloud.talk.api.NcApiCoroutines
|
||||||
import com.nextcloud.talk.data.user.model.User
|
import com.nextcloud.talk.data.user.model.User
|
||||||
import com.nextcloud.talk.models.domain.ConversationModel
|
import com.nextcloud.talk.models.domain.ConversationModel
|
||||||
import com.nextcloud.talk.models.json.capabilities.SpreedCapability
|
import com.nextcloud.talk.models.json.capabilities.SpreedCapability
|
||||||
|
@ -21,7 +22,8 @@ import com.nextcloud.talk.utils.message.SendMessageUtils
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import retrofit2.Response
|
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> {
|
override fun getRoom(user: User, roomToken: String): Observable<ConversationModel> {
|
||||||
val credentials: String = ApiUtils.getCredentials(user.username, user.token)!!
|
val credentials: String = ApiUtils.getCredentials(user.username, user.token)!!
|
||||||
val apiVersion = ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V3, 1))
|
val apiVersion = ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V3, 1))
|
||||||
|
@ -137,7 +139,7 @@ class RetrofitChatNetwork(private val ncApi: NcApi) : ChatNetworkDataSource {
|
||||||
it
|
it
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun sendChatMessage(
|
override suspend fun sendChatMessage(
|
||||||
credentials: String,
|
credentials: String,
|
||||||
url: String,
|
url: String,
|
||||||
message: CharSequence,
|
message: CharSequence,
|
||||||
|
@ -145,8 +147,8 @@ class RetrofitChatNetwork(private val ncApi: NcApi) : ChatNetworkDataSource {
|
||||||
replyTo: Int,
|
replyTo: Int,
|
||||||
sendWithoutNotification: Boolean,
|
sendWithoutNotification: Boolean,
|
||||||
referenceId: String
|
referenceId: String
|
||||||
): Observable<ChatOverallSingleMessage> =
|
): ChatOverallSingleMessage =
|
||||||
ncApi.sendChatMessage(
|
ncApiCoroutines.sendChatMessage(
|
||||||
credentials,
|
credentials,
|
||||||
url,
|
url,
|
||||||
message,
|
message,
|
||||||
|
@ -154,9 +156,7 @@ class RetrofitChatNetwork(private val ncApi: NcApi) : ChatNetworkDataSource {
|
||||||
replyTo,
|
replyTo,
|
||||||
sendWithoutNotification,
|
sendWithoutNotification,
|
||||||
referenceId
|
referenceId
|
||||||
).map {
|
)
|
||||||
it
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun pullChatMessages(
|
override fun pullChatMessages(
|
||||||
credentials: String,
|
credentials: String,
|
||||||
|
@ -180,10 +180,8 @@ class RetrofitChatNetwork(private val ncApi: NcApi) : ChatNetworkDataSource {
|
||||||
previousMessageId: Int
|
previousMessageId: Int
|
||||||
): Observable<GenericOverall> = ncApi.setChatReadMarker(credentials, url, previousMessageId).map { it }
|
): Observable<GenericOverall> = ncApi.setChatReadMarker(credentials, url, previousMessageId).map { it }
|
||||||
|
|
||||||
override fun editChatMessage(credentials: String, url: String, text: String): Observable<ChatOverallSingleMessage> =
|
override suspend fun editChatMessage(credentials: String, url: String, text: String): ChatOverallSingleMessage =
|
||||||
ncApi.editChatMessage(credentials, url, text).map {
|
ncApiCoroutines.editChatMessage(credentials, url, text)
|
||||||
it
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun listBans(credentials: String, url: String): Observable<List<TalkBan>> =
|
override fun listBans(credentials: String, url: String): Observable<List<TalkBan>> =
|
||||||
ncApi.listBans(credentials, url).map {
|
ncApi.listBans(credentials, url).map {
|
||||||
|
|
|
@ -15,25 +15,24 @@ import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.asLiveData
|
import androidx.lifecycle.asLiveData
|
||||||
|
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.AudioFocusRequestManager
|
||||||
import com.nextcloud.talk.chat.data.io.AudioRecorderManager
|
import com.nextcloud.talk.chat.data.io.AudioRecorderManager
|
||||||
import com.nextcloud.talk.chat.data.io.MediaPlayerManager
|
import com.nextcloud.talk.chat.data.io.MediaPlayerManager
|
||||||
import com.nextcloud.talk.chat.data.network.ChatNetworkDataSource
|
|
||||||
import com.nextcloud.talk.models.json.chat.ChatOverallSingleMessage
|
import com.nextcloud.talk.models.json.chat.ChatOverallSingleMessage
|
||||||
import com.nextcloud.talk.utils.message.SendMessageUtils
|
import com.nextcloud.talk.utils.message.SendMessageUtils
|
||||||
import com.nextcloud.talk.utils.preferences.AppPreferences
|
import com.nextcloud.talk.utils.preferences.AppPreferences
|
||||||
import com.stfalcon.chatkit.commons.models.IMessage
|
import com.stfalcon.chatkit.commons.models.IMessage
|
||||||
import io.reactivex.Observer
|
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
|
||||||
import io.reactivex.disposables.Disposable
|
import io.reactivex.disposables.Disposable
|
||||||
import io.reactivex.schedulers.Schedulers
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import java.lang.Thread.sleep
|
import java.lang.Thread.sleep
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class MessageInputViewModel @Inject constructor(
|
class MessageInputViewModel @Inject constructor(
|
||||||
private val chatNetworkDataSource: ChatNetworkDataSource,
|
private val chatRepository: ChatMessageRepository,
|
||||||
private val audioRecorderManager: AudioRecorderManager,
|
private val audioRecorderManager: AudioRecorderManager,
|
||||||
private val mediaPlayerManager: MediaPlayerManager,
|
private val mediaPlayerManager: MediaPlayerManager,
|
||||||
private val audioFocusRequestManager: AudioFocusRequestManager,
|
private val audioFocusRequestManager: AudioFocusRequestManager,
|
||||||
|
@ -106,7 +105,7 @@ class MessageInputViewModel @Inject constructor(
|
||||||
sealed interface ViewState
|
sealed interface ViewState
|
||||||
object SendChatMessageStartState : ViewState
|
object SendChatMessageStartState : ViewState
|
||||||
class SendChatMessageSuccessState(val message: CharSequence) : ViewState
|
class SendChatMessageSuccessState(val message: CharSequence) : ViewState
|
||||||
class SendChatMessageErrorState(val e: Throwable, val message: CharSequence) : ViewState
|
class SendChatMessageErrorState(val message: CharSequence) : ViewState
|
||||||
private val _sendChatMessageViewState: MutableLiveData<ViewState> = MutableLiveData(SendChatMessageStartState)
|
private val _sendChatMessageViewState: MutableLiveData<ViewState> = MutableLiveData(SendChatMessageStartState)
|
||||||
val sendChatMessageViewState: LiveData<ViewState>
|
val sendChatMessageViewState: LiveData<ViewState>
|
||||||
get() = _sendChatMessageViewState
|
get() = _sendChatMessageViewState
|
||||||
|
@ -156,7 +155,8 @@ class MessageInputViewModel @Inject constructor(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
chatNetworkDataSource.sendChatMessage(
|
viewModelScope.launch {
|
||||||
|
chatRepository.sendChatMessage(
|
||||||
credentials,
|
credentials,
|
||||||
url,
|
url,
|
||||||
message,
|
message,
|
||||||
|
@ -164,51 +164,32 @@ class MessageInputViewModel @Inject constructor(
|
||||||
replyTo,
|
replyTo,
|
||||||
sendWithoutNotification,
|
sendWithoutNotification,
|
||||||
referenceId
|
referenceId
|
||||||
).subscribeOn(Schedulers.io())
|
).collect { result ->
|
||||||
?.observeOn(AndroidSchedulers.mainThread())
|
if (result.isSuccess) {
|
||||||
?.subscribe(object : Observer<ChatOverallSingleMessage> {
|
Log.d(TAG, "received ref id: " + (result.getOrNull()?.ocs?.data?.referenceId ?: "none"))
|
||||||
override fun onSubscribe(d: Disposable) {
|
|
||||||
disposableSet.add(d)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onError(e: Throwable) {
|
|
||||||
_sendChatMessageViewState.value = SendChatMessageErrorState(e, message)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onComplete() {
|
|
||||||
// unused atm
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onNext(t: ChatOverallSingleMessage) {
|
|
||||||
Log.d(TAG, "received ref id: " + (t.ocs?.data?.referenceId ?: "none"))
|
|
||||||
// TODO check ref id and replace temp message
|
|
||||||
_sendChatMessageViewState.value = SendChatMessageSuccessState(message)
|
_sendChatMessageViewState.value = SendChatMessageSuccessState(message)
|
||||||
|
} else {
|
||||||
|
_sendChatMessageViewState.value = SendChatMessageErrorState(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun editChatMessage(credentials: String, url: String, text: String) {
|
fun editChatMessage(credentials: String, url: String, text: String) {
|
||||||
chatNetworkDataSource.editChatMessage(credentials, url, text)
|
viewModelScope.launch {
|
||||||
.subscribeOn(Schedulers.io())
|
chatRepository.editChatMessage(
|
||||||
?.observeOn(AndroidSchedulers.mainThread())
|
credentials,
|
||||||
?.subscribe(object : Observer<ChatOverallSingleMessage> {
|
url,
|
||||||
override fun onSubscribe(d: Disposable) {
|
text
|
||||||
disposableSet.add(d)
|
).collect { result ->
|
||||||
}
|
if (result.isSuccess) {
|
||||||
|
_editMessageViewState.value = EditMessageSuccessState(result.getOrNull()!!)
|
||||||
override fun onError(e: Throwable) {
|
} else {
|
||||||
Log.e(TAG, "failed to edit message", e)
|
|
||||||
_editMessageViewState.value = EditMessageErrorState
|
_editMessageViewState.value = EditMessageErrorState
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onComplete() {
|
|
||||||
// unused atm
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onNext(messageEdited: ChatOverallSingleMessage) {
|
|
||||||
_editMessageViewState.value = EditMessageSuccessState(messageEdited)
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun reply(message: IMessage?) {
|
fun reply(message: IMessage?) {
|
||||||
|
|
|
@ -10,7 +10,6 @@ package com.nextcloud.talk.conversationlist.data.network
|
||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.nextcloud.talk.chat.data.network.ChatNetworkDataSource
|
import com.nextcloud.talk.chat.data.network.ChatNetworkDataSource
|
||||||
import com.nextcloud.talk.chat.data.network.OfflineFirstChatRepository
|
|
||||||
import com.nextcloud.talk.conversationlist.data.OfflineConversationsRepository
|
import com.nextcloud.talk.conversationlist.data.OfflineConversationsRepository
|
||||||
import com.nextcloud.talk.data.database.dao.ConversationsDao
|
import com.nextcloud.talk.data.database.dao.ConversationsDao
|
||||||
import com.nextcloud.talk.data.database.mappers.asEntity
|
import com.nextcloud.talk.data.database.mappers.asEntity
|
||||||
|
@ -106,7 +105,7 @@ class OfflineFirstConversationsRepository @Inject constructor(
|
||||||
var conversationsFromSync: List<ConversationEntity>? = null
|
var conversationsFromSync: List<ConversationEntity>? = null
|
||||||
|
|
||||||
if (!monitor.isOnline.first()) {
|
if (!monitor.isOnline.first()) {
|
||||||
Log.d(OfflineFirstChatRepository.TAG, "Device is offline, can't load conversations from server")
|
Log.d(TAG, "Device is offline, can't load conversations from server")
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,105 +74,79 @@ class RepositoryModule {
|
||||||
ncApi: NcApi,
|
ncApi: NcApi,
|
||||||
ncApiCoroutines: NcApiCoroutines,
|
ncApiCoroutines: NcApiCoroutines,
|
||||||
userProvider: CurrentUserProviderNew
|
userProvider: CurrentUserProviderNew
|
||||||
): ConversationsRepository {
|
): ConversationsRepository = ConversationsRepositoryImpl(ncApi, ncApiCoroutines, userProvider)
|
||||||
return ConversationsRepositoryImpl(ncApi, ncApiCoroutines, userProvider)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideSharedItemsRepository(ncApi: NcApi, dateUtils: DateUtils): SharedItemsRepository {
|
fun provideSharedItemsRepository(ncApi: NcApi, dateUtils: DateUtils): SharedItemsRepository =
|
||||||
return SharedItemsRepositoryImpl(ncApi, dateUtils)
|
SharedItemsRepositoryImpl(ncApi, dateUtils)
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideUnifiedSearchRepository(ncApi: NcApi, userProvider: CurrentUserProviderNew): UnifiedSearchRepository {
|
fun provideUnifiedSearchRepository(ncApi: NcApi, userProvider: CurrentUserProviderNew): UnifiedSearchRepository =
|
||||||
return UnifiedSearchRepositoryImpl(ncApi, userProvider)
|
UnifiedSearchRepositoryImpl(ncApi, userProvider)
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideDialogPollRepository(ncApi: NcApi, userProvider: CurrentUserProviderNew): PollRepository {
|
fun provideDialogPollRepository(ncApi: NcApi, userProvider: CurrentUserProviderNew): PollRepository =
|
||||||
return PollRepositoryImpl(ncApi, userProvider)
|
PollRepositoryImpl(ncApi, userProvider)
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideRemoteFileBrowserItemsRepository(
|
fun provideRemoteFileBrowserItemsRepository(
|
||||||
okHttpClient: OkHttpClient,
|
okHttpClient: OkHttpClient,
|
||||||
userProvider: CurrentUserProviderNew
|
userProvider: CurrentUserProviderNew
|
||||||
): RemoteFileBrowserItemsRepository {
|
): RemoteFileBrowserItemsRepository = RemoteFileBrowserItemsRepositoryImpl(okHttpClient, userProvider)
|
||||||
return RemoteFileBrowserItemsRepositoryImpl(okHttpClient, userProvider)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideUsersRepository(database: TalkDatabase): UsersRepository {
|
fun provideUsersRepository(database: TalkDatabase): UsersRepository = UsersRepositoryImpl(database.usersDao())
|
||||||
return UsersRepositoryImpl(database.usersDao())
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideArbitraryStoragesRepository(database: TalkDatabase): ArbitraryStoragesRepository {
|
fun provideArbitraryStoragesRepository(database: TalkDatabase): ArbitraryStoragesRepository =
|
||||||
return ArbitraryStoragesRepositoryImpl(database.arbitraryStoragesDao())
|
ArbitraryStoragesRepositoryImpl(database.arbitraryStoragesDao())
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideReactionsRepository(
|
fun provideReactionsRepository(
|
||||||
ncApi: NcApi,
|
ncApi: NcApi,
|
||||||
userProvider: CurrentUserProviderNew,
|
userProvider: CurrentUserProviderNew,
|
||||||
dao: ChatMessagesDao
|
dao: ChatMessagesDao
|
||||||
): ReactionsRepository {
|
): ReactionsRepository = ReactionsRepositoryImpl(ncApi, userProvider, dao)
|
||||||
return ReactionsRepositoryImpl(ncApi, userProvider, dao)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideCallRecordingRepository(ncApi: NcApi, userProvider: CurrentUserProviderNew): CallRecordingRepository {
|
fun provideCallRecordingRepository(ncApi: NcApi, userProvider: CurrentUserProviderNew): CallRecordingRepository =
|
||||||
return CallRecordingRepositoryImpl(ncApi, userProvider)
|
CallRecordingRepositoryImpl(ncApi, userProvider)
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideRequestAssistanceRepository(
|
fun provideRequestAssistanceRepository(
|
||||||
ncApi: NcApi,
|
ncApi: NcApi,
|
||||||
userProvider: CurrentUserProviderNew
|
userProvider: CurrentUserProviderNew
|
||||||
): RequestAssistanceRepository {
|
): RequestAssistanceRepository = RequestAssistanceRepositoryImpl(ncApi, userProvider)
|
||||||
return RequestAssistanceRepositoryImpl(ncApi, userProvider)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideOpenConversationsRepository(
|
fun provideOpenConversationsRepository(
|
||||||
ncApi: NcApi,
|
ncApi: NcApi,
|
||||||
userProvider: CurrentUserProviderNew
|
userProvider: CurrentUserProviderNew
|
||||||
): OpenConversationsRepository {
|
): OpenConversationsRepository = OpenConversationsRepositoryImpl(ncApi, userProvider)
|
||||||
return OpenConversationsRepositoryImpl(ncApi, userProvider)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun translateRepository(ncApi: NcApi): TranslateRepository {
|
fun translateRepository(ncApi: NcApi): TranslateRepository = TranslateRepositoryImpl(ncApi)
|
||||||
return TranslateRepositoryImpl(ncApi)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideChatNetworkDataSource(ncApi: NcApi): ChatNetworkDataSource {
|
fun provideChatNetworkDataSource(ncApi: NcApi, ncApiCoroutines: NcApiCoroutines): ChatNetworkDataSource =
|
||||||
return RetrofitChatNetwork(ncApi)
|
RetrofitChatNetwork(ncApi, ncApiCoroutines)
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideConversationsNetworkDataSource(ncApi: NcApi): ConversationsNetworkDataSource {
|
fun provideConversationsNetworkDataSource(ncApi: NcApi): ConversationsNetworkDataSource =
|
||||||
return RetrofitConversationsNetwork(ncApi)
|
RetrofitConversationsNetwork(ncApi)
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideConversationInfoEditRepository(
|
fun provideConversationInfoEditRepository(
|
||||||
ncApi: NcApi,
|
ncApi: NcApi,
|
||||||
userProvider: CurrentUserProviderNew
|
userProvider: CurrentUserProviderNew
|
||||||
): ConversationInfoEditRepository {
|
): ConversationInfoEditRepository = ConversationInfoEditRepositoryImpl(ncApi, userProvider)
|
||||||
return ConversationInfoEditRepositoryImpl(ncApi, userProvider)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideConversationRepository(ncApi: NcApi, userProvider: CurrentUserProviderNew): ConversationRepository {
|
fun provideConversationRepository(ncApi: NcApi, userProvider: CurrentUserProviderNew): ConversationRepository =
|
||||||
return ConversationRepositoryImpl(ncApi, userProvider)
|
ConversationRepositoryImpl(ncApi, userProvider)
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideInvitationsRepository(ncApi: NcApi): InvitationsRepository {
|
fun provideInvitationsRepository(ncApi: NcApi): InvitationsRepository = InvitationsRepositoryImpl(ncApi)
|
||||||
return InvitationsRepositoryImpl(ncApi)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideOfflineFirstChatRepository(
|
fun provideOfflineFirstChatRepository(
|
||||||
|
@ -182,8 +156,8 @@ class RepositoryModule {
|
||||||
appPreferences: AppPreferences,
|
appPreferences: AppPreferences,
|
||||||
networkMonitor: NetworkMonitor,
|
networkMonitor: NetworkMonitor,
|
||||||
userProvider: CurrentUserProviderNew
|
userProvider: CurrentUserProviderNew
|
||||||
): ChatMessageRepository {
|
): ChatMessageRepository =
|
||||||
return OfflineFirstChatRepository(
|
OfflineFirstChatRepository(
|
||||||
chatMessagesDao,
|
chatMessagesDao,
|
||||||
chatBlocksDao,
|
chatBlocksDao,
|
||||||
dataSource,
|
dataSource,
|
||||||
|
@ -191,7 +165,6 @@ class RepositoryModule {
|
||||||
networkMonitor,
|
networkMonitor,
|
||||||
userProvider
|
userProvider
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideOfflineFirstConversationsRepository(
|
fun provideOfflineFirstConversationsRepository(
|
||||||
|
@ -200,26 +173,22 @@ class RepositoryModule {
|
||||||
chatNetworkDataSource: ChatNetworkDataSource,
|
chatNetworkDataSource: ChatNetworkDataSource,
|
||||||
networkMonitor: NetworkMonitor,
|
networkMonitor: NetworkMonitor,
|
||||||
currentUserProviderNew: CurrentUserProviderNew
|
currentUserProviderNew: CurrentUserProviderNew
|
||||||
): OfflineConversationsRepository {
|
): OfflineConversationsRepository =
|
||||||
return OfflineFirstConversationsRepository(
|
OfflineFirstConversationsRepository(
|
||||||
dao,
|
dao,
|
||||||
dataSource,
|
dataSource,
|
||||||
chatNetworkDataSource,
|
chatNetworkDataSource,
|
||||||
networkMonitor,
|
networkMonitor,
|
||||||
currentUserProviderNew
|
currentUserProviderNew
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideContactsRepository(ncApiCoroutines: NcApiCoroutines, userManager: UserManager): ContactsRepository {
|
fun provideContactsRepository(ncApiCoroutines: NcApiCoroutines, userManager: UserManager): ContactsRepository =
|
||||||
return ContactsRepositoryImpl(ncApiCoroutines, userManager)
|
ContactsRepositoryImpl(ncApiCoroutines, userManager)
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideConversationCreationRepository(
|
fun provideConversationCreationRepository(
|
||||||
ncApiCoroutines: NcApiCoroutines,
|
ncApiCoroutines: NcApiCoroutines,
|
||||||
userManager: UserManager
|
userManager: UserManager
|
||||||
): ConversationCreationRepository {
|
): ConversationCreationRepository = ConversationCreationRepositoryImpl(ncApiCoroutines, userManager)
|
||||||
return ConversationCreationRepositoryImpl(ncApiCoroutines, userManager)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue