Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1192,8 +1192,8 @@ class ChatActivity :

pendingTargetMessageId = extras?.getString(BundleKeys.KEY_MESSAGE_ID)?.toLongOrNull()?.takeIf { it > 0L }
?: extras?.getLong(BundleKeys.KEY_MESSAGE_ID)?.takeIf { it > 0L }
pendingTargetThreadId = extras?.getString(BundleKeys.KEY_THREAD_ID)?.toLongOrNull()?.takeIf { it > 0L }
?: extras?.getLong(BundleKeys.KEY_THREAD_ID)?.takeIf { it > 0L }
pendingTargetThreadId = extras?.getString(KEY_THREAD_ID)?.toLongOrNull()?.takeIf { it > 0L }
?: extras?.getLong(KEY_THREAD_ID)?.takeIf { it > 0L }
pendingTargetSearchQuery = extras?.getString(BundleKeys.KEY_SEARCH_QUERY)
}

Expand Down Expand Up @@ -1332,7 +1332,6 @@ class ChatActivity :
currentConversation = state.conversationModel
chatApiVersion = ApiUtils.getChatApiVersion(spreedCapabilities, intArrayOf(1))
participantPermissions = ParticipantPermissions(spreedCapabilities, state.conversationModel!!)

supportFragmentManager.commit {
setReorderingAllowed(true) // optimizes out redundant replace operations
replace(R.id.fragment_container_activity_chat, messageInputFragment)
Expand Down Expand Up @@ -1440,7 +1439,6 @@ class ChatActivity :
when (state) {
is ChatViewModel.JoinRoomSuccessState -> {
currentConversation = state.conversationModel

sessionIdAfterRoomJoined = currentConversation!!.sessionId
ApplicationWideCurrentRoomHolder.getInstance().session = currentConversation!!.sessionId
ApplicationWideCurrentRoomHolder.getInstance().currentRoomToken = currentConversation!!.token
Expand Down
77 changes: 39 additions & 38 deletions app/src/main/java/com/nextcloud/talk/chat/MessageInputFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ import com.nextcloud.talk.ui.dialog.AttachmentDialog
import com.nextcloud.talk.ui.theme.ViewThemeUtils
import com.nextcloud.talk.users.UserManager
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.DisplayUtils
import com.nextcloud.talk.utils.CapabilitiesUtil
import com.nextcloud.talk.utils.CharPolicy
import com.nextcloud.talk.utils.DateUtils
import com.nextcloud.talk.utils.DisplayUtils
import com.nextcloud.talk.utils.EmojiTextInputEditText
import com.nextcloud.talk.utils.ImageEmojiEditText
import com.nextcloud.talk.utils.SpreedFeatures
Expand Down Expand Up @@ -299,47 +299,48 @@ class MessageInputFragment : Fragment() {
}.collect()
}

messageInputViewModel.callStartedFlow.observe(viewLifecycleOwner) {
val (message, show) = it
if (show) {
binding.fragmentCallStarted.callAuthorChip.text = message.actorDisplayName
binding.fragmentCallStarted.callAuthorChipSecondary.text = message.actorDisplayName
val user = currentUserProvider.currentUser.blockingGet()
val url: String = if (message.actorType == "guests" || message.actorType == "guest") {
ApiUtils.getUrlForGuestAvatar(user!!.baseUrl!!, message.actorDisplayName, true)
} else {
ApiUtils.getUrlForAvatar(
user!!.baseUrl!!,
message.actorId,
false,
darkMode = DisplayUtils.isDarkModeOn(requireContext())
)
}
viewLifecycleOwner.lifecycleScope.launch {
chatActivity.chatViewModel.lastCallSystemMessage.collect {
if (it.shouldShow) {
binding.fragmentCallStarted.callAuthorChip.text = it.actorDisplayName
binding.fragmentCallStarted.callAuthorChipSecondary.text = it.actorDisplayName
val user = currentUserProvider.currentUser.blockingGet()
val url: String = if (it.actorType == "guests" || it.actorType == "guest") {
ApiUtils.getUrlForGuestAvatar(user!!.baseUrl!!, it.actorDisplayName, true)
} else {
ApiUtils.getUrlForAvatar(
user!!.baseUrl!!,
it.actorId,
false,
darkMode = DisplayUtils.isDarkModeOn(requireContext())
)
}

val imageRequest: ImageRequest = ImageRequest.Builder(requireContext())
.data(url)
.crossfade(true)
.transformations(CircleCropTransformation())
.target(object : Target {
override fun onStart(placeholder: Drawable?) {
// unused atm
}
val imageRequest: ImageRequest = ImageRequest.Builder(requireContext())
.data(url)
.crossfade(true)
.transformations(CircleCropTransformation())
.target(object : Target {
override fun onStart(placeholder: Drawable?) {
// unused atm
}

override fun onError(error: Drawable?) {
// unused atm
}
override fun onError(error: Drawable?) {
// unused atm
}

override fun onSuccess(result: Drawable) {
binding.fragmentCallStarted.callAuthorChip.chipIcon = result
binding.fragmentCallStarted.callAuthorChipSecondary.chipIcon = result
}
})
.build()
override fun onSuccess(result: Drawable) {
binding.fragmentCallStarted.callAuthorChip.chipIcon = result
binding.fragmentCallStarted.callAuthorChipSecondary.chipIcon = result
}
})
.build()

imageLoader(requireContext()).enqueue(imageRequest)
binding.fragmentCallStarted.root.visibility = View.VISIBLE
} else {
binding.fragmentCallStarted.root.visibility = View.GONE
imageLoader(requireContext()).enqueue(imageRequest)
binding.fragmentCallStarted.root.visibility = View.VISIBLE
} else {
binding.fragmentCallStarted.root.visibility = View.GONE
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,24 @@ class ChatViewModel @AssistedInject constructor(
val expandedParents: Set<Int> = emptySet()
)

data class CallStartedIndicatorData(
val actorDisplayName: String,
val actorType: String,
val actorId: String,
val shouldShow: Boolean
)

private val _lastCallSystemMessage = MutableStateFlow<ChatMessage?>(null)

val lastCallSystemMessage = _lastCallSystemMessage.map { msg ->
CallStartedIndicatorData(
msg?.actorDisplayName ?: "",
msg?.actorType ?: "",
msg?.actorId ?: "",
msg != null
)
}

private data class ProcessedMessages(val items: List<ChatItem>, val missingParentIds: List<Long>)

private fun observeMessages() {
Expand Down Expand Up @@ -1328,6 +1346,21 @@ class ChatViewModel @AssistedInject constructor(
val chatMessageMap = chatMessageList.associateBy { it.jsonMessageId }.toMutableMap()
val chatMessageIterator = chatMessageMap.iterator()

chatMessageList.lastOrNull {
it.systemMessageType in
listOf(
ChatMessage.SystemMessageType.CALL_STARTED,
ChatMessage.SystemMessageType.CALL_JOINED,
ChatMessage.SystemMessageType.CALL_LEFT,
ChatMessage.SystemMessageType.CALL_ENDED,
ChatMessage.SystemMessageType.CALL_TRIED,
ChatMessage.SystemMessageType.CALL_ENDED_EVERYONE,
ChatMessage.SystemMessageType.CALL_MISSED
)
}?.let { callMessage ->
processCallSystemMessage(callMessage)
}

while (chatMessageIterator.hasNext()) {
val currentMessage = chatMessageIterator.next()

Expand All @@ -1338,6 +1371,21 @@ class ChatViewModel @AssistedInject constructor(
return chatMessageMap.values.toList()
}

private fun processCallSystemMessage(recent: ChatMessage) {
when (recent.systemMessageType) {
ChatMessage.SystemMessageType.CALL_STARTED -> {
_lastCallSystemMessage.tryEmit(recent)
}
ChatMessage.SystemMessageType.CALL_ENDED,
ChatMessage.SystemMessageType.CALL_MISSED,
ChatMessage.SystemMessageType.CALL_TRIED,
ChatMessage.SystemMessageType.CALL_ENDED_EVERYONE -> {
_lastCallSystemMessage.tryEmit(null)
}
else -> {}
}
}

private fun isInfoMessageAboutDeletion(currentMessage: MutableMap.MutableEntry<Int, ChatMessage>): Boolean =
currentMessage.value.parentMessageId != null &&
currentMessage.value.systemMessageType == ChatMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@ class MessageInputViewModel :
val isVoicePreviewPlaying: LiveData<Boolean>
get() = _isVoicePreviewPlaying

private val _callStartedFlow: MutableLiveData<Pair<ChatMessage, Boolean>> = MutableLiveData()
val callStartedFlow: LiveData<Pair<ChatMessage, Boolean>>
get() = _callStartedFlow

object ScheduleChatMessageStartState : ViewState
class ScheduleChatMessageSuccessState(val scheduledAt: Long) : ViewState
object ScheduleChatMessageErrorState : ViewState
Expand Down Expand Up @@ -287,10 +283,6 @@ class MessageInputViewModel :
_getRecordingTime.postValue(time)
}

fun showCallStartedIndicator(recent: ChatMessage, show: Boolean) {
_callStartedFlow.postValue(Pair(recent, show))
}

fun startThreadCreation() {
_createThreadViewState.postValue(CreateThreadEditState())
}
Expand Down
Loading