forward message to note to self

Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
sowjanyakch 2025-04-23 16:02:10 +02:00
parent 22e6eb35f1
commit 9155c4ca69
No known key found for this signature in database
GPG Key ID: F7AA2A8B65B50220
3 changed files with 80 additions and 23 deletions

View File

@ -256,6 +256,8 @@ class ChatActivity :
lateinit var chatViewModel: ChatViewModel
lateinit var messageInputViewModel: MessageInputViewModel
private lateinit var noteToSelfRoomToken: String
private val startSelectContactForResult = registerForActivityResult(
ActivityResultContracts
.StartActivityForResult()
@ -640,6 +642,27 @@ class ChatActivity :
}
}
chatViewModel.noteToSelfViewState.observe(this) { state ->
when (state) {
is ChatViewModel.NoteToSelfErrorState -> {
Snackbar.make(binding.root, "Unable to send message to note to self", Snackbar.LENGTH_LONG).show()
}
ChatViewModel.NoteToSelfStartState -> {
}
is ChatViewModel.NoteToSelfSuccessState -> {
val roomOverall = state.roomOverall
noteToSelfRoomToken = roomOverall.ocs?.data?.token!!
}
is ChatViewModel.NoteToSelfNotAvailableState -> {
}
else -> {
}
}
}
chatViewModel.joinRoomViewState.observe(this) { state ->
when (state) {
is ChatViewModel.JoinRoomSuccessState -> {

View File

@ -275,6 +275,14 @@ class ChatViewModel @Inject constructor(
val reactionDeletedViewState: LiveData<ViewState>
get() = _reactionDeletedViewState
object NoteToSelfStartState : ViewState
class NoteToSelfErrorState(val message: String) : ViewState
class NoteToSelfSuccessState(val roomOverall: RoomOverall) : ViewState
private val _noteToSelfViewState: MutableLiveData<ViewState> = MutableLiveData(NoteToSelfStartState)
val noteToSelfViewState: LiveData<ViewState>
get() = _noteToSelfViewState
fun initData(credentials: String, urlForChatting: String, roomToken: String) {
chatRepository.initData(credentials, urlForChatting, roomToken)
}
@ -539,7 +547,24 @@ class ChatViewModel @Inject constructor(
fun checkForNoteToSelf(user: User) {
chatNetworkDataSource.checkForNoteToSelf(user).subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe(CheckForNoteToSelfObserver())
?. subscribe(object : Observer<RoomOverall> {
override fun onSubscribe(d: Disposable) {
disposableSet.add(d)
}
override fun onNext(roomOverall: RoomOverall) {
_noteToSelfViewState.value = NoteToSelfSuccessState(roomOverall)
}
override fun onError(e: Throwable) {
Log.e(TAG, "Error when sharing location to notes $e")
_noteToSelfViewState.value = NoteToSelfErrorState(e.localizedMessage ?: "")
}
override fun onComplete() {
// unused atm
}
})
}
fun shareLocationToNotes(credentials: String, url: String, objectType: String, objectId: String, metadata: String) {
@ -782,24 +807,6 @@ class ChatViewModel @Inject constructor(
}
}
inner class CheckForNoteToSelfObserver : Observer<RoomOverall> {
override fun onSubscribe(d: Disposable) {
disposableSet.add(d)
}
override fun onNext(roomOverall: RoomOverall) {
val room = roomOverall.ocs?.data
}
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 {

View File

@ -25,6 +25,7 @@ import com.nextcloud.talk.R
import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.chat.ChatActivity
import com.nextcloud.talk.chat.data.model.ChatMessage
import com.nextcloud.talk.chat.viewmodels.ChatViewModel
import com.nextcloud.talk.data.network.NetworkMonitor
import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.databinding.DialogMessageActionsBinding
@ -69,6 +70,9 @@ class MessageActionsDialog(
@Inject
lateinit var reactionsRepository: ReactionsRepository
@Inject
lateinit var chatViewModel: ChatViewModel
@Inject
lateinit var dateUtils: DateUtils
@ -96,6 +100,8 @@ class MessageActionsDialog(
.EDIT_MESSAGES_NOTE_TO_SELF
) && currentConversation?.type == ConversationEnums.ConversationType.NOTE_TO_SELF
private var noteToSelfRoomToken: String = ""
private val isMessageBotOneToOne = (message.actorType == ACTOR_BOTS) && (
message.isOneToOneConversation ||
message.isFormerOneToOneConversation
@ -118,6 +124,7 @@ class MessageActionsDialog(
viewThemeUtils.material.colorBottomSheetBackground(dialogMessageActionsBinding.root)
viewThemeUtils.material.colorBottomSheetDragHandle(dialogMessageActionsBinding.bottomSheetDragHandle)
initObservers()
initEmojiBar(hasChatPermission)
initMenuItemCopy(!message.isDeleted)
@ -126,7 +133,6 @@ class MessageActionsDialog(
!message.isDeleted &&
currentConversation?.type != ConversationEnums.ConversationType.NOTE_TO_SELF
)
initMenuItems(networkMonitor.isOnline.value)
}
@ -173,6 +179,27 @@ class MessageActionsDialog(
}
}
fun initObservers() {
chatViewModel.noteToSelfViewState.observe(this) { state ->
when (state) {
is ChatViewModel.NoteToSelfErrorState -> {
}
ChatViewModel.NoteToSelfStartState -> {
}
is ChatViewModel.NoteToSelfSuccessState -> {
val roomOverall = state.roomOverall
noteToSelfRoomToken = roomOverall.ocs?.data?.token!!
}
is ChatViewModel.NoteToSelfNotAvailableState -> {
}
else -> {
}
}
}
}
override fun onStart() {
super.onStart()
val bottomSheet = findViewById<View>(R.id.design_bottom_sheet)
@ -447,11 +474,11 @@ class MessageActionsDialog(
dialogMessageActionsBinding.menuSaveMessage.visibility = getVisibility(visible)
}
private fun initMenuAddToNote(visible: Boolean, roomToken: String = "") {
private fun initMenuAddToNote(visible: Boolean) {
if (visible) {
chatViewModel.checkForNoteToSelf(user!!)
dialogMessageActionsBinding.menuShareToNote.setOnClickListener {
chatActivity.chatViewModel.checkForNoteToSelf(user!!)
chatActivity.shareToNotes(message, roomToken)
chatActivity.shareToNotes(message, noteToSelfRoomToken)
dismiss()
}
}