@@ -16,6 +16,8 @@ import kotlinx.serialization.json.jsonPrimitive
16
16
import kotlinx.serialization.json.long
17
17
import li.songe.gkd.service.typeInfo
18
18
import li.songe.gkd.util.LOCAL_SUBS_IDS
19
+ import li.songe.gkd.util.distinctByIfAny
20
+ import li.songe.gkd.util.filterIfNotAll
19
21
import li.songe.gkd.util.json
20
22
import li.songe.gkd.util.toast
21
23
import li.songe.json5.Json5
@@ -782,7 +784,7 @@ data class RawSubscription(
782
784
is JsonArray -> groupsJson
783
785
}).map { jsonElement ->
784
786
jsonToGroupRaw(jsonElement)
785
- }.distinctBy { it.key },
787
+ }.distinctByIfAny { it.key },
786
788
)
787
789
}
788
790
@@ -824,7 +826,7 @@ data class RawSubscription(
824
826
jsonToGlobalApp(
825
827
jsonElement.jsonObject, index
826
828
)
827
- }?.distinctBy { it.id },
829
+ }?.distinctByIfAny { it.id },
828
830
action = getString(jsonObject, " action" ),
829
831
preKeys = getIntIArray(jsonObject, " preKeys" ),
830
832
excludeMatches = getStringIArray(jsonObject, " excludeMatches" ),
@@ -865,7 +867,7 @@ data class RawSubscription(
865
867
jsonToGlobalApp(
866
868
jsonElement.jsonObject, index
867
869
)
868
- }?.distinctBy { it.id },
870
+ }?.distinctByIfAny { it.id },
869
871
rules = (jsonObject[" rules" ]?.jsonArray?.map { jsonElement ->
870
872
jsonToGlobalRule(jsonElement.jsonObject)
871
873
} ? : emptyList()).distinctNotNullBy { it.key },
@@ -892,13 +894,7 @@ data class RawSubscription(
892
894
jsonElement.jsonObject,
893
895
index
894
896
)
895
- } ? : emptyList()).distinctBy { it.id }.run {
896
- if (any { it.groups.isEmpty() }) {
897
- filterNot { it.groups.isEmpty() }
898
- } else {
899
- this
900
- }
901
- },
897
+ } ? : emptyList()).filterIfNotAll { it.groups.isNotEmpty() }.distinctByIfAny { it.id },
902
898
categories = (rootJson[" categories" ]?.jsonArray?.mapIndexed { index, jsonElement ->
903
899
RawCategory (
904
900
key = getInt(jsonElement.jsonObject, " key" )
@@ -907,10 +903,10 @@ data class RawSubscription(
907
903
? : error(" miss categories[$index ].name" ),
908
904
enable = getBoolean(jsonElement.jsonObject, " enable" ),
909
905
)
910
- } ? : emptyList()).distinctBy { it.key },
906
+ } ? : emptyList()).filterIfNotAll { it.name.isNotEmpty() }.distinctByIfAny { it.key },
911
907
globalGroups = (rootJson[" globalGroups" ]?.jsonArray?.mapIndexed { index, jsonElement ->
912
908
jsonToGlobalGroup(jsonElement.jsonObject, index)
913
- } ? : emptyList()).distinctBy { it.key }
909
+ } ? : emptyList()).distinctByIfAny { it.key }
914
910
)
915
911
}
916
912
0 commit comments