Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init other data earlier than ConversationModel #4738

Merged
merged 1 commit into from
Feb 18, 2025
Merged
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
21 changes: 11 additions & 10 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,17 @@ class ChatActivity :
conversationUser = currentUserProvider.currentUser.blockingGet()
handleIntent(intent)

messageInputFragment = getMessageInputFragment()

chatViewModel = ViewModelProvider(this, viewModelFactory)[ChatViewModel::class.java]

val urlForChatting = ApiUtils.getUrlForChat(chatApiVersion, conversationUser?.baseUrl, roomToken)
val credentials = ApiUtils.getCredentials(conversationUser!!.username, conversationUser!!.token)
chatViewModel.initData(
credentials!!,
urlForChatting,
roomToken
)

messageInputFragment = getMessageInputFragment()
messageInputViewModel = ViewModelProvider(this, viewModelFactory)[MessageInputViewModel::class.java]
messageInputViewModel.setData(chatViewModel.getChatRepository())

Expand Down Expand Up @@ -576,14 +583,8 @@ class ChatActivity :
chatViewModel.getConversationFlow
.onEach { conversationModel ->
currentConversation = conversationModel

val urlForChatting = ApiUtils.getUrlForChat(chatApiVersion, conversationUser?.baseUrl, roomToken)
val credentials = ApiUtils.getCredentials(conversationUser!!.username, conversationUser!!.token)

chatViewModel.setData(
currentConversation!!,
credentials!!,
urlForChatting
chatViewModel.updateConversation(
currentConversation!!
)

logConversationInfos("GetRoomSuccessState")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ interface ChatMessageRepository : LifecycleAwareManager {

val removeMessageFlow: Flow<ChatMessage>

fun setData(conversationModel: ConversationModel, credentials: String, urlForChatting: String)
fun initData(credentials: String, urlForChatting: String, roomToken: String)

fun updateConversation(conversationModel: ConversationModel)

fun initScopeAndLoadInitialMessages(withNetworkParams: Bundle)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,14 @@ class OfflineFirstChatRepository @Inject constructor(
private lateinit var credentials: String
private lateinit var urlForChatting: String

override fun setData(conversationModel: ConversationModel, credentials: String, urlForChatting: String) {
this.conversationModel = conversationModel
override fun initData(credentials: String, urlForChatting: String, roomToken: String) {
internalConversationId = currentUser.id.toString() + "@" + roomToken
this.credentials = credentials
this.urlForChatting = urlForChatting
internalConversationId = conversationModel.internalId
}

override fun updateConversation(conversationModel: ConversationModel) {
this.conversationModel = conversationModel
}

override fun initScopeAndLoadInitialMessages(withNetworkParams: Bundle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,12 @@ class ChatViewModel @Inject constructor(
val reactionDeletedViewState: LiveData<ViewState>
get() = _reactionDeletedViewState

fun setData(conversationModel: ConversationModel, credentials: String, urlForChatting: String) {
chatRepository.setData(conversationModel, credentials, urlForChatting)
fun initData(credentials: String, urlForChatting: String, roomToken: String) {
chatRepository.initData(credentials, urlForChatting, roomToken)
}

fun updateConversation(currentConversation: ConversationModel) {
chatRepository.updateConversation(currentConversation)
}

fun getRoom(token: String) {
Expand Down
Loading