mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-09 13:59:48 +01:00
get Note-to-Self room by endpoint + convert to coroutines
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
c6d1f68442
commit
ab19f631ae
@ -251,4 +251,7 @@ interface NcApiCoroutines {
|
||||
@Url url: String,
|
||||
@Query("limit") limit: Int
|
||||
): ChatOverall
|
||||
|
||||
@GET
|
||||
suspend fun getNoteToSelfRoom(@Header("Authorization") authorization: String, @Url url: String): RoomOverall
|
||||
}
|
||||
|
@ -3300,23 +3300,21 @@ class ChatActivity :
|
||||
conversationUser!!,
|
||||
intArrayOf(ApiUtils.API_V4, ApiUtils.API_V3, 1)
|
||||
)
|
||||
chatViewModel.checkForNoteToSelf(
|
||||
|
||||
this.lifecycleScope.launch {
|
||||
val noteToSelfConversation = chatViewModel.checkForNoteToSelf(
|
||||
ApiUtils.getCredentials(conversationUser!!.username, conversationUser!!.token)!!,
|
||||
ApiUtils.getUrlForRooms(
|
||||
ApiUtils.getUrlForNoteToSelf(
|
||||
apiVersion,
|
||||
conversationUser!!.baseUrl
|
||||
),
|
||||
false
|
||||
)
|
||||
)
|
||||
|
||||
chatViewModel.getNoteToSelfAvailability.observe(this) { state ->
|
||||
when (state) {
|
||||
is ChatViewModel.NoteToSelfAvailableState -> {
|
||||
this.lifecycleScope.launch {
|
||||
if (noteToSelfConversation != null) {
|
||||
var shareUri: Uri? = null
|
||||
val data: HashMap<String?, String?>?
|
||||
var metaData: String = ""
|
||||
var objectId: String = ""
|
||||
var metaData = ""
|
||||
var objectId = ""
|
||||
if (message.hasFileAttachment()) {
|
||||
val filename = message.selectedIndividualHashMap!!["name"]
|
||||
path = applicationContext.cacheDir.absolutePath + "/" + filename
|
||||
@ -3342,15 +3340,12 @@ class ChatActivity :
|
||||
"\"longitude\":\"$lon\",\"name\":\"$name\"}"
|
||||
}
|
||||
|
||||
shareToNotes(shareUri, state.roomToken, message, objectId, metaData)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
shareToNotes(shareUri, noteToSelfConversation.token, message, objectId, metaData)
|
||||
} else {
|
||||
Snackbar.make(binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun shareToNotes(
|
||||
shareUri: Uri?,
|
||||
|
@ -12,7 +12,6 @@ import com.nextcloud.talk.models.json.capabilities.SpreedCapability
|
||||
import com.nextcloud.talk.models.json.chat.ChatMessageJson
|
||||
import com.nextcloud.talk.models.json.chat.ChatOverallSingleMessage
|
||||
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.opengraph.Reference
|
||||
import com.nextcloud.talk.models.json.reminder.Reminder
|
||||
@ -42,7 +41,8 @@ interface ChatNetworkDataSource {
|
||||
displayName: String
|
||||
): Observable<ChatOverallSingleMessage>
|
||||
|
||||
fun checkForNoteToSelf(credentials: String, url: String, includeStatus: Boolean): Observable<RoomsOverall>
|
||||
suspend fun checkForNoteToSelf(credentials: String, url: String): RoomOverall
|
||||
|
||||
fun shareLocationToNotes(
|
||||
credentials: String,
|
||||
url: String,
|
||||
|
@ -14,7 +14,6 @@ import com.nextcloud.talk.models.json.capabilities.SpreedCapability
|
||||
import com.nextcloud.talk.models.json.chat.ChatMessageJson
|
||||
import com.nextcloud.talk.models.json.chat.ChatOverallSingleMessage
|
||||
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.opengraph.Reference
|
||||
import com.nextcloud.talk.models.json.reminder.Reminder
|
||||
@ -124,11 +123,8 @@ class RetrofitChatNetwork(
|
||||
it
|
||||
}
|
||||
|
||||
override fun checkForNoteToSelf(
|
||||
credentials: String,
|
||||
url: String,
|
||||
includeStatus: Boolean
|
||||
): Observable<RoomsOverall> = ncApi.getRooms(credentials, url, includeStatus).map { it }
|
||||
override suspend fun checkForNoteToSelf(credentials: String, url: String): RoomOverall =
|
||||
ncApiCoroutines.getNoteToSelfRoom(credentials, url)
|
||||
|
||||
override fun shareLocationToNotes(
|
||||
credentials: String,
|
||||
|
@ -34,14 +34,12 @@ import com.nextcloud.talk.models.json.capabilities.SpreedCapability
|
||||
import com.nextcloud.talk.models.json.chat.ChatMessageJson
|
||||
import com.nextcloud.talk.models.json.chat.ChatOverallSingleMessage
|
||||
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.opengraph.Reference
|
||||
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
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys
|
||||
import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew
|
||||
import com.nextcloud.talk.utils.preferences.AppPreferences
|
||||
@ -199,13 +197,6 @@ class ChatViewModel @Inject constructor(
|
||||
val getReminderExistState: LiveData<ViewState>
|
||||
get() = _getReminderExistState
|
||||
|
||||
object NoteToSelfNotAvailableState : ViewState
|
||||
open class NoteToSelfAvailableState(val roomToken: String) : ViewState
|
||||
|
||||
private val _getNoteToSelfAvailability: MutableLiveData<ViewState> = MutableLiveData(NoteToSelfNotAvailableState)
|
||||
val getNoteToSelfAvailability: LiveData<ViewState>
|
||||
get() = _getNoteToSelfAvailability
|
||||
|
||||
object GetRoomStartState : ViewState
|
||||
object GetRoomErrorState : ViewState
|
||||
object GetRoomSuccessState : ViewState
|
||||
@ -538,10 +529,17 @@ class ChatViewModel @Inject constructor(
|
||||
})
|
||||
}
|
||||
|
||||
fun checkForNoteToSelf(credentials: String, baseUrl: String, includeStatus: Boolean) {
|
||||
chatNetworkDataSource.checkForNoteToSelf(credentials, baseUrl, includeStatus).subscribeOn(Schedulers.io())
|
||||
?.observeOn(AndroidSchedulers.mainThread())
|
||||
?.subscribe(CheckForNoteToSelfObserver())
|
||||
suspend fun checkForNoteToSelf(credentials: String, baseUrl: String): ConversationModel? {
|
||||
val response = chatNetworkDataSource.checkForNoteToSelf(credentials, baseUrl)
|
||||
if (response.ocs?.meta?.statusCode == HTTP_CODE_OK) {
|
||||
val noteToSelfConversation = ConversationModel.mapToConversationModel(
|
||||
response.ocs?.data!!,
|
||||
userProvider.currentUser.blockingGet()
|
||||
)
|
||||
return noteToSelfConversation
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
fun shareLocationToNotes(credentials: String, url: String, objectType: String, objectId: String, metadata: String) {
|
||||
@ -784,36 +782,6 @@ class ChatViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
inner class CheckForNoteToSelfObserver : Observer<RoomsOverall> {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
disposableSet.add(d)
|
||||
}
|
||||
|
||||
override fun onNext(roomsOverall: RoomsOverall) {
|
||||
val rooms = roomsOverall.ocs?.data
|
||||
rooms?.let {
|
||||
try {
|
||||
val noteToSelf = rooms.first {
|
||||
val model = ConversationModel.mapToConversationModel(it, userProvider.currentUser.blockingGet())
|
||||
ConversationUtils.isNoteToSelfConversation(model)
|
||||
}
|
||||
_getNoteToSelfAvailability.value = NoteToSelfAvailableState(noteToSelf.token)
|
||||
} catch (e: NoSuchElementException) {
|
||||
_getNoteToSelfAvailability.value = NoteToSelfNotAvailableState
|
||||
Log.e(TAG, "Note to self not found $e")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
Log.d(TAG, "Error when getting rooms for Note to Self Observer $e")
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
// unused atm
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("Detekt.TooGenericExceptionCaught")
|
||||
fun outOfOfficeStatusOfUser(credentials: String, baseUrl: String, userId: String) {
|
||||
viewModelScope.launch {
|
||||
@ -875,6 +843,7 @@ class ChatViewModel @Inject constructor(
|
||||
companion object {
|
||||
private val TAG = ChatViewModel::class.simpleName
|
||||
const val JOIN_ROOM_RETRY_COUNT: Long = 3
|
||||
const val HTTP_CODE_OK: Int = 200
|
||||
}
|
||||
|
||||
sealed class OutOfOfficeUIState {
|
||||
|
@ -181,6 +181,10 @@ object ApiUtils {
|
||||
return getUrlForApi(version, baseUrl) + "/room"
|
||||
}
|
||||
|
||||
fun getUrlForNoteToSelf(version: Int, baseUrl: String?): String {
|
||||
return getUrlForApi(version, baseUrl) + "/room/note-to-self"
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getUrlForRoom(version: Int, baseUrl: String?, token: String?): String {
|
||||
return getUrlForRooms(version, baseUrl) + "/" + token
|
||||
|
Loading…
Reference in New Issue
Block a user