refactor: ensure `Channel` and `ChannelSettings` indexes match

pull/684/head
andrekir 2023-08-12 07:43:38 -03:00
rodzic 76d01af995
commit 67fedb9ff8
1 zmienionych plików z 7 dodań i 4 usunięć

Wyświetl plik

@ -51,12 +51,15 @@ class ChannelSetRepository @Inject constructor(
* Updates the [ChannelSettings] list with the provided channel.
*/
suspend fun updateChannelSettings(channel: Channel) {
if (channel.role == Channel.Role.DISABLED) return
channelSetStore.updateData { preference ->
if (preference.settingsCount > channel.index) {
preference.toBuilder().setSettings(channel.index, channel.settings).build()
} else {
preference.toBuilder().addSettings(channel.settings).build()
val builder = preference.toBuilder()
// Resize to fit channel
while (builder.settingsCount <= channel.index) {
builder.addSettings(ChannelSettings.getDefaultInstance())
}
// use setSettings() to ensure settingsList and channel indexes match
builder.setSettings(channel.index, channel.settings).build()
}
}