Fix dynamic alteration not working properly on client.
This commit is contained in:
		
							parent
							
								
									0aaa56a4aa
								
							
						
					
					
						commit
						2f4b30297c
					
				
					 2 changed files with 25 additions and 18 deletions
				
			
		| 
						 | 
					@ -5,6 +5,7 @@ import com.pixelized.desktop.lwa.repository.network.NetworkRepository
 | 
				
			||||||
import com.pixelized.shared.lwa.model.alteration.Alteration
 | 
					import com.pixelized.shared.lwa.model.alteration.Alteration
 | 
				
			||||||
import com.pixelized.shared.lwa.model.alteration.AlterationJsonFactory
 | 
					import com.pixelized.shared.lwa.model.alteration.AlterationJsonFactory
 | 
				
			||||||
import com.pixelized.shared.lwa.protocol.websocket.ApiSynchronisation
 | 
					import com.pixelized.shared.lwa.protocol.websocket.ApiSynchronisation
 | 
				
			||||||
 | 
					import com.pixelized.shared.lwa.protocol.websocket.ApiSynchronisation.AlterationApiSynchronisation
 | 
				
			||||||
import com.pixelized.shared.lwa.protocol.websocket.SocketMessage
 | 
					import com.pixelized.shared.lwa.protocol.websocket.SocketMessage
 | 
				
			||||||
import kotlinx.coroutines.CoroutineScope
 | 
					import kotlinx.coroutines.CoroutineScope
 | 
				
			||||||
import kotlinx.coroutines.Dispatchers
 | 
					import kotlinx.coroutines.Dispatchers
 | 
				
			||||||
| 
						 | 
					@ -118,15 +119,17 @@ class AlterationStore(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private suspend fun handleMessage(message: SocketMessage) {
 | 
					    private suspend fun handleMessage(message: SocketMessage) {
 | 
				
			||||||
        when (message) {
 | 
					        when (message) {
 | 
				
			||||||
            is ApiSynchronisation.AlterationUpdate -> updateAlterationFlow(
 | 
					            is AlterationApiSynchronisation -> when (message) {
 | 
				
			||||||
 | 
					                is ApiSynchronisation.AlterationDelete -> updateAlterationFlow(
 | 
				
			||||||
                    alterationId = message.alterationId,
 | 
					                    alterationId = message.alterationId,
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            is ApiSynchronisation.AlterationDelete -> _alterationsFlow.update { alterations ->
 | 
					                is ApiSynchronisation.AlterationUpdate -> _alterationsFlow.update { alterations ->
 | 
				
			||||||
                    alterations.toMutableMap().also {
 | 
					                    alterations.toMutableMap().also {
 | 
				
			||||||
                        it.remove(message.alterationId)
 | 
					                        it.remove(message.alterationId)
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            else -> Unit
 | 
					            else -> Unit
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -195,27 +195,31 @@ class CharacterSheetStore(
 | 
				
			||||||
        _detailFlow.update(character)
 | 
					        _detailFlow.update(character)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private suspend fun updateAlterations(
 | 
					    private fun updateAlterations(
 | 
				
			||||||
        characterSheetId: String,
 | 
					        characterSheetId: String,
 | 
				
			||||||
        alterationId: String,
 | 
					        alterationId: String,
 | 
				
			||||||
        active: Boolean,
 | 
					        active: Boolean,
 | 
				
			||||||
    ) {
 | 
					    ) {
 | 
				
			||||||
        if (alterationStore.alteration(alterationId = alterationId) == null) return
 | 
					        // check if the alteration exist
 | 
				
			||||||
        val sheet = getCharacterSheet(characterSheetId = characterSheetId)
 | 
					        alterationStore.alteration(alterationId = alterationId) ?: return
 | 
				
			||||||
 | 
					        // check if the character exit (detail may have not been downloaded)
 | 
				
			||||||
 | 
					        val sheet = detailFlow.value[characterSheetId] ?: return
 | 
				
			||||||
 | 
					        // check if the alteration is already active or not on this character.
 | 
				
			||||||
        val containAlteration = sheet.alterations.contains(alterationId)
 | 
					        val containAlteration = sheet.alterations.contains(alterationId)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (containAlteration.not() && active) {
 | 
					        if (containAlteration.not() && active) {
 | 
				
			||||||
            val alterations = sheet.alterations.toMutableList().also {
 | 
					            _detailFlow.update(
 | 
				
			||||||
                it.add(alterationId)
 | 
					                sheet = sheet.copy(
 | 
				
			||||||
            }
 | 
					                    alterations = sheet.alterations.toMutableList().also { it.add(alterationId) }
 | 
				
			||||||
            _detailFlow.update(sheet.copy(alterations = alterations))
 | 
					                )
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (containAlteration && active.not()) {
 | 
					        if (containAlteration && active.not()) {
 | 
				
			||||||
            val alterations = sheet.alterations.toMutableList().also {
 | 
					            _detailFlow.update(
 | 
				
			||||||
                it.remove(alterationId)
 | 
					                sheet = sheet.copy(
 | 
				
			||||||
            }
 | 
					                    alterations = sheet.alterations.toMutableList().also { it.remove(alterationId) }
 | 
				
			||||||
            _detailFlow.update(sheet.copy(alterations = alterations))
 | 
					                )
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue