mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-21 19:55:07 +01:00
create a note to self
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
bcd0216fca
commit
22e6eb35f1
@ -256,8 +256,6 @@ class ChatActivity :
|
||||
lateinit var chatViewModel: ChatViewModel
|
||||
lateinit var messageInputViewModel: MessageInputViewModel
|
||||
|
||||
private var noteToSelfRoomToken: String = ""
|
||||
|
||||
private val startSelectContactForResult = registerForActivityResult(
|
||||
ActivityResultContracts
|
||||
.StartActivityForResult()
|
||||
@ -436,24 +434,6 @@ class ChatActivity :
|
||||
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
|
||||
val apiVersion = ApiUtils.getConversationApiVersion(
|
||||
conversationUser!!,
|
||||
intArrayOf(
|
||||
ApiUtils.API_V4,
|
||||
ApiUtils
|
||||
.API_V3,
|
||||
1
|
||||
)
|
||||
)
|
||||
chatViewModel.checkForNoteToSelf(
|
||||
ApiUtils.getCredentials(conversationUser?.username, conversationUser?.token)!!,
|
||||
ApiUtils.getUrlForRooms(
|
||||
apiVersion,
|
||||
conversationUser?.baseUrl
|
||||
),
|
||||
false
|
||||
)
|
||||
|
||||
initObservers()
|
||||
|
||||
pickMultipleMedia = registerForActivityResult(
|
||||
@ -789,19 +769,6 @@ class ChatActivity :
|
||||
}
|
||||
}
|
||||
|
||||
chatViewModel.getNoteToSelfAvailability.observe(this) { state ->
|
||||
when (state) {
|
||||
is ChatViewModel.NoteToSelfAvailableState -> {
|
||||
this.lifecycleScope.launch {
|
||||
noteToSelfRoomToken = state.roomToken
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
noteToSelfRoomToken = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
chatViewModel.chatMessageViewState.observe(this) { state ->
|
||||
when (state) {
|
||||
is ChatViewModel.ChatMessageStartState -> {
|
||||
@ -3159,8 +3126,7 @@ class ChatActivity :
|
||||
currentConversation,
|
||||
isShowMessageDeletionButton(message),
|
||||
participantPermissions.hasChatPermission(),
|
||||
spreedCapabilities,
|
||||
noteToSelfRoomToken
|
||||
spreedCapabilities
|
||||
).show()
|
||||
}
|
||||
}
|
||||
|
@ -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,7 @@ interface ChatNetworkDataSource {
|
||||
displayName: String
|
||||
): Observable<ChatOverallSingleMessage>
|
||||
|
||||
fun checkForNoteToSelf(credentials: String, url: String, includeStatus: Boolean): Observable<RoomsOverall>
|
||||
fun checkForNoteToSelf(user: User): Observable<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,15 @@ class RetrofitChatNetwork(
|
||||
it
|
||||
}
|
||||
|
||||
override fun checkForNoteToSelf(
|
||||
credentials: String,
|
||||
url: String,
|
||||
includeStatus: Boolean
|
||||
): Observable<RoomsOverall> = ncApi.getRooms(credentials, url, includeStatus).map { it }
|
||||
override fun checkForNoteToSelf(user: User): Observable<RoomOverall> {
|
||||
val credentials: String = ApiUtils.getCredentials(user.username, user.token)!!
|
||||
val apiVersion = ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4))
|
||||
|
||||
return ncApi.getRoom(
|
||||
credentials,
|
||||
ApiUtils.getUrlForRoom(apiVersion, user.baseUrl!!, "note-to-self")
|
||||
)
|
||||
}
|
||||
|
||||
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
|
||||
@ -538,8 +536,8 @@ class ChatViewModel @Inject constructor(
|
||||
})
|
||||
}
|
||||
|
||||
fun checkForNoteToSelf(credentials: String, baseUrl: String, includeStatus: Boolean) {
|
||||
chatNetworkDataSource.checkForNoteToSelf(credentials, baseUrl, includeStatus).subscribeOn(Schedulers.io())
|
||||
fun checkForNoteToSelf(user: User) {
|
||||
chatNetworkDataSource.checkForNoteToSelf(user).subscribeOn(Schedulers.io())
|
||||
?.observeOn(AndroidSchedulers.mainThread())
|
||||
?.subscribe(CheckForNoteToSelfObserver())
|
||||
}
|
||||
@ -784,25 +782,13 @@ class ChatViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
inner class CheckForNoteToSelfObserver : Observer<RoomsOverall> {
|
||||
inner class CheckForNoteToSelfObserver : Observer<RoomOverall> {
|
||||
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 onNext(roomOverall: RoomOverall) {
|
||||
val room = roomOverall.ocs?.data
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
|
@ -60,8 +60,7 @@ class MessageActionsDialog(
|
||||
private val currentConversation: ConversationModel?,
|
||||
private val showMessageDeletionButton: Boolean,
|
||||
private val hasChatPermission: Boolean,
|
||||
private val spreedCapabilities: SpreedCapability,
|
||||
private val noteToSelfRoomToken: String
|
||||
private val spreedCapabilities: SpreedCapability
|
||||
) : BottomSheetDialog(chatActivity) {
|
||||
|
||||
@Inject
|
||||
@ -125,8 +124,7 @@ class MessageActionsDialog(
|
||||
initMenuAddToNote(
|
||||
networkMonitor.isOnline.value &&
|
||||
!message.isDeleted &&
|
||||
currentConversation?.type != ConversationEnums.ConversationType.NOTE_TO_SELF,
|
||||
noteToSelfRoomToken
|
||||
currentConversation?.type != ConversationEnums.ConversationType.NOTE_TO_SELF
|
||||
)
|
||||
|
||||
initMenuItems(networkMonitor.isOnline.value)
|
||||
@ -452,10 +450,12 @@ class MessageActionsDialog(
|
||||
private fun initMenuAddToNote(visible: Boolean, roomToken: String = "") {
|
||||
if (visible) {
|
||||
dialogMessageActionsBinding.menuShareToNote.setOnClickListener {
|
||||
chatActivity.chatViewModel.checkForNoteToSelf(user!!)
|
||||
chatActivity.shareToNotes(message, roomToken)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
dialogMessageActionsBinding.menuShareToNote.visibility = getVisibility(visible)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user