mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-29 00:19:44 +01:00
forward message to note to self
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
22e6eb35f1
commit
9155c4ca69
@ -256,6 +256,8 @@ class ChatActivity :
|
|||||||
lateinit var chatViewModel: ChatViewModel
|
lateinit var chatViewModel: ChatViewModel
|
||||||
lateinit var messageInputViewModel: MessageInputViewModel
|
lateinit var messageInputViewModel: MessageInputViewModel
|
||||||
|
|
||||||
|
private lateinit var noteToSelfRoomToken: String
|
||||||
|
|
||||||
private val startSelectContactForResult = registerForActivityResult(
|
private val startSelectContactForResult = registerForActivityResult(
|
||||||
ActivityResultContracts
|
ActivityResultContracts
|
||||||
.StartActivityForResult()
|
.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 ->
|
chatViewModel.joinRoomViewState.observe(this) { state ->
|
||||||
when (state) {
|
when (state) {
|
||||||
is ChatViewModel.JoinRoomSuccessState -> {
|
is ChatViewModel.JoinRoomSuccessState -> {
|
||||||
|
@ -275,6 +275,14 @@ class ChatViewModel @Inject constructor(
|
|||||||
val reactionDeletedViewState: LiveData<ViewState>
|
val reactionDeletedViewState: LiveData<ViewState>
|
||||||
get() = _reactionDeletedViewState
|
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) {
|
fun initData(credentials: String, urlForChatting: String, roomToken: String) {
|
||||||
chatRepository.initData(credentials, urlForChatting, roomToken)
|
chatRepository.initData(credentials, urlForChatting, roomToken)
|
||||||
}
|
}
|
||||||
@ -539,7 +547,24 @@ class ChatViewModel @Inject constructor(
|
|||||||
fun checkForNoteToSelf(user: User) {
|
fun checkForNoteToSelf(user: User) {
|
||||||
chatNetworkDataSource.checkForNoteToSelf(user).subscribeOn(Schedulers.io())
|
chatNetworkDataSource.checkForNoteToSelf(user).subscribeOn(Schedulers.io())
|
||||||
?.observeOn(AndroidSchedulers.mainThread())
|
?.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) {
|
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")
|
@Suppress("Detekt.TooGenericExceptionCaught")
|
||||||
fun outOfOfficeStatusOfUser(credentials: String, baseUrl: String, userId: String) {
|
fun outOfOfficeStatusOfUser(credentials: String, baseUrl: String, userId: String) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
@ -25,6 +25,7 @@ import com.nextcloud.talk.R
|
|||||||
import com.nextcloud.talk.application.NextcloudTalkApplication
|
import com.nextcloud.talk.application.NextcloudTalkApplication
|
||||||
import com.nextcloud.talk.chat.ChatActivity
|
import com.nextcloud.talk.chat.ChatActivity
|
||||||
import com.nextcloud.talk.chat.data.model.ChatMessage
|
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.network.NetworkMonitor
|
||||||
import com.nextcloud.talk.data.user.model.User
|
import com.nextcloud.talk.data.user.model.User
|
||||||
import com.nextcloud.talk.databinding.DialogMessageActionsBinding
|
import com.nextcloud.talk.databinding.DialogMessageActionsBinding
|
||||||
@ -69,6 +70,9 @@ class MessageActionsDialog(
|
|||||||
@Inject
|
@Inject
|
||||||
lateinit var reactionsRepository: ReactionsRepository
|
lateinit var reactionsRepository: ReactionsRepository
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var chatViewModel: ChatViewModel
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var dateUtils: DateUtils
|
lateinit var dateUtils: DateUtils
|
||||||
|
|
||||||
@ -96,6 +100,8 @@ class MessageActionsDialog(
|
|||||||
.EDIT_MESSAGES_NOTE_TO_SELF
|
.EDIT_MESSAGES_NOTE_TO_SELF
|
||||||
) && currentConversation?.type == ConversationEnums.ConversationType.NOTE_TO_SELF
|
) && currentConversation?.type == ConversationEnums.ConversationType.NOTE_TO_SELF
|
||||||
|
|
||||||
|
private var noteToSelfRoomToken: String = ""
|
||||||
|
|
||||||
private val isMessageBotOneToOne = (message.actorType == ACTOR_BOTS) && (
|
private val isMessageBotOneToOne = (message.actorType == ACTOR_BOTS) && (
|
||||||
message.isOneToOneConversation ||
|
message.isOneToOneConversation ||
|
||||||
message.isFormerOneToOneConversation
|
message.isFormerOneToOneConversation
|
||||||
@ -118,6 +124,7 @@ class MessageActionsDialog(
|
|||||||
|
|
||||||
viewThemeUtils.material.colorBottomSheetBackground(dialogMessageActionsBinding.root)
|
viewThemeUtils.material.colorBottomSheetBackground(dialogMessageActionsBinding.root)
|
||||||
viewThemeUtils.material.colorBottomSheetDragHandle(dialogMessageActionsBinding.bottomSheetDragHandle)
|
viewThemeUtils.material.colorBottomSheetDragHandle(dialogMessageActionsBinding.bottomSheetDragHandle)
|
||||||
|
initObservers()
|
||||||
initEmojiBar(hasChatPermission)
|
initEmojiBar(hasChatPermission)
|
||||||
initMenuItemCopy(!message.isDeleted)
|
initMenuItemCopy(!message.isDeleted)
|
||||||
|
|
||||||
@ -126,7 +133,6 @@ class MessageActionsDialog(
|
|||||||
!message.isDeleted &&
|
!message.isDeleted &&
|
||||||
currentConversation?.type != ConversationEnums.ConversationType.NOTE_TO_SELF
|
currentConversation?.type != ConversationEnums.ConversationType.NOTE_TO_SELF
|
||||||
)
|
)
|
||||||
|
|
||||||
initMenuItems(networkMonitor.isOnline.value)
|
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() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
val bottomSheet = findViewById<View>(R.id.design_bottom_sheet)
|
val bottomSheet = findViewById<View>(R.id.design_bottom_sheet)
|
||||||
@ -447,11 +474,11 @@ class MessageActionsDialog(
|
|||||||
dialogMessageActionsBinding.menuSaveMessage.visibility = getVisibility(visible)
|
dialogMessageActionsBinding.menuSaveMessage.visibility = getVisibility(visible)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initMenuAddToNote(visible: Boolean, roomToken: String = "") {
|
private fun initMenuAddToNote(visible: Boolean) {
|
||||||
if (visible) {
|
if (visible) {
|
||||||
|
chatViewModel.checkForNoteToSelf(user!!)
|
||||||
dialogMessageActionsBinding.menuShareToNote.setOnClickListener {
|
dialogMessageActionsBinding.menuShareToNote.setOnClickListener {
|
||||||
chatActivity.chatViewModel.checkForNoteToSelf(user!!)
|
chatActivity.shareToNotes(message, noteToSelfRoomToken)
|
||||||
chatActivity.shareToNotes(message, roomToken)
|
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user